-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make System.Security.Cryptography.X509Certificates compliant with interop guidelines - part 3 #61435
Conversation
…erop guidelines - part 3
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsFixes #51564 This PR makes the following calls compliant with Interop gudielines :
There's 5 Interop calls inside System.Security.Cryptography.X509Certificates.Tests project, should I move them also or it is OK for DllImport to be in test libraries?
|
{ | ||
[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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static unsafe partial bool CryptAcquireContext(out IntPtr psafeProvHandle, | |
internal static unsafe partial bool CryptAcquireContext( | |
out IntPtr psafeProvHandle, |
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, SetLastError = true)] | ||
internal static unsafe partial bool CertGetCertificateChain(IntPtr hChainEngine, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd put all of the contents of CERT_CHAIN_PARA.cs into this file, since there's no need for it with any other function.
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, SetLastError = true)] | ||
internal static unsafe partial bool CertGetCertificateChain(IntPtr hChainEngine, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static unsafe partial bool CertGetCertificateChain(IntPtr hChainEngine, | |
internal static unsafe partial bool CertGetCertificateChain( | |
IntPtr hChainEngine, |
// 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static unsafe partial bool CertGetIntendedKeyUsage(CertEncodingType dwCertEncodingType, | |
internal static unsafe partial bool CertGetIntendedKeyUsage( | |
CertEncodingType dwCertEncodingType, |
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static unsafe partial SafeCertContextHandle CertFindCertificateInStore(SafeCertStoreHandle hCertStore, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static unsafe partial SafeCertContextHandle CertFindCertificateInStore(SafeCertStoreHandle hCertStore, | |
internal static unsafe partial SafeCertContextHandle CertFindCertificateInStore( | |
SafeCertStoreHandle hCertStore, |
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)] | ||
public static partial bool CryptAcquireCertificatePrivateKey(SafeCertContextHandle pCert, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static partial bool CryptAcquireCertificatePrivateKey(SafeCertContextHandle pCert, | |
public static partial bool CryptAcquireCertificatePrivateKey( | |
SafeCertContextHandle pCert, |
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, EntryPoint = "CryptDecodeObject", CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static unsafe partial bool CryptDecodeObjectPointer(CertEncodingType dwCertEncodingType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static unsafe partial bool CryptDecodeObjectPointer(CertEncodingType dwCertEncodingType, | |
internal static unsafe partial bool CryptDecodeObjectPointer( | |
CertEncodingType dwCertEncodingType, |
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, EntryPoint = "CryptDecodeObject", CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static unsafe partial bool CryptDecodeObjectPointer(CertEncodingType dwCertEncodingType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static unsafe partial bool CryptDecodeObjectPointer(CertEncodingType dwCertEncodingType, | |
internal static unsafe partial bool CryptDecodeObjectPointer( | |
CertEncodingType dwCertEncodingType, |
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static partial bool CryptHashPublicKeyInfo(IntPtr hCryptProv, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static partial bool CryptHashPublicKeyInfo(IntPtr hCryptProv, | |
internal static partial bool CryptHashPublicKeyInfo( | |
IntPtr hCryptProv, |
internal static partial class Crypt32 | ||
{ | ||
[GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static unsafe partial bool CryptImportPublicKeyInfoEx2(CertEncodingType dwCertEncodingType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal static unsafe partial bool CryptImportPublicKeyInfoEx2(CertEncodingType dwCertEncodingType, | |
internal static unsafe partial bool CryptImportPublicKeyInfoEx2( | |
CertEncodingType dwCertEncodingType, |
Search-fu is failing me today. What are they? |
runtime/src/libraries/System.Security.Cryptography.X509Certificates/tests/HostnameMatchTests.Unix.cs Lines 192 to 193 in 57bfe47
runtime/src/libraries/System.Security.Cryptography.X509Certificates/tests/InteropTests.cs Lines 115 to 131 in 57bfe47
runtime/src/libraries/System.Security.Cryptography.X509Certificates/tests/X509StoreTests.cs Lines 579 to 582 in 57bfe47
|
Hm. I'm guessing that the tests had their own P/Invokes because they were originally compiled as AnyOS. Since they're split now (and the in-progress unified System.Security.Cryptography.Tests is already split) they should probably be fixed to use the existing interop-decls. (CheckX509Hostname being the hardest of the three, since the Interop decl uses a SafeHandle instead of IntPtr and is in a grab-bag file... so for that one it's probably just making a dedicated Interop.CheckX509Hostname for the IntPtr version and leaving the SafeHandle version where it is). -- But that should be a followup PR, no need to reset this one 😄 |
Thanks for doing this, @pedrobsaila! شكرا & merci |
Fixes partially #51564
The issue is still under progress, more PRs are to come. The current one makes the following calls compliant with Interop guidelines :
There are 5 DllImport methods inside System.Security.Cryptography.X509Certificates.Tests project, should I move them also ?