internal void InternalTryFindCertificateTest(string ipAddress, IEnumerable <string> findValues, X509FindType findType) { IEnumerable <X509Certificate2> foundCerts; IEnumerable <string> unfoundCerts = X509CertificateUtility.TryFindCertificate(ipAddress, StoreName.My, findValues, findType, out foundCerts); bool isThumbprintTest = findType == X509FindType.FindByThumbprint; this.VerifyCollectionEquity(foundCerts.Select(c => isThumbprintTest ? c.Thumbprint : c.Subject), Utility.installedCertificates.Select(p => isThumbprintTest ? p.Item1 : "CN=" + p.Item3)); this.VerifyCollectionEquity(unfoundCerts, Utility.uninstalledCertificates); }
public static void UninstallCertificates(IEnumerable <string> thumbprints) { IEnumerable <X509Certificate2> installedCerts; X509CertificateUtility.TryFindCertificate("localhost", StoreName.My, thumbprints, X509FindType.FindByThumbprint, out installedCerts); ProcessCertificates(new Action <X509Store, X509Certificate2>( (store, cert) => { store.Remove(cert); }), installedCerts); }
public void IsCertificateValidTest() { IEnumerable <X509Certificate2> foundCerts; X509CertificateUtility.TryFindCertificate( "localhost", StoreName.My, Utility.installedCertificates.Select(p => p.Item1), X509FindType.FindByThumbprint, out foundCerts); Assert.AreEqual(Utility.installedCertificates.Count(), foundCerts.Count()); Assert.IsTrue(foundCerts.All(cert => Utility.installedValidCertificates.Any(p => p.Item1 == cert.Thumbprint) == X509CertificateUtility.IsCertificateValid(cert))); }
public void FindIssuerTest() { IEnumerable <string> cns = Utility.installedCertificates.Select(p => p.Item3); IEnumerable <X509Certificate2> foundCerts; IEnumerable <string> unfoundCerts = X509CertificateUtility.TryFindCertificate(string.Empty, StoreName.My, cns, X509FindType.FindBySubjectName, out foundCerts); Assert.IsFalse(unfoundCerts.Any()); Assert.AreEqual(cns.Count(), foundCerts.Count()); X509Certificate2[] foundCertsResult = foundCerts.ToArray(); for (int i = 0; i < foundCertsResult.Count(); i++) { string issuerThumbprint = foundCertsResult[i].FindIssuer(new string[] { Utility.installedCertificates[i].Item1 }); Assert.AreEqual(Utility.installedCertificates[i].Item1, issuerThumbprint); } }