public void ResetStores(string[] args) { SystemX509Store store; WriteLine("Removing all Machine Private Certs"); using (store = SystemX509Store.OpenPrivateEdit()) { foreach (var certificate in store.GetAllCertificates()) { store.Remove(certificate); } } WriteLine("Removing all Machine Public Certs"); using (store = SystemX509Store.OpenExternalEdit()) { foreach (var certificate in store.GetAllCertificates()) { store.Remove(certificate); } } WriteLine("Removing all Machine Anchors Certs"); using (store = SystemX509Store.OpenAnchorEdit()) { foreach (var certificate in store.GetAllCertificates()) { store.Remove(certificate); } } }
public void EnsureMachineStores(string[] args) { SystemX509Store store = null; using (store = SystemX509Store.OpenPrivateEdit()) { WriteLine("Created Private Store"); } using (store = SystemX509Store.OpenExternalEdit()) { WriteLine("Created Public Store"); } using (store = SystemX509Store.OpenAnchorEdit()) { WriteLine("Created Anchor Store"); } }
private static SystemX509Store OpenStore(string storeName) { SystemX509Store store; switch (storeName.ToLower()) { case "public": store = SystemX509Store.OpenExternalEdit(); break; case "private": store = SystemX509Store.OpenPrivateEdit(); break; default: throw new ArgumentException(storeName); } return(store); }
/// <summary> /// Sets up standard stores for Testing /// WARNING: This may require elevated permissions /// </summary> public static void EnsureStandardMachineStores() { SystemX509Store.CreateAll(); string basePath = Directory.GetCurrentDirectory(); string redmondCertsPath = MakeCertificatesPath(basePath, "redmond"); string nhindCertsPath = MakeCertificatesPath(basePath, "nhind"); X509Store privateStore = CryptoUtility.OpenStoreReadWrite(SystemX509Store.PrivateCertsStoreName, StoreLocation.LocalMachine); if (!DoPrivateKeysExist(privateStore, redmondCertsPath)) { InstallPrivateKeys(privateStore, LoadPrivateCerts(redmondCertsPath, true)); } if (!DoPrivateKeysExist(privateStore, nhindCertsPath)) { InstallPrivateKeys(privateStore, LoadPrivateCerts(nhindCertsPath, true)); } privateStore.Close(); SystemX509Store store; using (store = SystemX509Store.OpenExternalEdit()) { InstallCerts(store, LoadPublicCerts(redmondCertsPath)); InstallCerts(store, LoadPublicCerts(nhindCertsPath)); } using (store = SystemX509Store.OpenAnchorEdit()) { InstallCerts(store, LoadIncomingAnchors(redmondCertsPath)); InstallCerts(store, LoadOutgoingAnchors(redmondCertsPath)); InstallCerts(store, LoadIncomingAnchors(nhindCertsPath)); InstallCerts(store, LoadOutgoingAnchors(nhindCertsPath)); } }
void EnsureStandardMachineStores(string path) { SystemX509Store.CreateAll(); string basePath = path; string redmondCertsPath = MakeCertificatesPath(basePath, "redmond"); string nhindCertsPath = MakeCertificatesPath(basePath, "nhind"); string noAnchorCertsPath = MakeCertificatesPath(basePath, "noAnchor"); SystemX509Store store; WriteLine("Installing Private Certs"); using (store = SystemX509Store.OpenPrivateEdit()) { InstallCerts(store, LoadCerts(redmondCertsPath, "Private")); InstallCerts(store, LoadCerts(nhindCertsPath, "Private")); } WriteLine("Installing Public Certs"); using (store = SystemX509Store.OpenExternalEdit()) { InstallCerts(store, LoadCerts(redmondCertsPath, "Public")); InstallCerts(store, LoadCerts(nhindCertsPath, "Public")); InstallCerts(store, LoadCerts(noAnchorCertsPath, "Public")); } WriteLine("Installing Anchors Certs"); using (store = SystemX509Store.OpenAnchorEdit()) { InstallCerts(store, LoadCerts(redmondCertsPath, "IncomingAnchors")); InstallCerts(store, LoadCerts(redmondCertsPath, "OutgoingAnchors")); InstallCerts(store, LoadCerts(nhindCertsPath, "IncomingAnchors")); InstallCerts(store, LoadCerts(nhindCertsPath, "OutgoingAnchors")); } }