public bool ClearCertificateCache(bool bRemoveRoot) { bool result = true; try { this.GetWriterLock(); this.certServerCache.Clear(); this.certRoot = null; string text = string.Format("CN={0}{1}", CONFIG.sMakeCertRootCN, CONFIG.sMakeCertSubjectO); X509Certificate2Collection x509Certificate2Collection; if (bRemoveRoot) { x509Certificate2Collection = DefaultCertificateProvider.FindCertsBySubject(StoreName.Root, StoreLocation.CurrentUser, text); if (x509Certificate2Collection.Count > 0) { X509Store x509Store = new X509Store(StoreName.Root, StoreLocation.CurrentUser); x509Store.Open(OpenFlags.ReadWrite | OpenFlags.OpenExistingOnly); try { x509Store.RemoveRange(x509Certificate2Collection); } catch { result = false; } x509Store.Close(); } } x509Certificate2Collection = DefaultCertificateProvider.FindCertsByIssuer(StoreName.My, text); if (x509Certificate2Collection.Count > 0) { if (!bRemoveRoot) { X509Certificate2 rootCertificate = this.GetRootCertificate(); if (rootCertificate != null) { x509Certificate2Collection.Remove(rootCertificate); if (x509Certificate2Collection.Count < 1) { return(true); } } } X509Store x509Store2 = new X509Store(StoreName.My, StoreLocation.CurrentUser); x509Store2.Open(OpenFlags.ReadWrite | OpenFlags.OpenExistingOnly); try { x509Store2.RemoveRange(x509Certificate2Collection); } catch { result = false; } x509Store2.Close(); } } finally { this.FreeWriterLock(); } return(result); }
public bool rootCertIsTrusted(out bool bUserTrusted, out bool bMachineTrusted) { bUserTrusted = (0 < DefaultCertificateProvider.FindCertsBySubject(StoreName.Root, StoreLocation.CurrentUser, string.Format("CN={0}{1}", CONFIG.sMakeCertRootCN, CONFIG.sMakeCertSubjectO)).Count); bMachineTrusted = (0 < DefaultCertificateProvider.FindCertsBySubject(StoreName.Root, StoreLocation.LocalMachine, string.Format("CN={0}{1}", CONFIG.sMakeCertRootCN, CONFIG.sMakeCertSubjectO)).Count); return(bUserTrusted || bMachineTrusted); }