| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Net.Security; |
| | | 6 | | using System.Runtime.InteropServices; |
| | | 7 | | using System.Security.Cryptography.X509Certificates; |
| | | 8 | | |
| | | 9 | | namespace System.Net |
| | | 10 | | { |
| | | 11 | | internal static partial class UnmanagedCertificateContext |
| | | 12 | | { |
| | | 13 | | internal static unsafe void GetRemoteCertificatesFromStoreContext(IntPtr certContext, X509Certificate2Collection |
| | 0 | 14 | | { |
| | 0 | 15 | | if (certContext == IntPtr.Zero) |
| | 0 | 16 | | { |
| | 0 | 17 | | return; |
| | | 18 | | } |
| | | 19 | | |
| | 0 | 20 | | Interop.Crypt32.CERT_CONTEXT context = *(Interop.Crypt32.CERT_CONTEXT*)certContext; |
| | | 21 | | |
| | 0 | 22 | | if (context.hCertStore != IntPtr.Zero) |
| | 0 | 23 | | { |
| | 0 | 24 | | Interop.Crypt32.CERT_CONTEXT* last = null; |
| | | 25 | | |
| | 0 | 26 | | while (true) |
| | 0 | 27 | | { |
| | 0 | 28 | | Interop.Crypt32.CERT_CONTEXT* next = |
| | 0 | 29 | | Interop.Crypt32.CertEnumCertificatesInStore(context.hCertStore, last); |
| | | 30 | | |
| | 0 | 31 | | if (next == null) |
| | 0 | 32 | | { |
| | 0 | 33 | | break; |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | if ((IntPtr)next != certContext) |
| | 0 | 37 | | { |
| | 0 | 38 | | var cert = new X509Certificate2(new IntPtr(next)); |
| | 0 | 39 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(certContext, $"Adding remote certificate |
| | | 40 | | |
| | 0 | 41 | | result.Add(cert); |
| | 0 | 42 | | } |
| | | 43 | | |
| | 0 | 44 | | last = next; |
| | 0 | 45 | | } |
| | 0 | 46 | | } |
| | 0 | 47 | | } |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | |