internal static X509Certificate2Collection GetRemoteCertificatesFromStoreContext(SafeFreeCertContext certContext) { X509Certificate2Collection result = new X509Certificate2Collection(); if (certContext.IsInvalid) { return(result); } Interop.Crypt32.CERT_CONTEXT context = Marshal.PtrToStructure <Interop.Crypt32.CERT_CONTEXT>(certContext.DangerousGetHandle()); if (context.hCertStore != IntPtr.Zero) { X509Store store = null; try { store = X509StoreExtensions.CreateFromNativeHandle(context.hCertStore); result = store.Certificates; } finally { if (store != null) { store.Dispose(); } } } return(result); }
internal static unsafe X509Certificate2Collection GetRemoteCertificatesFromStoreContext(IntPtr certContext) { X509Certificate2Collection result = new X509Certificate2Collection(); if (certContext == IntPtr.Zero) { return(result); } Interop.Crypt32.CERT_CONTEXT context = *(Interop.Crypt32.CERT_CONTEXT *)certContext; if (context.hCertStore != IntPtr.Zero) { Interop.Crypt32.CERT_CONTEXT *last = null; while (true) { Interop.Crypt32.CERT_CONTEXT *next = Interop.Crypt32.CertEnumCertificatesInStore(context.hCertStore, last); if (next == null) { break; } if ((IntPtr)next != certContext) { var cert = new X509Certificate2(new IntPtr(next)); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(certContext, $"Adding remote certificate:{cert}"); } result.Add(cert); } last = next; } } return(result); }
internal static X509Certificate2Collection GetRemoteCertificatesFromStoreContext(SafeFreeCertContext certContext) { X509Certificate2Collection result = new X509Certificate2Collection(); if (certContext.IsInvalid) { return(result); } Interop.Crypt32.CERT_CONTEXT context = Marshal.PtrToStructure <Interop.Crypt32.CERT_CONTEXT>(certContext.DangerousGetHandle()); if (context.hCertStore != IntPtr.Zero) { Interop.Crypt32.CERT_CONTEXT *last = null; while (true) { Interop.Crypt32.CERT_CONTEXT *next = Interop.Crypt32.CertEnumCertificatesInStore(context.hCertStore, last); if (next == null) { break; } var cert = new X509Certificate2(new IntPtr(next)); if (GlobalLog.IsEnabled) { GlobalLog.Print( "UnmanagedCertificateContext::GetRemoteCertificatesFromStoreContext " + "adding remote certificate:" + cert.Subject + cert.Thumbprint); } result.Add(cert); last = next; } } return(result); }
internal static X509Certificate2Collection GetRemoteCertificatesFromStoreContext(SafeFreeCertContext certContext) { X509Certificate2Collection result = new X509Certificate2Collection(); if (certContext.IsInvalid) { return(result); } Interop.Crypt32.CERT_CONTEXT context = Marshal.PtrToStructure <Interop.Crypt32.CERT_CONTEXT>(certContext.DangerousGetHandle()); if (context.hCertStore != IntPtr.Zero) { Interop.Crypt32.CERT_CONTEXT *last = null; while (true) { Interop.Crypt32.CERT_CONTEXT *next = Interop.Crypt32.CertEnumCertificatesInStore(context.hCertStore, last); if (next == null) { break; } var cert = new X509Certificate2(new IntPtr(next)); if (NetEventSource.IsEnabled) { NetEventSource.Info(certContext, $"Adding remote certificate:{cert}"); } result.Add(cert); last = next; } } return(result); }