★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/27092Nouvelle recherche | Portail wanayoo
Skip to content
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 rsa key gen with non-default exponent #27092

Closed

Conversation

Copy link
Contributor

@sam-github sam-github commented Apr 4, 2019

EVP_PKEY_CTX_set_rsa_keygen_pubexp() accepts ownership of the exponent
on success, so do not free it.

Fixes: #27087

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

EVP_PKEY_CTX_set_rsa_keygen_pubexp() accepts ownership of the exponent
on success, so do not free it.

Fixes: nodejs#27087
@sam-github sam-github requested a review from tniessen Apr 4, 2019
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 4, 2019

@nodejs-github-bot nodejs-github-bot added c++ crypto labels Apr 4, 2019
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 4, 2019

Copy link
Member

@bnoordhuis bnoordhuis left a comment

LGTM. Good catch.

@@ -146,7 +146,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);

// Now do the same with an encrypted private key.
generateKeyPair('rsa', {
publicExponent: 0x10001,
Copy link
Contributor

@mscdex mscdex Apr 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this exponent in both tests (here and the change above) as an additional test parameter?

Copy link
Contributor Author

@sam-github sam-github Apr 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mscdex exponent 0x10001 is tested 4 times in test-crypto-keygen.js, I don't mind copy and pasting the tests with non-default exponents, but don't think it will increase coverage. Can you confirm you want me to do this? For your reference:

core/node (fix-non-default-exp-rsa-keygen $%) % grep publicExponent test/parallel/test-crypto-keygen.js
    publicExponent: 3,   // I changed this from 0x0001
    publicExponent: 0x10001,
    publicExponent: 0x1001,   // I changed this from 0x0001
    publicExponent: 0x10001,
    publicExponent: 0x10001,
    publicExponent: 0x10001,

Copy link
Contributor

@mscdex mscdex Apr 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, either way is fine then.

Copy link
Member

@tniessen tniessen left a comment

Doesn't release return the pointer? I am not sure, maybe it doesn't :)

@sam-github
Copy link
Contributor Author

@sam-github sam-github commented Apr 8, 2019

yes, release both returns the pointer, and nulls it (so the auto ptr doesn't own it). But its the only function to use (I think).

@sam-github
Copy link
Contributor Author

@sam-github sam-github commented Apr 8, 2019

Landed in 0911e88

@sam-github sam-github closed this Apr 8, 2019
@sam-github sam-github deleted the fix-non-default-exp-rsa-keygen branch Apr 8, 2019
sam-github added a commit that referenced this issue Apr 8, 2019
EVP_PKEY_CTX_set_rsa_keygen_pubexp() accepts ownership of the exponent
on success, so do not free it.

Fixes: #27087

PR-URL: #27092
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@mscdex
Copy link
Contributor

@mscdex mscdex commented Sep 4, 2019

FWIW this fixes a crash that currently exists on latest v10.x.

BethGriggs pushed a commit that referenced this issue Oct 18, 2019
EVP_PKEY_CTX_set_rsa_keygen_pubexp() accepts ownership of the exponent
on success, so do not free it.

Fixes: #27087
Fixes: #29433

PR-URL: #27092
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BethGriggs BethGriggs mentioned this pull request Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ crypto
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants