private void Log(EventTypeEnumeration type, TestFederationTrust.TestFederationTrustEventId id, LocalizedString message) { this.events.Add(new TestFederationTrust.ResultEvent { Id = id, Type = type, Message = message }); }
private bool IsValidPrivateKey(X509Certificate2 certificate, TestFederationTrust.TestFederationTrustEventId eventId, string propertyName) { if (!certificate.HasPrivateKey) { return(false); } bool result; try { RSACryptoServiceProvider rsacryptoServiceProvider = certificate.PrivateKey as RSACryptoServiceProvider; result = (rsacryptoServiceProvider != null); } catch (CryptographicException) { result = false; } catch (NotSupportedException) { result = false; } return(result); }
private X509Certificate2 GetOrganizationCertificate(X509Store store, string thumbprint, TestFederationTrust.TestFederationTrustEventId eventId, string propertyName) { X509Certificate2Collection x509Certificate2Collection = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); if (x509Certificate2Collection == null || x509Certificate2Collection.Count == 0 || x509Certificate2Collection[0] == null) { this.Log(EventTypeEnumeration.Error, eventId, Strings.FederationCertificateNotFound(propertyName)); return(null); } X509Certificate2 x509Certificate = x509Certificate2Collection[0]; if (TestFederationTrust.IsExpiredCertificate(x509Certificate)) { this.Log(EventTypeEnumeration.Error, eventId, Strings.FederationCertificateExpired(propertyName)); return(null); } if (!this.IsValidPrivateKey(x509Certificate, eventId, propertyName)) { this.Log(EventTypeEnumeration.Error, eventId, Strings.FederationCertificateHasNoPrivateKey(propertyName)); return(null); } this.Log(EventTypeEnumeration.Success, eventId, Strings.CertificateValid(propertyName)); return(x509Certificate); }