Make S.S.C.X509Certificates compliant with interop guidelines - part 3
authorBadre BSAILA <54767641+pedrobsaila@users.noreply.github.com>
Mon, 22 Nov 2021 18:03:33 +0000 (19:03 +0100)
committerGitHub <noreply@github.com>
Mon, 22 Nov 2021 18:03:33 +0000 (10:03 -0800)
49 files changed:
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptAcquireContext_IntPtr.cs [moved from src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/Native/Interop.cryptoapi.cs with 58% similarity]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CERT_CHAIN_ENGINE_CONFIG.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertChainFlags.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStore.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreFlags.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreType.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertCreateCertificateChainEngine.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertDeleteCertificateFromStore.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindCertificateInStore.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindExtension.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindFlags.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindType.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChain.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChainEngine.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetCertificateChain.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetIntendedKeyUsage.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetValidUsages.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertSaveStore.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveAs.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveTo.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertVerifyTimeValidity.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.ChainEngine.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.ChainEngineConfigFlags.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptAcquireCertificatePrivateKey_SafeNCryptKeyHandle.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptDecodeObjectPointer_IntPtr.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptDecodeObjectPointer_string.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptHashPublicKeyInfo.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptImportPublicKeyInfoEx2.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptImportPublicKeyInfoFlags.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.X509KeyUsageFlags.cs [new file with mode: 0644]
src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeCertContextHandleWithKeyContainerDeletion.cs
src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeChainEngineHandle.cs [new file with mode: 0644]
src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeX509ChainHandle.cs [moved from src/libraries/System.Security.Cryptography.X509Certificates/src/Microsoft/Win32/SafeHandles/SafeX509ChainHandle.cs with 93% similarity]
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.Import.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.PrivateKey.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.BuildChain.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/FindPal.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/Native/Helpers.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/Native/Interop.crypt32.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/Native/Primitives.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/Native/SafeHandles.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/StorePal.Export.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/StorePal.Import.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/StorePal.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.CustomExtensions.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.PublicKey.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System.Security.Cryptography.X509Certificates.csproj

