diff options
author | Jose M. Palacios Diaz <jmpd1988@gmail.com> | 2017-11-06 17:22:42 -0500 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-12-01 21:18:11 +0100 |
commit | 845633a7c62ad9ffd33880a43e05a49382bb76bb (patch) | |
tree | aaa2e2e15a13b207e8db74f1011e00870c16cb22 /test/parallel/test-crypto-dh.js | |
parent | 31e0dbc0c700e7bb8fa453258ba0233975ece575 (diff) | |
download | android-node-v8-845633a7c62ad9ffd33880a43e05a49382bb76bb.tar.gz android-node-v8-845633a7c62ad9ffd33880a43e05a49382bb76bb.tar.bz2 android-node-v8-845633a7c62ad9ffd33880a43e05a49382bb76bb.zip |
crypto: better docs for cases where peer's public key is invalid
changes in c++ are in the computeSecret function, but the thrown
exception that was moved to JS land was in BufferToPoint
function, here i let the allocation error be thrown so the only value
returned is the nullptr that i use later to catch the error in
computeSecret, to then construct the exception in JS land.
an ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY error was added to errors.js
and with that, subsequent changes to docs and tests were made.
PR-URL: https://github.com/nodejs/node/pull/16849
Refs: https://www.iacr.org/archive/pkc2003/25670211/25670211.pdf
Fixes: https://github.com/nodejs/node/issues/16625
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/parallel/test-crypto-dh.js')
-rw-r--r-- | test/parallel/test-crypto-dh.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index c162d660bd..d55540dd88 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -222,9 +222,13 @@ if (availableCurves.has('prime256v1') && availableCurves.has('secp256k1')) { const ecdh3 = crypto.createECDH('secp256k1'); const key3 = ecdh3.generateKeys(); - assert.throws(() => { - ecdh2.computeSecret(key3, 'latin1', 'buffer'); - }, /^Error: Failed to translate Buffer to a EC_POINT$/); + common.expectsError( + () => ecdh2.computeSecret(key3, 'latin1', 'buffer'), + { + code: 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY', + type: Error, + message: 'Public key is not valid for specified curve' + }); // ECDH should allow .setPrivateKey()/.setPublicKey() const ecdh4 = crypto.createECDH('prime256v1'); @@ -331,9 +335,13 @@ if (availableCurves.has('prime256v1') && availableHashes.has('sha256')) { const invalidKey = Buffer.alloc(65); invalidKey.fill('\0'); curve.generateKeys(); - assert.throws(() => { - curve.computeSecret(invalidKey); - }, /^Error: Failed to translate Buffer to a EC_POINT$/); + common.expectsError( + () => curve.computeSecret(invalidKey), + { + code: 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY', + type: Error, + message: 'Public key is not valid for specified curve' + }); // Check that signing operations are not impacted by the above error. const ecPrivateKey = '-----BEGIN EC PRIVATE KEY-----\n' + |