Use a custom PFX reader/writer on Unix OSes - #42226
Conversation
Have some todos, and Windows won't compile...
|
Thank you for your contribution. As announced in dotnet/coreclr#27549 this repository will be moving to dotnet/runtime on November 13. If you would like to continue working on this PR after this date, the easiest way to move the change to dotnet/runtime is:
|
|
All of the Nano 1903 test failures are that it took the private static readonly bool s_loaderFailsKeysEarly =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
!PlatformDetection.IsWindows10Version1903OrGreater;The build number used for detecting 1903 matches what I see in docs (18362) and works for non-Nano. And PlatformDetection's IsWindowsNanoServer starts off with the IsOSPlatform(Windows) check. Weird. |
|
K, this time OneCert_EncryptedEmptyPassword_OneKey_EncryptedNullPassword_NoMac hit a one in a million (okay, less unlikely than that...) chance where the padding worked out so decryption "succeeded" but ASN parsing failed. Added a second acceptable failure code to that one... if there are more sneaky one in a millions then I'll call it "overtesting" instead of "test case generation validation" and remove testing for the Win32 codes at all. As for the Nano failures, apparently I can't read. It's 1809, not 1903. Since it has the "1903" behavior, but is 1809, my test was wrong... so I'm changing it to RS5/1809; and hopefully the full run doesn't say that Windows Client 1809 disagrees. (I forget where I came up with 1903 as the cutover, but I remember feeling like it was a guess when I did it) |
|
Yay, finally got all the edge cases on all the OSes at the same time! 🍾 |
| } | ||
|
|
||
| return certs; | ||
| return ((ECDiffieHellmanOpenSsl)key).DuplicateKeyHandle(); |
There was a problem hiding this comment.
Nit: for what it's worth, you can simplify these kinds of patterns with switch expressions:
internal static SafeEvpPKeyHandle GetPrivateKey(AsymmetricAlgorithm key) =>
key switch
{
RSAOpenSsl rsa => rsa.DuplicateKeyHandle(),
DSAOpenSsl dsa => dsa.DuplicateKeyHandle(),
_ => ((ECDiffieHellmanOpenSsl)key).DuplicateKeyHandle()
};|
I can't tell if either @krwq or @stephentoub have made it to the end of the PR while reviewing, so I'm still waiting on a checkmark. I'd like to control the squash message, so please don't hit squash and merge as signoff. |
|
Yay @bartonjs, that was a big change. |
|
Yes, I've made it, new iterations LGTM as well |
This change moves PFX import and export primarily into managed code to work around inconsistencies across the operating systems.
Current issues:
This change moves the necessary ASN types from the Pkcs12 library into Common so they're shared between Pkcs12Info/Pkcs12Builder and X509Certificates, then uses a managed loader and managed writer.
Quirks:
As part of this change the X509Certificates SafePasswordHandle is now always UTF-16, because that's the encoding required for the PKCS12 KDF, so some platform-split code got to go away. Some helper routines for CFString were added to make the transition back to macOS P/Invokes easier from the SafePasswordHandle.
Fixes #40539.
Fixes #2743.
Fixes #2745.
Fixes #2746.
Fixes #11046.
Fixes #16705.
Fixes #24225.
Fixes #24226.
Fixes #26397.
Fixes #30946.
Fixes #31746.
Fixes #37599.
(And maybe others)