Skip to content

Commit 4f0f12c

Browse files
sam-githubBethGriggs
authored andcommittedOct 18, 2019
crypto: fix rsa key gen with non-default exponent
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 90fb146 commit 4f0f12c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎src/node_crypto.cc

+2
Original file line numberDiff line numberDiff line change
@@ -4864,8 +4864,10 @@ class RSAKeyPairGenerationConfig : public KeyPairGenerationConfig {
48644864
BignumPointer bn(BN_new());
48654865
CHECK_NOT_NULL(bn.get());
48664866
CHECK(BN_set_word(bn.get(), exponent_));
4867+
// EVP_CTX acceps ownership of bn on success.
48674868
if (EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx.get(), bn.get()) <= 0)
48684869
return false;
4870+
bn.release();
48694871
}
48704872

48714873
return true;

‎test/parallel/test-crypto-keygen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function convertDERToPEM(label, der) {
8686
// To make the test faster, we will only test sync key generation once and
8787
// with a relatively small key.
8888
const ret = generateKeyPairSync('rsa', {
89-
publicExponent: 0x10001,
89+
publicExponent: 3,
9090
modulusLength: 512,
9191
publicKeyEncoding: {
9292
type: 'pkcs1',
@@ -144,7 +144,7 @@ function convertDERToPEM(label, der) {
144144

145145
// Now do the same with an encrypted private key.
146146
generateKeyPair('rsa', {
147-
publicExponent: 0x10001,
147+
publicExponent: 0x1001,
148148
modulusLength: 512,
149149
publicKeyEncoding: {
150150
type: 'pkcs1',

0 commit comments

Comments
 (0)
Please sign in to comment.