-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Use EVP_PKEY for RSA Decrypt #50063
Use EVP_PKEY for RSA Decrypt #50063
Conversation
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue Details
Contributes to #46526
|
src/libraries/Native/Unix/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c
Show resolved
Hide resolved
OK, I'm officially confused.
|
@bartonjs Hmm. Let me give it a shot. |
size_t written; | ||
|
||
if (EVP_PKEY_decrypt(ctx, destination, &written, source, Int32ToSizeT(sourceLen)) > 0) |
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.
@bartonjs written
needs to be initialized to the length of destination
here. From OpenSSL docs:
If out is not NULL then before the call the outlen parameter should contain the length of the out buffer, if the call is successful the decrypted data is written to out and the amount of data written to outlen.
So written
is an in/out, not just an out and might be garbage, which makes sense why all of the failures were in checked / release builds. OpenSSL then checks the that the outlen
input is long enough to write to.
The validation call is here:
And if arglen
(written in your case) is too small after checking it against the key size, it throws.
If you initialize written
to zero first, the error will happen consistently, just to demonstrate that the value prior to calling EVP_PKEY_decrypt
matters.
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 opened a PR into your PR for this here. bartonjs#1
If the PR into a PR is too weird or doesn't work you can grab a patch here and apply it directly to your branch https://github.com/bartonjs/runtime/pull/1.patch (assuming the changes are useful 😄 )
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.
Oy, what an embarrassing RTFM moment. Thanks for the detective work.
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 opened a PR into your PR for this here
Huh, the tab had gotten your first message, but not the second. I didn't ignore your PRPR, just happened to have made a pretty-darn-close-to-identical version before seeing that it existed (when catching up on email notifications).
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.
No worries. I'm glad we pretty much came to the same change set. 😀
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.
Yay, that seemed to do it.
src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs
Outdated
Show resolved
Hide resolved
The new failures aren't caused by the latest commit, going ahead and merging. |
EVP_DIGEST*
/IntPtr cache from HashProviderDispenser to an Interop file so it can be shared across S.S.C.Algorithms and S.S.C.OpenSsl.Contributes to #46526