-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make S.S.C.X509Certificates compliant with interop guidelines - part 3
- Loading branch information
1 parent
0e9ce96
commit c334e55
Showing
49 changed files
with
738 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CERT_CHAIN_ENGINE_CONFIG.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertChainFlags.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreFlags.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertControlStoreType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertCreateCertificateChainEngine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertDeleteCertificateFromStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindCertificateInStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindFlags.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFindType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChain.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertFreeCertificateChainEngine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetCertificateChain.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetIntendedKeyUsage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertGetValidUsages.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertSaveStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveAs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CertStoreSaveTo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
Oops, something went wrong.