public void CertificateAdd(string[] args) { CertificateFileInfo certFileInfo = CertificateFileInfo.Create(0, args); MemoryX509Store certStore = certFileInfo.LoadCerts(); PushCerts(certStore, false, certFileInfo.Status); }
public void CertificateExportKey(string[] args) { CertificateFileInfo certFileInfo = CertificateFileInfo.Create(0, args); MemoryX509Store certStore = certFileInfo.LoadCerts(); ShowKey(certStore); }
internal MemoryX509Store LoadCerts(string filePath, string password, X509KeyStorageFlags flags) { MemoryX509Store certStore = new MemoryX509Store(); LoadCerts(certStore, filePath, password, flags); return(certStore); }
static TestCertificates() { AgentTester.EnsureStandardMachineStores(); ChainCertsStore = LoadCertificateFolder("Chain"); PublicCertsStore = new MemoryX509Store(LoadAllPublic()); AllPublicCerts = LoadAllPublic(); }
internal MemoryX509Store LoadCerts(X509KeyStorageFlags flags) { MemoryX509Store certStore = new MemoryX509Store(); LoadCerts(certStore, flags); return(certStore); }
public static MemoryX509Store LoadCertificates(string folderPath, X509KeyStorageFlags flags) { if (string.IsNullOrEmpty(folderPath)) { throw new ArgumentException("value was null or empty", "folderPath"); } if (!Directory.Exists(folderPath)) { throw new DirectoryNotFoundException("Directory not found: " + folderPath); } MemoryX509Store certStore = new MemoryX509Store(); string[] files = Directory.GetFiles(folderPath); for (int i = 0; i < files.Length; ++i) { string file = files[i]; string ext = Path.GetExtension(file) ?? string.Empty; ext = ext.ToLower(); switch (ext) { default: certStore.ImportKeyFile(file, flags); break; case ".pfx": certStore.ImportKeyFile(file, "passw0rd!", flags); break; } } return(certStore); }
MemoryX509Store LoadCertificates(string folderPath) { if (!Directory.Exists(folderPath)) { throw new DirectoryNotFoundException("Directory not found: " + folderPath); } MemoryX509Store certStore = new MemoryX509Store(); try { string[] files = Directory.GetFiles(folderPath); if (files.IsNullOrEmpty()) { throw new ArgumentException("Empty directory"); } CertificateCommands certcmd = GetCommand <CertificateCommands>(); foreach (string file in files) { certcmd.LoadCerts(certStore, file, "passw0rd!", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet); } return(certStore); } catch { certStore.Dispose(); throw; } }
static bool DoPrivateKeysExist(X509Store store, string path) { using (MemoryX509Store certs = LoadPrivateCerts(path, false)) { foreach (X509Certificate2 cert in certs) { X509Certificate2 found = store.Certificates.FindByThumbprint(cert.Thumbprint); if (found == null) { return(false); } bool hasKey = false; try { hasKey = (!string.IsNullOrEmpty(found.PrivateKey.ToXmlString(true))); } catch { } if (!hasKey) { return(false); } } } return(true); }
public CryptographerTests() { m_tester = AgentTester.CreateTest(); m_cryptographer = m_tester.AgentA.Cryptographer; MemoryX509Store certs = AgentTester.LoadPrivateCerts("redmond"); m_cert = certs.First(); }
public static MemoryX509Store LoadCertificateFolder(string folderPath) { string path = FullPath(folderPath); MemoryX509Store store = new MemoryX509Store(); store.ImportFolder(path, X509KeyStorageFlags.DefaultKeySet); return(store); }
public static DirectAgent CreateAgent(string domain, string certsBasePath) { MemoryX509Store privateCerts = LoadPrivateCerts(certsBasePath, false); MemoryX509Store publicCerts = LoadPublicCerts(certsBasePath); TrustAnchorResolver anchors = new TrustAnchorResolver( (IX509CertificateStore)LoadIncomingAnchors(certsBasePath), (IX509CertificateStore)LoadOutgoingAnchors(certsBasePath)); return(new DirectAgent(domain, privateCerts.CreateResolver(), publicCerts.CreateResolver(), anchors)); }
public void CertificateEnsure(string[] args) { CertificateFileInfo certFileInfo = CertificateFileInfo.Create(0, args); MemoryX509Store certStore = certFileInfo.LoadCerts(); // // This checks for duplicates...(using thumbprints) // PushCerts(certStore, true, certFileInfo.Status); }
public void CertificateSearchByFile(string[] args) { CertificateFileInfo certFileInfo = CertificateFileInfo.Create(0, args); MemoryX509Store certs = certFileInfo.LoadCerts(); WriteLine(string.Empty); this.Search( x => (certs.FirstOrDefault(y => this.Match(x, y)) != null) ); }
public CryptographerTests() { m_tester = AgentTester.CreateTest(); m_cryptographer = m_tester.AgentA.Cryptographer as SMIMECryptographer; MemoryX509Store certs = AgentTester.LoadPrivateCerts("redmond"); m_cert = certs .ToList() .First(c => c.HasPrivateKey); }
public void TestDnsAltName() { MemoryX509Store dnsCerts = TestCertificates.LoadCertificateFolder("Dns"); foreach (X509Certificate2 dnsCert in dnsCerts) { string dnsName = dnsCert.GetNameInfo(X509NameType.DnsName, false); Assert.True(dnsCert.MatchDnsName(dnsName)); Assert.True(dnsCert.MatchDnsOrEmailOrName(dnsName)); } }
public TrustChainTests() { m_store = TestCertificates.ChainCertsStore.Clone(); m_resolver = m_store.CreateResolver(); m_validator = this.CreateValidator(); // // Find the endcert and the root cert // We'll trust the root cert, but the intermediaries are not trusted // m_endCerts = m_resolver.GetCertificates(new MailAddress("*****@*****.**")); m_trustedAnchors = m_resolver.GetCertificatesForDomain("root.xyz"); }
static void InstallPrivateKeys(X509Store store, MemoryX509Store certs) { foreach (X509Certificate2 cert in certs) { X509Certificate2 found = store.Certificates.FindByThumbprint(cert.Thumbprint); if (found != null) { store.Remove(found); found.Reset(); } store.Add(cert); } }
public void AnchorSearchByFile(string[] args) { string owner = args.GetRequiredValue(0); CertificateFileInfo certFileInfo = CertificateFileInfo.Create(1, args); MemoryX509Store certs = certFileInfo.LoadCerts(); WriteLine(string.Empty); this.Search( owner, x => (certs.FirstOrDefault(y => this.CertCommands.Match(x, y)) != null) ); }
internal void LoadCerts(MemoryX509Store certStore, string filePath, string password, X509KeyStorageFlags flags) { string ext = Path.GetExtension(filePath) ?? string.Empty; switch (ext.ToLower()) { default: certStore.ImportKeyFile(filePath, flags); break; case ".pfx": certStore.ImportKeyFile(filePath, password, flags); break; } }
public void CertificateEnsureMachine(string[] args) { using (SystemX509Store store = OpenStore(args.GetRequiredValue(0))) { CertificateFileInfo certFileInfo = CertificateFileInfo.Create(1, args); MemoryX509Store certs = certFileInfo.LoadCerts(MachineKeyFlags); foreach (X509Certificate2 cert in certs) { string comment = "EXISTS"; if (!store.Contains(cert)) { store.Add(cert); comment = "ADDED"; } WriteLine("{0}: {1}, Thumbprint:{2}", comment, cert.Subject, cert.Thumbprint); } } }
internal void LoadCerts(MemoryX509Store certStore, X509KeyStorageFlags flags) { if (!File.Exists(this.FilePath)) { throw new FileNotFoundException("File does not exist", this.FilePath); } string ext = Path.GetExtension(this.FilePath) ?? string.Empty; switch (ext.ToLower()) { default: certStore.ImportKeyFile(this.FilePath, flags); break; case ".pfx": certStore.ImportKeyFile(FilePath, this.Password, flags); break; } }
public static DirectAgent CreateAgent( IDomainResolver domain, string certsBasePath, ISmimeCryptographer cryptographer, ICertPolicyResolvers certPolicyResolvers) { MemoryX509Store privateCerts = LoadPrivateCerts(certsBasePath, false); MemoryX509Store publicCerts = LoadPublicCerts(certsBasePath); TrustAnchorResolver anchors = new TrustAnchorResolver( (IX509CertificateStore)LoadOutgoingAnchors(certsBasePath), (IX509CertificateStore)LoadIncomingAnchors(certsBasePath)); return(new DirectAgent( domain, privateCerts.CreateResolver(), publicCerts.CreateResolver(), anchors, TrustModel.Default, cryptographer ?? SMIMECryptographer.Default, certPolicyResolvers )); }