-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[macOS] Use data keys on macOS for RSA, EC cryptography #51976
Conversation
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsTest run for #51926 + reunification of the key import/export to use data keys on macOS. This should in theory be significantly faster but last CI run had one failing test and that needs to be investigated.
|
Hmm, just as expected it runs into the same trap as dotnet/corefx#27394. RSA PKCS #1 encryption/decryption on macOS 10.14 and older is broken for empty data (https://github.com/apple-opensource/Security/blob/e7e7d09ddf756349e64613a6890b0807ca06001f/OSX/sec/Security/SecRSAKey.c#L507). It's not a problem on recent iOS and macOS versions. It is a solvable problem by doing the de-padding on the managed side. |
cc75c55
to
a7aea91
Compare
src/libraries/Common/src/System/Security/Cryptography/RSASecurityTransforms.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/System/Security/Cryptography/RSASecurityTransforms.macOS.cs
Show resolved
Hide resolved
6a31b21
to
973f8a4
Compare
973f8a4
to
04d2618
Compare
using (PinAndClear.Track(rsaPrivateKey)) | ||
{ | ||
return Interop.AppleCrypto.ImportEphemeralKey(rsaPrivateKey, true); | ||
} |
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.
Side-note for reviewers: The GetPrivateKey
method is called from one place which disposes the returned SafeHandle. In case we return a new handle here it will dispose it and then dispose the original RSA key. In the case of DSA below we reuse the internal handle and it gets disposed twice which is harmless.
Resurrects the remaining work from #38101 (cc @vcsjones). Two code paths in S.S.C.X509Certificates are changed to explicitly import keys though the legacy CSSM keys because they are the only ones that reliably work with the macOS keychain APIs.
It also enables more of the RSA OAEP code paths through native code instead of using the managed
RsaPaddingProcesser
.