diff options
author | Nitzan Uziely <linkgoron@gmail.com> | 2021-04-23 00:28:39 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-04-26 11:55:45 -0700 |
commit | 09c97b813890f6f1465ebd149831bed07682d496 (patch) | |
tree | ff5f4bee1298c0e9cfb08094bbe6a252dbf32b40 /test/parallel/test-crypto-keygen.js | |
parent | 3b86138f0062cc96c1f53f5d7cf820d4e345f351 (diff) | |
download | node-new-09c97b813890f6f1465ebd149831bed07682d496.tar.gz |
crypto: fix generateKeyPair type checks
Change saltLength, divisorLength, primeLength and generator
checks in generateKeyPair to int32 from uint32, to align
with c++ code.
fixes: https://github.com/nodejs/node/issues/38358
PR-URL: https://github.com/nodejs/node/pull/38364
Fixes: https://github.com/nodejs/node/issues/38358
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-crypto-keygen.js')
-rw-r--r-- | test/parallel/test-crypto-keygen.js | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index cbf797c0ea..a120a3838e 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -958,7 +958,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } // Test invalid divisor lengths. - for (const divisorLength of ['a', true, {}, [], 4096.1]) { + for (const divisorLength of ['a', true, {}, [], 4096.1, 2147483648, -1]) { assert.throws(() => generateKeyPair('dsa', { modulusLength: 2048, divisorLength @@ -1081,6 +1081,52 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); message: 'Unknown DH group' }); + assert.throws(() => { + generateKeyPair('dh', { + primeLength: 2147483648 + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.primeLength' is invalid. " + + 'Received 2147483648', + }); + + assert.throws(() => { + generateKeyPair('dh', { + primeLength: -1 + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.primeLength' is invalid. " + + 'Received -1', + }); + + assert.throws(() => { + generateKeyPair('dh', { + primeLength: 2, + generator: 2147483648, + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.generator' is invalid. " + + 'Received 2147483648', + }); + + assert.throws(() => { + generateKeyPair('dh', { + primeLength: 2, + generator: -1, + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.generator' is invalid. " + + 'Received -1', + }); + // Test incompatible options. const allOpts = { group: 'modp5', @@ -1142,6 +1188,35 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); }); } + // too long salt length + assert.throws(() => { + generateKeyPair('rsa-pss', { + modulusLength: 512, + saltLength: 2147483648, + hash: 'sha256', + mgf1Hash: 'sha256' + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.saltLength' is invalid. " + + 'Received 2147483648' + }); + + assert.throws(() => { + generateKeyPair('rsa-pss', { + modulusLength: 512, + saltLength: -1, + hash: 'sha256', + mgf1Hash: 'sha256' + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.saltLength' is invalid. " + + 'Received -1' + }); + // Invalid private key type. for (const type of ['foo', 'spki']) { assert.throws(() => { |