-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
crypto: fix Node_SignFinal #15024
crypto: fix Node_SignFinal #15024
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3976,7 +3976,8 @@ void SignBase::CheckThrow(SignBase::Error error) { | |
|
||
static bool ApplyRSAOptions(EVP_PKEY* pkey, EVP_PKEY_CTX* pkctx, int padding, | ||
int salt_len) { | ||
if (pkey->type == EVP_PKEY_RSA || pkey->type == EVP_PKEY_RSA2) { | ||
if (EVP_PKEY_id(pkey) == EVP_PKEY_RSA || | ||
EVP_PKEY_id(pkey) == EVP_PKEY_RSA2) { | ||
if (EVP_PKEY_CTX_set_rsa_padding(pkctx, padding) <= 0) | ||
return false; | ||
if (padding == RSA_PKCS1_PSS_PADDING) { | ||
|
@@ -4085,33 +4086,23 @@ static int Node_SignFinal(EVP_MD_CTX* mdctx, unsigned char* md, | |
if (!EVP_DigestFinal_ex(mdctx, m, &m_len)) | ||
return rv; | ||
|
||
if (mdctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { | ||
size_t sltmp = static_cast<size_t>(EVP_PKEY_size(pkey)); | ||
pkctx = EVP_PKEY_CTX_new(pkey, nullptr); | ||
if (pkctx == nullptr) | ||
goto err; | ||
if (EVP_PKEY_sign_init(pkctx) <= 0) | ||
goto err; | ||
if (!ApplyRSAOptions(pkey, pkctx, padding, pss_salt_len)) | ||
goto err; | ||
if (EVP_PKEY_CTX_set_signature_md(pkctx, mdctx->digest) <= 0) | ||
goto err; | ||
if (EVP_PKEY_sign(pkctx, md, &sltmp, m, m_len) <= 0) | ||
goto err; | ||
*sig_len = sltmp; | ||
rv = 1; | ||
err: | ||
EVP_PKEY_CTX_free(pkctx); | ||
return rv; | ||
} | ||
|
||
if (mdctx->digest->sign == nullptr) { | ||
EVPerr(EVP_F_EVP_SIGNFINAL, EVP_R_NO_SIGN_FUNCTION_CONFIGURED); | ||
return 0; | ||
} | ||
|
||
return mdctx->digest->sign(mdctx->digest->type, m, m_len, md, sig_len, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same fix as in openssl-1.1.0 and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Node is already assuming this codepath isn't needed in the verify half. This codepath is because, in 0.9.8, an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your explanation about its history. I thought it might be safe for we do not have NoneWithRSA but I did not have the confidence to remove that code path. . |
||
pkey->pkey.ptr); | ||
size_t sltmp = static_cast<size_t>(EVP_PKEY_size(pkey)); | ||
pkctx = EVP_PKEY_CTX_new(pkey, nullptr); | ||
if (pkctx == nullptr) | ||
goto err; | ||
if (EVP_PKEY_sign_init(pkctx) <= 0) | ||
goto err; | ||
if (!ApplyRSAOptions(pkey, pkctx, padding, pss_salt_len)) | ||
goto err; | ||
if (EVP_PKEY_CTX_set_signature_md(pkctx, EVP_MD_CTX_md(mdctx)) <= 0) | ||
goto err; | ||
if (EVP_PKEY_sign(pkctx, md, &sltmp, m, m_len) <= 0) | ||
goto err; | ||
*sig_len = sltmp; | ||
rv = 1; | ||
err: | ||
EVP_PKEY_CTX_free(pkctx); | ||
return rv; | ||
} | ||
|
||
SignBase::Error Sign::SignFinal(const char* key_pem, | ||
|
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.
It is better to add a description about a signature algorithm in the comment of examples like
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.
Wrote something to that effect.
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.
It looks good to me.