-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use EVP_PKEY for RSA signing operations #50257
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
Conversation
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsWith this change all RSA private key operations (excluding import/export) use the EVP_PKEY APIs.
Contributes to #46526.
|
int32_t destinationLen) | ||
{ | ||
assert(pkey != NULL); | ||
assert(hash != NULL); |
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.
I think I traced back to the public RSAOpenSsl.TrySignHash
entry point that hash can be nullptr, since ROS<byte>.IsEmpty
is never checked. Double-check me on this.
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.
Hmm. I agree, I don't see a size check. So either there's no test with the default span as input, or I'm missing something. I'll look more into this.
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.
Yeah, looks like we're missing a test here. The assert totally trips.
The good news is, with the test case, I see that simply removing the assert makes things behave as expected:
Interop+Crypto+OpenSslCryptographicException : error:0408E08F:rsa routines:pkey_rsa_sign:invalid digest length
Stack Trace:
/home/jbarton/git/bartonjs/runtime/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Rsa.cs(94,0): at Interop.Crypto.RsaSignHash(SafeEvpPKeyHandle pkey, RSASignaturePaddingMode paddingMode, IntPtr digestAlgorithm, ReadOnlySpan`1 hash, Span`1 destination)
/home/jbarton/git/bartonjs/runtime/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs(683,0): at System.Security.Cryptography.RSAImplementation.RSAOpenSsl.TrySignHash(ReadOnlySpan`1 hash, Span`1 destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, Boolean allocateSignature, Int32& bytesWritten, Byte[]& signature)
/home/jbarton/git/bartonjs/runtime/src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs(639,0): at System.Security.Cryptography.RSAImplementation.RSAOpenSsl.TrySignHash(ReadOnlySpan`1 hash, Span`1 destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, Int32& bytesWritten)
(That's the correct exception since (NULL, 0) is not a valid input for RSASSA-*-SHA256... which wants something of length 32.)
With this change all RSA private key operations (excluding import/export) use the EVP_PKEY APIs.
Contributes to #46526.