internal X509Certificate2 GetRemoteCertificate(out X509Certificate2Collection remoteCertificateStore) { remoteCertificateStore = null; if (this.m_SecurityContext == null) { return(null); } X509Certificate2 certificate = null; SafeFreeCertContext certContext = null; try { certContext = SSPIWrapper.QueryContextAttributes(GlobalSSPI.SSPISecureChannel, this.m_SecurityContext, ContextAttribute.RemoteCertificate) as SafeFreeCertContext; if ((certContext != null) && !certContext.IsInvalid) { certificate = new X509Certificate2(certContext.DangerousGetHandle()); } } finally { if (certContext != null) { remoteCertificateStore = UnmanagedCertificateContext.GetStore(certContext); certContext.Close(); } } if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.GetString("net_log_remote_certificate", new object[] { (certificate == null) ? "null" : certificate.ToString(true) })); } return(certificate); }
//This method extracts a remote certificate and chain upon request. private void ExtractRemoteCertificate() { SafeFreeCertContext remoteContext = null; this.remoteCertificate = null; this.remoteCertificateChain = null; try { remoteContext = ExtractCertificateHandle(ContextAttribute.RemoteCertificate); if (remoteContext != null && !remoteContext.IsInvalid) { this.remoteCertificateChain = UnmanagedCertificateContext.GetStore(remoteContext); this.remoteCertificate = new X509Certificate2(remoteContext.DangerousGetHandle()); } } finally { if (remoteContext != null) { remoteContext.Close(); } } }