@@ -6,10 +6,15 @@ using System.Runtime.InteropServices;
 
 internal static partial class Interop
 {
-    public static partial class cryptoapi
+    internal static partial class Advapi32
     {
         [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "CryptAcquireContextW", CharSet = CharSet.Unicode, SetLastError = true)]
         [return: MarshalAs(UnmanagedType.Bool)]
-        public static unsafe partial bool CryptAcquireContext(out IntPtr psafeProvHandle, char* pszContainer, char* pszProvider, int dwProvType, Crypt32.CryptAcquireContextFlags dwFlags);
+        internal static unsafe partial bool CryptAcquireContext(
+            out IntPtr psafeProvHandle,
+            char* pszContainer,
+            char* pszProvider,
+            int dwProvType,
+            Interop.Crypt32.CryptAcquireContextFlags dwFlags);
     }
 }
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CERT_CHAIN_ENGINE_CONFIG.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CERT_CHAIN_ENGINE_CONFIG.cs
new file mode 100644 (file)
index 0000000..7597ea1
--- /dev/null
@@ -0,0 +1,28 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [StructLayout(LayoutKind.Sequential)]
+        internal struct CERT_CHAIN_ENGINE_CONFIG
+        {
+            public int cbSize;
+            public IntPtr hRestrictedRoot;
+            public IntPtr hRestrictedTrust;
+            public IntPtr hRestrictedOther;
+            public int cAdditionalStore;
+            public IntPtr rghAdditionalStore;
+            public ChainEngineConfigFlags dwFlags;
+            public int dwUrlRetrievalTimeout;
+            public int MaximumCachedCertificates;
+            public int CycleDetectionModulus;
+            public IntPtr hExclusiveRoot;
+            public IntPtr hExclusiveTrustedPeople;
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertChainFlags.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertChainFlags.cs
new file mode 100644 (file)
index 0000000..748fc10
--- /dev/null
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [Flags]
+        internal enum CertChainFlags : int
+        {
+            None                                           = 0x00000000,
+            CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE       = 0x00000100,
+            CERT_CHAIN_DISABLE_AIA                         = 0x00002000,
+            CERT_CHAIN_REVOCATION_CHECK_END_CERT           = 0x10000000,
+            CERT_CHAIN_REVOCATION_CHECK_CHAIN              = 0x20000000,
+            CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = 0x40000000,
+            CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY         = unchecked((int)0x80000000),
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStore.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStore.cs
new file mode 100644 (file)
index 0000000..5d3a993
--- /dev/null
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static partial bool CertControlStore(SafeCertStoreHandle hCertStore, CertControlStoreFlags dwFlags, CertControlStoreType dwControlType, IntPtr pvCtrlPara);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreFlags.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreFlags.cs
new file mode 100644 (file)
index 0000000..9f4baff
--- /dev/null
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [Flags]
+        internal enum CertControlStoreFlags : int
+        {
+            None = 0x00000000,
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreType.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreType.cs
new file mode 100644 (file)
index 0000000..a0f04a1
--- /dev/null
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        internal enum CertControlStoreType : int
+        {
+            CERT_STORE_CTRL_AUTO_RESYNC = 4,
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertCreateCertificateChainEngine.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertCreateCertificateChainEngine.cs
new file mode 100644 (file)
index 0000000..65bc29d
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static partial bool CertCreateCertificateChainEngine(ref CERT_CHAIN_ENGINE_CONFIG pConfig, out SafeChainEngineHandle hChainEngineHandle);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertDeleteCertificateFromStore.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertDeleteCertificateFromStore.cs
new file mode 100644 (file)
index 0000000..df9e431
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        // Note: CertDeleteCertificateFromStore always calls CertFreeCertificateContext on pCertContext, even if an error is encountered.
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial bool CertDeleteCertificateFromStore(CERT_CONTEXT* pCertContext);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindCertificateInStore.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindCertificateInStore.cs
new file mode 100644 (file)
index 0000000..3a54008
--- /dev/null
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial SafeCertContextHandle CertFindCertificateInStore(
+            SafeCertStoreHandle hCertStore,
+            CertEncodingType dwCertEncodingType,
+            CertFindFlags dwFindFlags,
+            CertFindType dwFindType,
+            void* pvFindPara,
+            CERT_CONTEXT* pPrevCertContext);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindExtension.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindExtension.cs
new file mode 100644 (file)
index 0000000..da00ba4
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial CERT_EXTENSION* CertFindExtension([MarshalAs(UnmanagedType.LPStr)] string pszObjId, int cExtensions, IntPtr rgExtensions);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindFlags.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindFlags.cs
new file mode 100644 (file)
index 0000000..35d76fe
--- /dev/null
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [Flags]
+        internal enum CertFindFlags : int
+        {
+            None = 0x00000000,
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindType.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindType.cs
new file mode 100644 (file)
index 0000000..ebb7918
--- /dev/null
@@ -0,0 +1,18 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        internal enum CertFindType : int
+        {
+            CERT_FIND_SUBJECT_CERT = 0x000b0000,
+            CERT_FIND_HASH         = 0x00010000,
+            CERT_FIND_SUBJECT_STR  = 0x00080007,
+            CERT_FIND_ISSUER_STR   = 0x00080004,
+            CERT_FIND_EXISTING     = 0x000d0000,
+            CERT_FIND_ANY          = 0x00000000,
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChain.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChain.cs
new file mode 100644 (file)
index 0000000..c92ccaf
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static partial void CertFreeCertificateChain(IntPtr pChainContext);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChainEngine.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChainEngine.cs
new file mode 100644 (file)
index 0000000..425dbe7
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32)]
+        internal static partial void CertFreeCertificateChainEngine(IntPtr hChainEngine);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetCertificateChain.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetCertificateChain.cs
new file mode 100644 (file)
index 0000000..ea7f477
--- /dev/null
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, SetLastError = true)]
+        internal static unsafe partial bool CertGetCertificateChain(
+            IntPtr hChainEngine,
+            SafeCertContextHandle pCertContext,
+            FILETIME* pTime,
+            SafeCertStoreHandle hStore,
+            ref CERT_CHAIN_PARA pChainPara,
+            CertChainFlags dwFlags,
+            IntPtr pvReserved,
+            out SafeX509ChainHandle ppChainContext);
+
+        [StructLayout(LayoutKind.Sequential)]
+        internal unsafe struct CERT_CHAIN_PARA
+        {
+            public int cbSize;
+            public CERT_USAGE_MATCH RequestedUsage;
+            public CERT_USAGE_MATCH RequestedIssuancePolicy;
+            public int dwUrlRetrievalTimeout;
+            public int fCheckRevocationFreshnessTime;
+            public int dwRevocationFreshnessTime;
+            public FILETIME* pftCacheResync;
+            public int pStrongSignPara;
+            public int dwStrongSignFlags;
+        }
+
+        [StructLayout(LayoutKind.Sequential)]
+        internal struct CERT_USAGE_MATCH
+        {
+            public CertUsageMatchType dwType;
+            public CTL_USAGE Usage;
+        }
+
+        internal enum CertUsageMatchType : int
+        {
+            USAGE_MATCH_TYPE_AND = 0x00000000,
+            USAGE_MATCH_TYPE_OR = 0x00000001,
+        }
+
+        [StructLayout(LayoutKind.Sequential)]
+        internal struct CTL_USAGE
+        {
+            public int cUsageIdentifier;
+            public IntPtr rgpszUsageIdentifier;
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetIntendedKeyUsage.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetIntendedKeyUsage.cs
new file mode 100644 (file)
index 0000000..ab9cb7a
--- /dev/null
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        // Note: It's somewhat unusual to use an API enum as a parameter type to a P/Invoke but in this case, X509KeyUsageFlags was intentionally designed as bit-wise
+        // identical to the wincrypt CERT_*_USAGE values.
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial bool CertGetIntendedKeyUsage(
+            CertEncodingType dwCertEncodingType,
+            CERT_INFO* pCertInfo,
+            out X509KeyUsageFlags pbKeyUsage,
+            int cbKeyUsage);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetValidUsages.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetValidUsages.cs
new file mode 100644 (file)
index 0000000..5e4dcf1
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial bool CertGetValidUsages(int cCerts, ref SafeCertContextHandle rghCerts, out int cNumOIDs, void* rghOIDs, ref int pcbOIDs);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertSaveStore.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertSaveStore.cs
new file mode 100644 (file)
index 0000000..56d777d
--- /dev/null
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        public static partial bool CertSaveStore(
+            SafeCertStoreHandle hCertStore,
+            CertEncodingType dwMsgAndCertEncodingType,
+            CertStoreSaveAs dwSaveAs,
+            CertStoreSaveTo dwSaveTo,
+            ref DATA_BLOB pvSaveToPara,
+            int dwFlags);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveAs.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveAs.cs
new file mode 100644 (file)
index 0000000..7165691
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        internal enum CertStoreSaveAs :  int
+        {
+            CERT_STORE_SAVE_AS_STORE = 1,
+            CERT_STORE_SAVE_AS_PKCS7 = 2,
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveTo.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveTo.cs
new file mode 100644 (file)
index 0000000..bc517d1
--- /dev/null
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        internal enum CertStoreSaveTo : int
+        {
+            CERT_STORE_SAVE_TO_MEMORY = 2
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertVerifyTimeValidity.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertVerifyTimeValidity.cs
new file mode 100644 (file)
index 0000000..5d7a09d
--- /dev/null
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial int CertVerifyTimeValidity(ref FILETIME pTimeToVerify, CERT_INFO* pCertInfo);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.ChainEngine.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.ChainEngine.cs
new file mode 100644 (file)
index 0000000..0f5c7db
--- /dev/null
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        internal enum ChainEngine : int
+        {
+            HCCE_CURRENT_USER = 0x0,
+            HCCE_LOCAL_MACHINE = 0x1,
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.ChainEngineConfigFlags.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.ChainEngineConfigFlags.cs
new file mode 100644 (file)
index 0000000..688cc71
--- /dev/null
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [Flags]
+        internal enum ChainEngineConfigFlags : int
+        {
+            CERT_CHAIN_CACHE_END_CERT = 0x00000001,
+            CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL = 0x00000004,
+            CERT_CHAIN_USE_LOCAL_MACHINE_STORE = 0x00000008,
+            CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE = 0x00000010,
+            CERT_CHAIN_ENABLE_SHARE_STORE = 0x00000020,
+            CERT_CHAIN_DISABLE_AIA = 0x00002000,
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptAcquireCertificatePrivateKey_SafeNCryptKeyHandle.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptAcquireCertificatePrivateKey_SafeNCryptKeyHandle.cs
new file mode 100644 (file)
index 0000000..24bf185
--- /dev/null
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        public static partial bool CryptAcquireCertificatePrivateKey(
+            SafeCertContextHandle pCert,
+            CryptAcquireCertificatePrivateKeyFlags dwFlags,
+            IntPtr pvParameters,
+            out SafeNCryptKeyHandle phCryptProvOrNCryptKey,
+            out CryptKeySpec pdwKeySpec,
+            out bool pfCallerFreeProvOrNCryptKey);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptDecodeObjectPointer_IntPtr.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptDecodeObjectPointer_IntPtr.cs
new file mode 100644 (file)
index 0000000..2a3535a
--- /dev/null
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, EntryPoint = "CryptDecodeObject", CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial bool CryptDecodeObjectPointer(
+            CertEncodingType dwCertEncodingType,
+            IntPtr lpszStructType,
+            byte[] pbEncoded,
+            int cbEncoded,
+            CryptDecodeObjectFlags dwFlags,
+            void* pvStructInfo,
+            ref int pcbStructInfo);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptDecodeObjectPointer_string.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptDecodeObjectPointer_string.cs
new file mode 100644 (file)
index 0000000..bbe4794
--- /dev/null
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, EntryPoint = "CryptDecodeObject", CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial bool CryptDecodeObjectPointer(
+            CertEncodingType dwCertEncodingType,
+            [MarshalAs(UnmanagedType.LPStr)] string lpszStructType,
+            byte[] pbEncoded, int cbEncoded,
+            CryptDecodeObjectFlags dwFlags,
+            void* pvStructInfo,
+            ref int pcbStructInfo);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptHashPublicKeyInfo.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptHashPublicKeyInfo.cs
new file mode 100644 (file)
index 0000000..0098acc
--- /dev/null
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static partial bool CryptHashPublicKeyInfo(
+            IntPtr hCryptProv,
+            int algId,
+            int dwFlags,
+            CertEncodingType dwCertEncodingType,
+            ref CERT_PUBLIC_KEY_INFO pInfo,
+            byte[] pbComputedHash,
+            ref int pcbComputedHash);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptImportPublicKeyInfoEx2.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptImportPublicKeyInfoEx2.cs
new file mode 100644 (file)
index 0000000..0d0d38f
--- /dev/null
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe partial bool CryptImportPublicKeyInfoEx2(
+            CertEncodingType dwCertEncodingType,
+            CERT_PUBLIC_KEY_INFO* pInfo,
+            CryptImportPublicKeyInfoFlags dwFlags,
+            void* pvAuxInfo,
+            out SafeBCryptKeyHandle phKey);
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptImportPublicKeyInfoFlags.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptImportPublicKeyInfoFlags.cs
new file mode 100644 (file)
index 0000000..776c2f9
--- /dev/null
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [Flags]
+        internal enum CryptImportPublicKeyInfoFlags
+        {
+            NONE = 0,
+            CRYPT_OID_INFO_PUBKEY_ENCRYPT_KEY_FLAG = 0x40000000,
+        }
+    }
+}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.X509KeyUsageFlags.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.X509KeyUsageFlags.cs
new file mode 100644 (file)
index 0000000..ff5130a
--- /dev/null
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+internal static partial class Interop
+{
+    internal static partial class Crypt32
+    {
+        [Flags]
+        public enum X509KeyUsageFlags
+        {
+            None = 0x0000,
+            EncipherOnly = 0x0001,
+            CrlSign = 0x0002,
+            KeyCertSign = 0x0004,
+            KeyAgreement = 0x0008,
+            DataEncipherment = 0x0010,
+            KeyEncipherment = 0x0020,
+            NonRepudiation = 0x0040,
+            DigitalSignature = 0x0080,
+            DecipherOnly = 0x8000,
+        }
+    }
+}
index 503b451..7488f62 100644 (file)
@@ -68,7 +68,7 @@ namespace Microsoft.Win32.SafeHandles
                     {
                         Interop.Crypt32.CryptAcquireContextFlags flags = (pProvInfo->dwFlags & Interop.Crypt32.CryptAcquireContextFlags.CRYPT_MACHINE_KEYSET) | Interop.Crypt32.CryptAcquireContextFlags.CRYPT_DELETEKEYSET;
                         IntPtr hProv;
-                        _ = Interop.cryptoapi.CryptAcquireContext(out hProv, pProvInfo->pwszContainerName, pProvInfo->pwszProvName, pProvInfo->dwProvType, flags);
+                        _ = Interop.Advapi32.CryptAcquireContext(out hProv, pProvInfo->pwszContainerName, pProvInfo->pwszProvName, pProvInfo->dwProvType, flags);
 
                         // Called CryptAcquireContext solely for the side effect of deleting the key containers. When called with these flags, no actual
                         // hProv is returned (so there's nothing to clean up.)
diff --git a/src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeChainEngineHandle.cs b/src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeChainEngineHandle.cs
new file mode 100644 (file)
index 0000000..516a159
--- /dev/null
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+namespace Microsoft.Win32.SafeHandles
+{
+    internal sealed class SafeChainEngineHandle : SafeHandleZeroOrMinusOneIsInvalid
+    {
+        public SafeChainEngineHandle()
+            : base(true)
+        {
+        }
+
+        private SafeChainEngineHandle(IntPtr handle)
+            : base(true)
+        {
+            SetHandle(handle);
+        }
+
+        public static readonly SafeChainEngineHandle MachineChainEngine =
+            new SafeChainEngineHandle((IntPtr)Interop.Crypt32.ChainEngine.HCCE_LOCAL_MACHINE);
+
+        public static readonly SafeChainEngineHandle UserChainEngine =
+            new SafeChainEngineHandle((IntPtr)Interop.Crypt32.ChainEngine.HCCE_CURRENT_USER);
+
+        protected sealed override bool ReleaseHandle()
+        {
+            Interop.Crypt32.CertFreeCertificateChainEngine(handle);
+            SetHandle(IntPtr.Zero);
+            return true;
+        }
+
+        protected override void Dispose(bool disposing)
+        {
+            if (this != UserChainEngine && this != MachineChainEngine)
+            {
+                base.Dispose(disposing);
+            }
+        }
+    }
+}
index bb6da36..d9c2d13 100644 (file)
@@ -139,7 +139,7 @@ namespace Internal.Cryptography.Pal
                 certInfo.SerialNumber.pbData = pCmsgSignerInfo->SerialNumber.pbData;
 
                 SafeCertContextHandle? pCertContext = null;
-                if (!Interop.crypt32.CertFindCertificateInStore(hCertStore, CertFindType.CERT_FIND_SUBJECT_CERT, &certInfo, ref pCertContext))
+                if (!Interop.crypt32.CertFindCertificateInStore(hCertStore, Interop.Crypt32.CertFindType.CERT_FIND_SUBJECT_CERT, &certInfo, ref pCertContext))
                     throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
                 return pCertContext;
             }
index 52340e8..95210c8 100644 (file)
@@ -271,7 +271,7 @@ namespace Internal.Cryptography.Pal
                 int keySpec = 0;
                 if (!Interop.crypt32.CryptAcquireCertificatePrivateKey(
                     certificateContext,
-                    CryptAcquireFlags.CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG,
+                    Interop.Crypt32.CryptAcquireCertificatePrivateKeyFlags.CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG,
                     IntPtr.Zero,
                     out privateKey,
                     out keySpec,
index 1c17b39..65bff14 100644 (file)
@@ -141,9 +141,9 @@ namespace Internal.Cryptography.Pal
                     int cbData = 0;
                     if (!Interop.Crypt32.CertGetCertificateContextProperty(_certContext, Interop.Crypt32.CertContextPropId.CERT_PUBKEY_ALG_PARA_PROP_ID, null, ref cbData))
                     {
-                        CERT_CHAIN_PARA chainPara = default;
-                        chainPara.cbSize = sizeof(CERT_CHAIN_PARA);
-                        if (!Interop.crypt32.CertGetCertificateChain((IntPtr)ChainEngine.HCCE_CURRENT_USER, _certContext, null, SafeCertStoreHandle.InvalidHandle, ref chainPara, CertChainFlags.None, IntPtr.Zero, out certChainContext))
+                        Interop.Crypt32.CERT_CHAIN_PARA chainPara = default;
+                        chainPara.cbSize = sizeof(Interop.Crypt32.CERT_CHAIN_PARA);
+                        if (!Interop.Crypt32.CertGetCertificateChain((IntPtr)Interop.Crypt32.ChainEngine.HCCE_CURRENT_USER, _certContext, null, SafeCertStoreHandle.InvalidHandle, ref chainPara, Interop.Crypt32.CertChainFlags.None, IntPtr.Zero, out certChainContext))
                             throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
                         if (!Interop.Crypt32.CertGetCertificateContextProperty(_certContext, Interop.Crypt32.CertContextPropId.CERT_PUBKEY_ALG_PARA_PROP_ID, null, ref cbData))
                             throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
index 0c3875d..ce38255 100644 (file)
@@ -40,15 +40,15 @@ namespace Internal.Cryptography.Pal
                 using (SafeChainEngineHandle storeHandle = GetChainEngine(trustMode, customTrustStore, useMachineContext))
                 using (SafeCertStoreHandle extraStoreHandle = ConvertStoreToSafeHandle(extraStore))
                 {
-                    CERT_CHAIN_PARA chainPara = default;
-                    chainPara.cbSize = Marshal.SizeOf<CERT_CHAIN_PARA>();
+                    Interop.Crypt32.CERT_CHAIN_PARA chainPara = default;
+                    chainPara.cbSize = Marshal.SizeOf<Interop.Crypt32.CERT_CHAIN_PARA>();
 
                     int applicationPolicyCount;
                     using (SafeHandle applicationPolicyOids = applicationPolicy!.ToLpstrArray(out applicationPolicyCount))
                     {
                         if (!applicationPolicyOids.IsInvalid)
                         {
-                            chainPara.RequestedUsage.dwType = CertUsageMatchType.USAGE_MATCH_TYPE_AND;
+                            chainPara.RequestedUsage.dwType = Interop.Crypt32.CertUsageMatchType.USAGE_MATCH_TYPE_AND;
                             chainPara.RequestedUsage.Usage.cUsageIdentifier = applicationPolicyCount;
                             chainPara.RequestedUsage.Usage.rgpszUsageIdentifier = applicationPolicyOids.DangerousGetHandle();
                         }
@@ -58,7 +58,7 @@ namespace Internal.Cryptography.Pal
                         {
                             if (!certificatePolicyOids.IsInvalid)
                             {
-                                chainPara.RequestedIssuancePolicy.dwType = CertUsageMatchType.USAGE_MATCH_TYPE_AND;
+                                chainPara.RequestedIssuancePolicy.dwType = Interop.Crypt32.CertUsageMatchType.USAGE_MATCH_TYPE_AND;
                                 chainPara.RequestedIssuancePolicy.Usage.cUsageIdentifier = certificatePolicyCount;
                                 chainPara.RequestedIssuancePolicy.Usage.rgpszUsageIdentifier = certificatePolicyOids.DangerousGetHandle();
                             }
@@ -66,9 +66,9 @@ namespace Internal.Cryptography.Pal
                             chainPara.dwUrlRetrievalTimeout = (int)Math.Floor(timeout.TotalMilliseconds);
 
                             Interop.Crypt32.FILETIME ft = Interop.Crypt32.FILETIME.FromDateTime(verificationTime);
-                            CertChainFlags flags = MapRevocationFlags(revocationMode, revocationFlag, disableAia);
+                            Interop.Crypt32.CertChainFlags flags = MapRevocationFlags(revocationMode, revocationFlag, disableAia);
                             SafeX509ChainHandle chain;
-                            if (!Interop.crypt32.CertGetCertificateChain(storeHandle.DangerousGetHandle(), certificatePal.CertContext, &ft, extraStoreHandle, ref chainPara, flags, IntPtr.Zero, out chain))
+                            if (!Interop.Crypt32.CertGetCertificateChain(storeHandle.DangerousGetHandle(), certificatePal.CertContext, &ft, extraStoreHandle, ref chainPara, flags, IntPtr.Zero, out chain))
                             {
                                 return null;
                             }
@@ -91,8 +91,8 @@ namespace Internal.Cryptography.Pal
                 // Need to get a valid SafeCertStoreHandle otherwise the default stores will be trusted
                 using (SafeCertStoreHandle customTrustStoreHandle = ConvertStoreToSafeHandle(customTrustStore, true))
                 {
-                    CERT_CHAIN_ENGINE_CONFIG customChainEngine = default;
-                    customChainEngine.cbSize = Marshal.SizeOf<CERT_CHAIN_ENGINE_CONFIG>();
+                    Interop.Crypt32.CERT_CHAIN_ENGINE_CONFIG customChainEngine = default;
+                    customChainEngine.cbSize = Marshal.SizeOf<Interop.Crypt32.CERT_CHAIN_ENGINE_CONFIG>();
                     customChainEngine.hExclusiveRoot = customTrustStoreHandle.DangerousGetHandle();
                     chainEngineHandle = Interop.crypt32.CertCreateCertificateChainEngine(ref customChainEngine);
                 }
@@ -113,28 +113,28 @@ namespace Internal.Cryptography.Pal
             return ((StorePal)StorePal.LinkFromCertificateCollection(extraStore!)).SafeCertStoreHandle;
         }
 
-        private static CertChainFlags MapRevocationFlags(
+        private static Interop.Crypt32.CertChainFlags MapRevocationFlags(
             X509RevocationMode revocationMode,
             X509RevocationFlag revocationFlag,
             bool disableAia)
         {
-            const CertChainFlags AiaDisabledFlags =
-                CertChainFlags.CERT_CHAIN_DISABLE_AIA | CertChainFlags.CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE;
+            const Interop.Crypt32.CertChainFlags AiaDisabledFlags =
+                Interop.Crypt32.CertChainFlags.CERT_CHAIN_DISABLE_AIA | Interop.Crypt32.CertChainFlags.CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE;
 
-            CertChainFlags dwFlags = disableAia ? AiaDisabledFlags : CertChainFlags.None;
+            Interop.Crypt32.CertChainFlags dwFlags = disableAia ? AiaDisabledFlags : Interop.Crypt32.CertChainFlags.None;
 
             if (revocationMode == X509RevocationMode.NoCheck)
                 return dwFlags;
 
             if (revocationMode == X509RevocationMode.Offline)
-                dwFlags |= CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY;
+                dwFlags |= Interop.Crypt32.CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY;
 
             if (revocationFlag == X509RevocationFlag.EndCertificateOnly)
-                dwFlags |= CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_END_CERT;
+                dwFlags |= Interop.Crypt32.CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_END_CERT;
             else if (revocationFlag == X509RevocationFlag.EntireChain)
-                dwFlags |= CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_CHAIN;
+                dwFlags |= Interop.Crypt32.CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_CHAIN;
             else
-                dwFlags |= CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
+                dwFlags |= Interop.Crypt32.CertChainFlags.CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
 
             return dwFlags;
         }
index ff76807..5b80a71 100644 (file)
@@ -36,12 +36,12 @@ namespace Internal.Cryptography.Pal
 
             unsafe
             {
-                CERT_CHAIN_POLICY_PARA para = default;
-                para.cbSize = sizeof(CERT_CHAIN_POLICY_PARA);
-                para.dwFlags = (int)flags;
+                Interop.Crypt32.CERT_CHAIN_POLICY_PARA para = default;
+                para.cbSize = (uint)sizeof(Interop.Crypt32.CERT_CHAIN_POLICY_PARA);
+                para.dwFlags = (uint)flags;
 
-                CERT_CHAIN_POLICY_STATUS status = default;
-                status.cbSize = sizeof(CERT_CHAIN_POLICY_STATUS);
+                Interop.Crypt32.CERT_CHAIN_POLICY_STATUS status = default;
+                status.cbSize = (uint)sizeof(Interop.Crypt32.CERT_CHAIN_POLICY_STATUS);
 
                 if (!Interop.crypt32.CertVerifyCertificateChainPolicy(ChainPolicy.CERT_CHAIN_POLICY_BASE, _chain, ref para, ref status))
                 {
@@ -105,7 +105,7 @@ namespace Internal.Cryptography.Pal
 
         public static bool ReleaseSafeX509ChainHandle(IntPtr handle)
         {
-            Interop.crypt32.CertFreeCertificateChain(handle);
+            Interop.Crypt32.CertFreeCertificateChain(handle);
             return true;
         }
 
index b3cbcaf..4cadc49 100644 (file)
@@ -48,7 +48,7 @@ namespace Internal.Cryptography.Pal
             fixed (byte* pThumbPrint = thumbPrint)
             {
                 Interop.Crypt32.DATA_BLOB blob = new Interop.Crypt32.DATA_BLOB(new IntPtr(pThumbPrint), (uint)thumbPrint.Length);
-                FindCore<object>(CertFindType.CERT_FIND_HASH, &blob);
+                FindCore<object>(Interop.Crypt32.CertFindType.CERT_FIND_HASH, &blob);
             }
         }
 
@@ -56,7 +56,7 @@ namespace Internal.Cryptography.Pal
         {
             fixed (char* pSubjectName = subjectName)
             {
-                FindCore<object>(CertFindType.CERT_FIND_SUBJECT_STR, pSubjectName);
+                FindCore<object>(Interop.Crypt32.CertFindType.CERT_FIND_SUBJECT_STR, pSubjectName);
             }
         }
 
@@ -75,7 +75,7 @@ namespace Internal.Cryptography.Pal
         {
             fixed (char* pIssuerName = issuerName)
             {
-                FindCore<object>(CertFindType.CERT_FIND_ISSUER_STR, pIssuerName);
+                FindCore<object>(Interop.Crypt32.CertFindType.CERT_FIND_ISSUER_STR, pIssuerName);
             }
         }
 
@@ -129,7 +129,7 @@ namespace Internal.Cryptography.Pal
                 (fileTime, compareResult),
                 static (state, pCertContext) =>
                 {
-                    int comparison = Interop.crypt32.CertVerifyTimeValidity(ref state.fileTime,
+                    int comparison = Interop.Crypt32.CertVerifyTimeValidity(ref state.fileTime,
                         pCertContext.CertContext->pCertInfo);
                     GC.KeepAlive(pCertContext);
                     return comparison == state.compareResult;
@@ -149,7 +149,7 @@ namespace Internal.Cryptography.Pal
                     bool foundMatch = false;
                     Interop.Crypt32.CERT_INFO* pCertInfo = pCertContext.CertContext->pCertInfo;
                     {
-                        Interop.Crypt32.CERT_EXTENSION* pV1Template = Interop.crypt32.CertFindExtension(Oids.EnrollCertTypeExtension,
+                        Interop.Crypt32.CERT_EXTENSION* pV1Template = Interop.Crypt32.CertFindExtension(Oids.EnrollCertTypeExtension,
                             pCertInfo->cExtension, pCertInfo->rgExtension);
                         if (pV1Template != null)
                         {
@@ -172,7 +172,7 @@ namespace Internal.Cryptography.Pal
 
                     if (!foundMatch)
                     {
-                        Interop.Crypt32.CERT_EXTENSION* pV2Template = Interop.crypt32.CertFindExtension(Oids.CertificateTemplate,
+                        Interop.Crypt32.CERT_EXTENSION* pV2Template = Interop.Crypt32.CertFindExtension(Oids.CertificateTemplate,
                             pCertInfo->cExtension, pCertInfo->rgExtension);
                         if (pV2Template != null)
                         {
@@ -211,7 +211,7 @@ namespace Internal.Cryptography.Pal
                 {
                     int numOids;
                     int cbData = 0;
-                    if (!Interop.crypt32.CertGetValidUsages(1, ref pCertContext, out numOids, null, ref cbData))
+                    if (!Interop.Crypt32.CertGetValidUsages(1, ref pCertContext, out numOids, null, ref cbData))
                         return false;
 
                     // -1 means the certificate is good for all usages.
@@ -220,7 +220,7 @@ namespace Internal.Cryptography.Pal
 
                     fixed (byte* pOidsPointer = new byte[cbData])
                     {
-                        if (!Interop.crypt32.CertGetValidUsages(1, ref pCertContext, out numOids, pOidsPointer, ref cbData))
+                        if (!Interop.Crypt32.CertGetValidUsages(1, ref pCertContext, out numOids, pOidsPointer, ref cbData))
                             return false;
 
                         IntPtr* pOids = (IntPtr*)pOidsPointer;
@@ -242,7 +242,7 @@ namespace Internal.Cryptography.Pal
                 static (oidValue, pCertContext) =>
                 {
                     Interop.Crypt32.CERT_INFO* pCertInfo = pCertContext.CertContext->pCertInfo;
-                    Interop.Crypt32.CERT_EXTENSION* pCertExtension = Interop.crypt32.CertFindExtension(Oids.CertPolicies,
+                    Interop.Crypt32.CERT_EXTENSION* pCertExtension = Interop.Crypt32.CertFindExtension(Oids.CertPolicies,
                         pCertInfo->cExtension, pCertInfo->rgExtension);
                     if (pCertExtension == null)
                         return false;
@@ -283,7 +283,7 @@ namespace Internal.Cryptography.Pal
                 static (oidValue, pCertContext) =>
                 {
                     Interop.Crypt32.CERT_INFO* pCertInfo = pCertContext.CertContext->pCertInfo;
-                    Interop.Crypt32.CERT_EXTENSION* pCertExtension = Interop.crypt32.CertFindExtension(oidValue, pCertInfo->cExtension, pCertInfo->rgExtension);
+                    Interop.Crypt32.CERT_EXTENSION* pCertExtension = Interop.Crypt32.CertFindExtension(oidValue, pCertInfo->cExtension, pCertInfo->rgExtension);
                     GC.KeepAlive(pCertContext);
                     return pCertExtension != null;
                 });
@@ -329,10 +329,10 @@ namespace Internal.Cryptography.Pal
 
         private unsafe void FindCore<TState>(TState state, Func<TState, SafeCertContextHandle, bool> filter)
         {
-            FindCore(CertFindType.CERT_FIND_ANY, null, state, filter);
+            FindCore(Interop.Crypt32.CertFindType.CERT_FIND_ANY, null, state, filter);
         }
 
-        private unsafe void FindCore<TState>(CertFindType dwFindType, void* pvFindPara, TState state = default!, Func<TState, SafeCertContextHandle, bool>? filter = null)
+        private unsafe void FindCore<TState>(Interop.Crypt32.CertFindType dwFindType, void* pvFindPara, TState state = default!, Func<TState, SafeCertContextHandle, bool>? filter = null)
         {
             SafeCertStoreHandle findResults = Interop.crypt32.CertOpenStore(
                 CertStoreProvider.CERT_STORE_PROV_MEMORY,
index 3d41a6d..07dc27d 100644 (file)
@@ -123,7 +123,7 @@ namespace Internal.Cryptography.Pal.Native
             {
                 int cb = 0;
 
-                if (!Interop.crypt32.CryptDecodeObjectPointer(
+                if (!Interop.Crypt32.CryptDecodeObjectPointer(
                     Interop.Crypt32.CertEncodingType.All,
                     lpszStructType,
                     encoded,
@@ -137,7 +137,7 @@ namespace Internal.Cryptography.Pal.Native
 
                 byte* decoded = stackalloc byte[cb];
 
-                if (!Interop.crypt32.CryptDecodeObjectPointer(
+                if (!Interop.Crypt32.CryptDecodeObjectPointer(
                     Interop.Crypt32.CertEncodingType.All,
                     lpszStructType,
                     encoded,
index 7d0516a..8df13c0 100644 (file)
@@ -87,15 +87,9 @@ internal static partial class Interop
 
         public static unsafe bool CryptDecodeObjectPointer(Interop.Crypt32.CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, byte[] pbEncoded, int cbEncoded, Interop.Crypt32.CryptDecodeObjectFlags dwFlags, void* pvStructInfo, ref int pcbStructInfo)
         {
-            return CryptDecodeObjectPointer(dwCertEncodingType, (IntPtr)lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, ref pcbStructInfo);
+            return Interop.Crypt32.CryptDecodeObjectPointer(dwCertEncodingType, (IntPtr)lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, ref pcbStructInfo);
         }
 
-        [GeneratedDllImport(Libraries.Crypt32, EntryPoint = "CryptDecodeObject", CharSet = CharSet.Unicode, SetLastError = true)]
-        private static unsafe partial bool CryptDecodeObjectPointer(Interop.Crypt32.CertEncodingType dwCertEncodingType, IntPtr lpszStructType, byte[] pbEncoded, int cbEncoded, Interop.Crypt32.CryptDecodeObjectFlags dwFlags, void* pvStructInfo, ref int pcbStructInfo);
-
-        [GeneratedDllImport(Libraries.Crypt32, EntryPoint = "CryptDecodeObject", CharSet = CharSet.Unicode, SetLastError = true)]
-        public static unsafe partial bool CryptDecodeObjectPointer(Interop.Crypt32.CertEncodingType dwCertEncodingType, [MarshalAs(UnmanagedType.LPStr)] string lpszStructType, byte[] pbEncoded, int cbEncoded, Interop.Crypt32.CryptDecodeObjectFlags dwFlags, void* pvStructInfo, ref int pcbStructInfo);
-
         public static unsafe bool CryptEncodeObject(Interop.Crypt32.CertEncodingType dwCertEncodingType, CryptDecodeObjectStructType lpszStructType, void* pvStructInfo, byte[]? pbEncoded, ref int pcbEncoded)
         {
             return Interop.Crypt32.CryptEncodeObject(dwCertEncodingType, (IntPtr)lpszStructType, pvStructInfo, pbEncoded, ref pcbEncoded);
@@ -127,9 +121,9 @@ internal static partial class Interop
             return encoded;
         }
 
-        internal static SafeChainEngineHandle CertCreateCertificateChainEngine(ref CERT_CHAIN_ENGINE_CONFIG config)
+        internal static SafeChainEngineHandle CertCreateCertificateChainEngine(ref Interop.Crypt32.CERT_CHAIN_ENGINE_CONFIG config)
         {
-            if (!CertCreateCertificateChainEngine(ref config, out SafeChainEngineHandle chainEngineHandle))
+            if (!Interop.Crypt32.CertCreateCertificateChainEngine(ref config, out SafeChainEngineHandle chainEngineHandle))
             {
                 int errorCode = Marshal.GetLastWin32Error();
                 throw errorCode.ToCryptographicException();
@@ -138,21 +132,6 @@ internal static partial class Interop
             return chainEngineHandle;
         }
 
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        private static partial bool CertCreateCertificateChainEngine(ref CERT_CHAIN_ENGINE_CONFIG pConfig, out SafeChainEngineHandle hChainEngineHandle);
-
-        [GeneratedDllImport(Libraries.Crypt32)]
-        public static partial void CertFreeCertificateChainEngine(IntPtr hChainEngine);
-
-        [GeneratedDllImport(Libraries.Crypt32, SetLastError = true)]
-        public static unsafe partial bool CertGetCertificateChain(IntPtr hChainEngine, SafeCertContextHandle pCertContext, Interop.Crypt32.FILETIME* pTime, SafeCertStoreHandle hStore, ref CERT_CHAIN_PARA pChainPara, CertChainFlags dwFlags, IntPtr pvReserved, out SafeX509ChainHandle ppChainContext);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static partial bool CryptHashPublicKeyInfo(IntPtr hCryptProv, int algId, int dwFlags, Interop.Crypt32.CertEncodingType dwCertEncodingType, ref Interop.Crypt32.CERT_PUBLIC_KEY_INFO pInfo, byte[] pbComputedHash, ref int pcbComputedHash);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static partial bool CertSaveStore(SafeCertStoreHandle hCertStore, Interop.Crypt32.CertEncodingType dwMsgAndCertEncodingType, CertStoreSaveAs dwSaveAs, CertStoreSaveTo dwSaveTo, ref Interop.Crypt32.DATA_BLOB pvSaveToPara, int dwFlags);
-
         /// <summary>
         /// A less error-prone wrapper for CertEnumCertificatesInStore().
         ///
@@ -160,52 +139,30 @@ internal static partial class Interop
         /// the next certificate in the iteration. The final call sets pCertContext to an invalid SafeCertStoreHandle
         /// and returns "false" to indicate the end of the store has been reached.
         /// </summary>
-        public static unsafe bool CertFindCertificateInStore(SafeCertStoreHandle hCertStore, CertFindType dwFindType, void* pvFindPara, [NotNull] ref SafeCertContextHandle? pCertContext)
+        public static unsafe bool CertFindCertificateInStore(SafeCertStoreHandle hCertStore, Interop.Crypt32.CertFindType dwFindType, void* pvFindPara, [NotNull] ref SafeCertContextHandle? pCertContext)
         {
             Interop.Crypt32.CERT_CONTEXT* pPrevCertContext = pCertContext == null ? null : pCertContext.Disconnect();
-            pCertContext = CertFindCertificateInStore(hCertStore, Interop.Crypt32.CertEncodingType.All, CertFindFlags.None, dwFindType, pvFindPara, pPrevCertContext);
+            pCertContext = Interop.Crypt32.CertFindCertificateInStore(hCertStore, Interop.Crypt32.CertEncodingType.All, Interop.Crypt32.CertFindFlags.None, dwFindType, pvFindPara, pPrevCertContext);
             return !pCertContext.IsInvalid;
         }
 
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        private static unsafe partial SafeCertContextHandle CertFindCertificateInStore(SafeCertStoreHandle hCertStore, Interop.Crypt32.CertEncodingType dwCertEncodingType, CertFindFlags dwFindFlags, CertFindType dwFindType, void* pvFindPara, Interop.Crypt32.CERT_CONTEXT* pPrevCertContext);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static unsafe partial int CertVerifyTimeValidity(ref Interop.Crypt32.FILETIME pTimeToVerify, Interop.Crypt32.CERT_INFO* pCertInfo);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static unsafe partial Interop.Crypt32.CERT_EXTENSION* CertFindExtension([MarshalAs(UnmanagedType.LPStr)] string pszObjId, int cExtensions, IntPtr rgExtensions);
-
-        // Note: It's somewhat unusual to use an API enum as a parameter type to a P/Invoke but in this case, X509KeyUsageFlags was intentionally designed as bit-wise
-        // identical to the wincrypt CERT_*_USAGE values.
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static unsafe partial bool CertGetIntendedKeyUsage(Interop.Crypt32.CertEncodingType dwCertEncodingType, Interop.Crypt32.CERT_INFO* pCertInfo, out X509KeyUsageFlags pbKeyUsage, int cbKeyUsage);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static unsafe partial bool CertGetValidUsages(int cCerts, ref SafeCertContextHandle rghCerts, out int cNumOIDs, void* rghOIDs, ref int pcbOIDs);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static partial bool CertControlStore(SafeCertStoreHandle hCertStore, CertControlStoreFlags dwFlags, CertControlStoreType dwControlType, IntPtr pvCtrlPara);
-
-        // Note: CertDeleteCertificateFromStore always calls CertFreeCertificateContext on pCertContext, even if an error is encountered.
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static unsafe partial bool CertDeleteCertificateFromStore(Interop.Crypt32.CERT_CONTEXT* pCertContext);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static partial void CertFreeCertificateChain(IntPtr pChainContext);
-
-        public static bool CertVerifyCertificateChainPolicy(ChainPolicy pszPolicyOID, SafeX509ChainHandle pChainContext, ref CERT_CHAIN_POLICY_PARA pPolicyPara, ref CERT_CHAIN_POLICY_STATUS pPolicyStatus)
+        public static unsafe bool CertGetIntendedKeyUsage(Interop.Crypt32.CertEncodingType dwCertEncodingType, Interop.Crypt32.CERT_INFO* pCertInfo, out X509KeyUsageFlags pbKeyUsage, int cbKeyUsage)
         {
-            return CertVerifyCertificateChainPolicy((IntPtr)pszPolicyOID, pChainContext, ref pPolicyPara, ref pPolicyStatus);
+            bool result = Interop.Crypt32.CertGetIntendedKeyUsage(dwCertEncodingType, pCertInfo, out Interop.Crypt32.X509KeyUsageFlags x509KeyUsageFlags, cbKeyUsage);
+            pbKeyUsage = (X509KeyUsageFlags)(int)x509KeyUsageFlags;
+            return result;
         }
 
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        private static partial bool CertVerifyCertificateChainPolicy(IntPtr pszPolicyOID, SafeX509ChainHandle pChainContext, ref CERT_CHAIN_POLICY_PARA pPolicyPara, ref CERT_CHAIN_POLICY_STATUS pPolicyStatus);
-
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static unsafe partial bool CryptImportPublicKeyInfoEx2(Interop.Crypt32.CertEncodingType dwCertEncodingType, Interop.Crypt32.CERT_PUBLIC_KEY_INFO* pInfo, CryptImportPublicKeyInfoFlags dwFlags, void* pvAuxInfo, out SafeBCryptKeyHandle phKey);
+        public static bool CertVerifyCertificateChainPolicy(ChainPolicy pszPolicyOID, SafeX509ChainHandle pChainContext, ref Interop.Crypt32.CERT_CHAIN_POLICY_PARA pPolicyPara, ref Interop.Crypt32.CERT_CHAIN_POLICY_STATUS pPolicyStatus)
+        {
+            return Interop.Crypt32.CertVerifyCertificateChainPolicy((IntPtr)pszPolicyOID, pChainContext, ref pPolicyPara, ref pPolicyStatus);
+        }
 
-        [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
-        public static partial bool CryptAcquireCertificatePrivateKey(SafeCertContextHandle pCert, CryptAcquireFlags dwFlags, IntPtr pvParameters, out SafeNCryptKeyHandle phCryptProvOrNCryptKey, out int pdwKeySpec, out bool pfCallerFreeProvOrNCryptKey);
+        public static bool CryptAcquireCertificatePrivateKey(SafeCertContextHandle pCert, Interop.Crypt32.CryptAcquireCertificatePrivateKeyFlags dwFlags, IntPtr pvParameters, out SafeNCryptKeyHandle phCryptProvOrNCryptKey, out int pdwKeySpec, out bool pfCallerFreeProvOrNCryptKey)
+        {
+            bool result = Interop.Crypt32.CryptAcquireCertificatePrivateKey(pCert, dwFlags, pvParameters, out phCryptProvOrNCryptKey, out Interop.Crypt32.CryptKeySpec pdwKeySpecEnum, out pfCallerFreeProvOrNCryptKey);
+            pdwKeySpec = (int)pdwKeySpecEnum;
+            return result;
+        }
     }
 }
index 53dbdb8..bec34b9 100644 (file)
@@ -21,22 +21,6 @@ namespace Internal.Cryptography.Pal.Native
         //... more fields follow ...
     }
 
-    [Flags]
-    internal enum CertFindFlags : int
-    {
-        None = 0x00000000,
-    }
-
-    internal enum CertFindType : int
-    {
-        CERT_FIND_SUBJECT_CERT = 0x000b0000,
-        CERT_FIND_HASH         = 0x00010000,
-        CERT_FIND_SUBJECT_STR  = 0x00080007,
-        CERT_FIND_ISSUER_STR   = 0x00080004,
-        CERT_FIND_EXISTING     = 0x000d0000,
-        CERT_FIND_ANY          = 0x00000000,
-    }
-
     internal enum FormatObjectType : int
     {
         None = 0,
@@ -70,58 +54,6 @@ namespace Internal.Cryptography.Pal.Native
     }
 
     [StructLayout(LayoutKind.Sequential)]
-    internal struct CTL_USAGE
-    {
-        public int cUsageIdentifier;
-        public IntPtr rgpszUsageIdentifier;
-    }
-
-    [StructLayout(LayoutKind.Sequential)]
-    internal struct CERT_USAGE_MATCH
-    {
-        public CertUsageMatchType dwType;
-        public CTL_USAGE Usage;
-    }
-
-    internal enum CertUsageMatchType : int
-    {
-        USAGE_MATCH_TYPE_AND = 0x00000000,
-        USAGE_MATCH_TYPE_OR  = 0x00000001,
-    }
-
-    [StructLayout(LayoutKind.Sequential)]
-    internal unsafe struct CERT_CHAIN_PARA
-    {
-        public int cbSize;
-        public CERT_USAGE_MATCH RequestedUsage;
-        public CERT_USAGE_MATCH RequestedIssuancePolicy;
-        public int dwUrlRetrievalTimeout;
-        public int fCheckRevocationFreshnessTime;
-        public int dwRevocationFreshnessTime;
-        public Interop.Crypt32.FILETIME* pftCacheResync;
-        public int pStrongSignPara;
-        public int dwStrongSignFlags;
-    }
-
-    [Flags]
-    internal enum CertChainFlags : int
-    {
-        None                                           = 0x00000000,
-        CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE       = 0x00000100,
-        CERT_CHAIN_DISABLE_AIA                         = 0x00002000,
-        CERT_CHAIN_REVOCATION_CHECK_END_CERT           = 0x10000000,
-        CERT_CHAIN_REVOCATION_CHECK_CHAIN              = 0x20000000,
-        CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = 0x40000000,
-        CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY         = unchecked((int)0x80000000),
-    }
-
-    internal enum ChainEngine : int
-    {
-        HCCE_CURRENT_USER = 0x0,
-        HCCE_LOCAL_MACHINE = 0x1,
-    }
-
-    [StructLayout(LayoutKind.Sequential)]
     internal struct CERT_DSS_PARAMETERS
     {
         public Interop.Crypt32.DATA_BLOB p;
@@ -162,17 +94,6 @@ namespace Internal.Cryptography.Pal.Native
         public IntPtr* rgpszUsageIdentifier; // LPSTR*
     }
 
-    internal enum CertStoreSaveAs :  int
-    {
-        CERT_STORE_SAVE_AS_STORE = 1,
-        CERT_STORE_SAVE_AS_PKCS7 = 2,
-    }
-
-    internal enum CertStoreSaveTo : int
-    {
-        CERT_STORE_SAVE_TO_MEMORY = 2,
-    }
-
     [StructLayout(LayoutKind.Sequential)]
     internal struct CERT_POLICY_INFO
     {
@@ -205,17 +126,6 @@ namespace Internal.Cryptography.Pal.Native
     }
 
     [Flags]
-    internal enum CertControlStoreFlags : int
-    {
-        None = 0x00000000,
-    }
-
-    internal enum CertControlStoreType : int
-    {
-        CERT_STORE_CTRL_AUTO_RESYNC = 4,
-    }
-
-    [Flags]
     internal enum CertTrustErrorStatus : int
     {
         CERT_TRUST_NO_ERROR                            = 0x00000000,
@@ -335,68 +245,9 @@ namespace Internal.Cryptography.Pal.Native
         public Guid ChainId;
     }
 
-    [StructLayout(LayoutKind.Sequential)]
-    internal struct CERT_CHAIN_POLICY_PARA
-    {
-        public int cbSize;
-        public int dwFlags;
-        public IntPtr pvExtraPolicyPara;
-    }
-
-    [StructLayout(LayoutKind.Sequential)]
-    internal struct CERT_CHAIN_POLICY_STATUS
-    {
-        public int cbSize;
-        public int dwError;
-        public IntPtr lChainIndex;
-        public IntPtr lElementIndex;
-        public IntPtr pvExtraPolicyStatus;
-    }
-
     internal enum ChainPolicy : int
     {
         // Predefined verify chain policies
         CERT_CHAIN_POLICY_BASE = 1,
     }
-
-    internal enum CryptAcquireFlags : int
-    {
-        CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG = 0x00040000,
-    }
-
-    [Flags]
-    internal enum ChainEngineConfigFlags : int
-    {
-        CERT_CHAIN_CACHE_END_CERT = 0x00000001,
-        CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL = 0x00000004,
-        CERT_CHAIN_USE_LOCAL_MACHINE_STORE = 0x00000008,
-        CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE = 0x00000010,
-        CERT_CHAIN_ENABLE_SHARE_STORE = 0x00000020,
-        CERT_CHAIN_DISABLE_AIA = 0x00002000,
-    }
-
-    // Windows 7 definition of the struct
-    [StructLayout(LayoutKind.Sequential)]
-    internal struct CERT_CHAIN_ENGINE_CONFIG
-    {
-        public int cbSize;
-        public IntPtr hRestrictedRoot;
-        public IntPtr hRestrictedTrust;
-        public IntPtr hRestrictedOther;
-        public int cAdditionalStore;
-        public IntPtr rghAdditionalStore;
-        public ChainEngineConfigFlags dwFlags;
-        public int dwUrlRetrievalTimeout;
-        public int MaximumCachedCertificates;
-        public int CycleDetectionModulus;
-        public IntPtr hExclusiveRoot;
-        public IntPtr hExclusiveTrustedPeople;
-    }
-
-    [Flags]
-    internal enum CryptImportPublicKeyInfoFlags
-    {
-        NONE = 0,
-        CRYPT_OID_INFO_PUBKEY_ENCRYPT_KEY_FLAG = 0x40000000,
-    }
 }
index 3d8a71f..c9cf3d6 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using Microsoft.Win32.SafeHandles;
-using System;
 using System.Runtime.InteropServices;
 
 #pragma warning disable CA1419 // TODO https://github.com/dotnet/roslyn-analyzers/issues/5232: not intended for use with P/Invoke
@@ -27,39 +26,4 @@ namespace Internal.Cryptography.Pal.Native
             return true;
         }
     }
-
-    internal sealed class SafeChainEngineHandle : SafeHandleZeroOrMinusOneIsInvalid
-    {
-        public SafeChainEngineHandle()
-            : base(true)
-        {
-        }
-
-        private SafeChainEngineHandle(IntPtr handle)
-            : base(true)
-        {
-            SetHandle(handle);
-        }
-
-        public static readonly SafeChainEngineHandle MachineChainEngine =
-            new SafeChainEngineHandle((IntPtr)ChainEngine.HCCE_LOCAL_MACHINE);
-
-        public static readonly SafeChainEngineHandle UserChainEngine =
-            new SafeChainEngineHandle((IntPtr)ChainEngine.HCCE_CURRENT_USER);
-
-        protected sealed override bool ReleaseHandle()
-        {
-            Interop.crypt32.CertFreeCertificateChainEngine(handle);
-            SetHandle(IntPtr.Zero);
-            return true;
-        }
-
-        protected override void Dispose(bool disposing)
-        {
-            if (this != UserChainEngine && this != MachineChainEngine)
-            {
-                base.Dispose(disposing);
-            }
-        }
-    }
 }
index a67477b..2a44fb6 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using Internal.Cryptography.Pal.Native;
 using Microsoft.Win32.SafeHandles;
 using System;
 using System.Diagnostics;
@@ -93,29 +92,29 @@ namespace Internal.Cryptography.Pal
                     }
 
                 case X509ContentType.SerializedStore:
-                    return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_STORE);
+                    return SaveToMemoryStore(Interop.Crypt32.CertStoreSaveAs.CERT_STORE_SAVE_AS_STORE);
 
                 case X509ContentType.Pkcs7:
-                    return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_PKCS7);
+                    return SaveToMemoryStore(Interop.Crypt32.CertStoreSaveAs.CERT_STORE_SAVE_AS_PKCS7);
 
                 default:
                     throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);
             }
         }
 
-        private byte[] SaveToMemoryStore(CertStoreSaveAs dwSaveAs)
+        private byte[] SaveToMemoryStore(Interop.Crypt32.CertStoreSaveAs dwSaveAs)
         {
             unsafe
             {
                 Interop.Crypt32.DATA_BLOB blob = new Interop.Crypt32.DATA_BLOB(IntPtr.Zero, 0);
-                if (!Interop.crypt32.CertSaveStore(_certStore, Interop.Crypt32.CertEncodingType.All, dwSaveAs, CertStoreSaveTo.CERT_STORE_SAVE_TO_MEMORY, ref blob, 0))
+                if (!Interop.Crypt32.CertSaveStore(_certStore, Interop.Crypt32.CertEncodingType.All, dwSaveAs, Interop.Crypt32.CertStoreSaveTo.CERT_STORE_SAVE_TO_MEMORY, ref blob, 0))
                     throw Marshal.GetLastWin32Error().ToCryptographicException();
 
                 byte[] exportedData = new byte[blob.cbData];
                 fixed (byte* pExportedData = exportedData)
                 {
                     blob.pbData = new IntPtr(pExportedData);
-                    if (!Interop.crypt32.CertSaveStore(_certStore, Interop.Crypt32.CertEncodingType.All, dwSaveAs, CertStoreSaveTo.CERT_STORE_SAVE_TO_MEMORY, ref blob, 0))
+                    if (!Interop.Crypt32.CertSaveStore(_certStore, Interop.Crypt32.CertEncodingType.All, dwSaveAs, Interop.Crypt32.CertStoreSaveTo.CERT_STORE_SAVE_TO_MEMORY, ref blob, 0))
                         throw Marshal.GetLastWin32Error().ToCryptographicException();
                 }
 
index a44b64d..ed4c538 100644 (file)
@@ -163,7 +163,7 @@ namespace Internal.Cryptography.Pal
             //
             // For compat with desktop, ignoring any failures from this call. (It is pretty unlikely to fail, in any case.)
             //
-            _ = Interop.crypt32.CertControlStore(certStore, CertControlStoreFlags.None, CertControlStoreType.CERT_STORE_CTRL_AUTO_RESYNC, IntPtr.Zero);
+            _ = Interop.Crypt32.CertControlStore(certStore, Interop.Crypt32.CertControlStoreFlags.None, Interop.Crypt32.CertControlStoreType.CERT_STORE_CTRL_AUTO_RESYNC, IntPtr.Zero);
 
             return new StorePal(certStore);
         }
index 4a51e20..47bbfe4 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using Internal.Cryptography.Pal.Native;
 using Microsoft.Win32.SafeHandles;
 using System;
 using System.Diagnostics;
@@ -58,11 +57,11 @@ namespace Internal.Cryptography.Pal
                 SafeCertContextHandle existingCertContext = ((CertificatePal)certificate).CertContext;
                 SafeCertContextHandle? enumCertContext = null;
                 Interop.Crypt32.CERT_CONTEXT* pCertContext = existingCertContext.CertContext;
-                if (!Interop.crypt32.CertFindCertificateInStore(_certStore, CertFindType.CERT_FIND_EXISTING, pCertContext, ref enumCertContext))
+                if (!Interop.crypt32.CertFindCertificateInStore(_certStore, Interop.Crypt32.CertFindType.CERT_FIND_EXISTING, pCertContext, ref enumCertContext))
                     return; // The certificate is not present in the store, simply return.
 
                 Interop.Crypt32.CERT_CONTEXT* pCertContextToDelete = enumCertContext.Disconnect();  // CertDeleteCertificateFromContext always frees the context (even on error)
-                if (!Interop.crypt32.CertDeleteCertificateFromStore(pCertContextToDelete))
+                if (!Interop.Crypt32.CertDeleteCertificateFromStore(pCertContextToDelete))
                     throw Marshal.GetLastWin32Error().ToCryptographicException();
 
                 GC.KeepAlive(existingCertContext);
index 763f127..677fb54 100644 (file)
@@ -224,7 +224,7 @@ namespace Internal.Cryptography.Pal
 
                             int cb = 20;
                             byte[] buffer = new byte[cb];
-                            if (!Interop.crypt32.CryptHashPublicKeyInfo(IntPtr.Zero, AlgId.CALG_SHA1, 0, Interop.Crypt32.CertEncodingType.All, ref publicKeyInfo, buffer, ref cb))
+                            if (!Interop.Crypt32.CryptHashPublicKeyInfo(IntPtr.Zero, AlgId.CALG_SHA1, 0, Interop.Crypt32.CertEncodingType.All, ref publicKeyInfo, buffer, ref cb))
                                 throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
                             if (cb < buffer.Length)
                             {
index 6751c91..8355f68 100644 (file)
@@ -134,7 +134,7 @@ namespace Internal.Cryptography.Pal
                 {
                     unsafe
                     {
-                        bool success = Interop.crypt32.CryptImportPublicKeyInfoEx2(Interop.Crypt32.CertEncodingType.X509_ASN_ENCODING, &(certContext.CertContext->pCertInfo->SubjectPublicKeyInfo), importFlags, null, out bCryptKeyHandle);
+                        bool success = Interop.Crypt32.CryptImportPublicKeyInfoEx2(Interop.Crypt32.CertEncodingType.X509_ASN_ENCODING, &(certContext.CertContext->pCertInfo->SubjectPublicKeyInfo), importFlags, null, out bCryptKeyHandle);
                         if (!success)
                             throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
                         return bCryptKeyHandle;
index 3783b0c..3ea6525 100644 (file)
     <Compile Include="Internal\Cryptography\IStorePal.cs" />
     <Compile Include="Internal\Cryptography\IX509Pal.cs" />
     <Compile Include="Microsoft\Win32\SafeHandles\SafePasswordHandle.cs" />
-    <Compile Include="Microsoft\Win32\SafeHandles\SafeX509ChainHandle.cs" />
+    <Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeX509ChainHandle.cs"
+             Link="Common\Microsoft\Win32\SafeHandles\SafeX509ChainHandle.cs" />
     <Compile Include="System\Security\Cryptography\X509Certificates\CertificateRequest.cs" />
     <Compile Include="System\Security\Cryptography\X509Certificates\DSACertificateExtensions.cs" />
     <Compile Include="System\Security\Cryptography\X509Certificates\ECDsaCertificateExtensions.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\ChainPal.GetChainStatusInformation.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\FindPal.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\Native\Helpers.cs" />
-    <Compile Include="Internal\Cryptography\Pal.Windows\Native\Interop.cryptoapi.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\Native\Interop.crypt32.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\Native\Primitives.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\Native\SafeHandles.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\X509Pal.GetCertContentType.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\X509Pal.PublicKey.cs" />
     <Compile Include="Internal\Cryptography\Pal.Windows\X509Pal.X500DistinguishedName.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.CryptAcquireContext_IntPtr.cs"
+             Link="Common\Interop\Windows\Advapi32\Interop.CryptAcquireContext_IntPtr.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.certificates.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.certificates.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.certificates_types.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.certificates_types.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertAddCertificateContextToStore.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertAddCertificateContextToStore.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertAddCertificateLinkToStore_CertStoreAddDisposition.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertAddCertificateLinkToStore_CertStoreAddDisposition.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertChainFlags.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertChainFlags.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertCloseStore.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertCloseStore.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertControlStore.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertControlStore.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertControlStoreFlags.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertControlStoreFlags.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertControlStoreType.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertControlStoreType.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertDeleteCertificateFromStore.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertDeleteCertificateFromStore.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertFindCertificateInStore.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertFindCertificateInStore.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertFreeCertificateChain.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertFreeCertificateChain.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertGetValidUsages.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertGetValidUsages.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertNameToStr.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertNameToStr.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.ChainEngine.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.ChainEngine.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptAcquireCertificatePrivateKey_SafeNCryptKeyHandle.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptAcquireCertificatePrivateKey_SafeNCryptKeyHandle.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptAcquireCertificatePrivateKeyFlags.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptAcquireCertificatePrivateKeyFlags.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptImportPublicKeyInfoEx2.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptImportPublicKeyInfoEx2.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptKeySpec.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptKeySpec.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptMsgClose.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CryptMsgClose.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CERT_CHAIN_ENGINE_CONFIG.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CERT_CHAIN_ENGINE_CONFIG.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CERT_CONTEXT.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CERT_CONTEXT.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CERT_EXTENSION.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CERT_PUBLIC_KEY_INFO.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertContextPropId.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertContextPropId.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertCreateCertificateChainEngine.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertCreateCertificateChainEngine.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertDuplicateCertificateChain.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertDuplicateCertificateChain.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertDuplicateCertificateContext.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertEncodingType.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertEnumCertificatesInStore_SafeCertStoreHandle.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertEnumCertificatesInStore_SafeCertStoreHandle.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertFindExtension.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertFindExtension.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertFindFlags.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertFindFlags.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertFindType.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertFindType.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertGetCertificateChain.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertGetCertificateChain.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertGetIntendedKeyUsage.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertGetIntendedKeyUsage.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertFreeCertificateChainEngine.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertFreeCertificateChainEngine.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertGetCertificateContextProperty.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertGetCertificateContextProperty.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertGetCertificateContextPropertyString.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertStoreFlags.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertQueryObjectType.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertQueryObjectType.cs" />
-    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertFreeCertificateContext.cs"
-             Link="Common\Interop\Windows\Crypt32\Interop.CertFreeCertificateContext.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertSaveStore.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertSaveStore.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertSerializeCertificateStoreElement.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertSerializeCertificateStoreElement.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertStoreSaveAs.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertStoreSaveAs.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertStoreSaveTo.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertStoreSaveTo.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertStrToName.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CertStrToName.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CertVerifyTimeValidity.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CertVerifyTimeValidity.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.ChainEngineConfigFlags.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.ChainEngineConfigFlags.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptAcquireContextFlags.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CryptAcquireContextFlags.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptDecodeObjectFlags.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CryptDecodeObjectFlags.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptDecodeObjectPointer_IntPtr.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptDecodeObjectPointer_IntPtr.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptDecodeObjectPointer_string.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptDecodeObjectPointer_string.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptDecodeObject_CertEncodingType.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CryptDecodeObject_CertEncodingType.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptEncodeObject_CertEncodingType.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CryptEncodeObject_CertEncodingType.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptFormatObject.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CryptFormatObject.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptHashPublicKeyInfo.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptHashPublicKeyInfo.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptImportPublicKeyInfoFlags.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.CryptImportPublicKeyInfoFlags.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptMsgGetParam.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.CryptMsgGetParam.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.CryptMsgParamType.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.PFXExportCertStore.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.PFXImportCertStore.cs"
              Link="Common\Interop\Windows\Crypt32\Interop.PFXImportCertStore.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Crypt32\Interop.X509KeyUsageFlags.cs"
+             Link="Common\Interop\Windows\Crypt32\Interop.X509KeyUsageFlags.cs" />
     <Compile Include="$(CommonPath)Internal\Cryptography\Windows\CryptoThrowHelper.cs"
              Link="Common\Internal\Cryptography\Windows\CryptoThrowHelper.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.FormatMessage.cs"
              Link="Common\Microsoft\Win32\SafeHandles\SafeCertContextHandleWithKeyContainerDeletion.cs" />
     <Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeCertStoreHandle.cs"
              Link="Common\Microsoft\Win32\SafeHandles\SafeCertStoreHandle.cs" />
+    <Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeChainEngineHandle.cs"
+             Link="Common\Microsoft\Win32\SafeHandles\SafeChainEngineHandle.cs" />
     <Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeCrypt32Handle.cs"
              Link="Common\Microsoft\Win32\SafeHandles\SafeCrypt32Handle.cs" />
     <Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeCryptMsgHandle.cs"