summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2019-10-10 02:41:30 +0200
committerRich Trott <rtrott@gmail.com>2019-10-11 22:02:55 -0700
commitc64ed10d8067fc3b21578d3eafe322d0e9496980 (patch)
treed391c01fbb94d9c30fcf16468236344e3f157581 /test
parent88e815649bbc9529e23bef22dda17570bd972683 (diff)
downloadandroid-node-v8-c64ed10d8067fc3b21578d3eafe322d0e9496980.tar.gz
android-node-v8-c64ed10d8067fc3b21578d3eafe322d0e9496980.tar.bz2
android-node-v8-c64ed10d8067fc3b21578d3eafe322d0e9496980.zip
crypto: reject public keys properly
Fixes: https://github.com/nodejs/node/issues/29904 PR-URL: https://github.com/nodejs/node/pull/29913 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-crypto-key-objects.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js
index 558f7dc1f4..15de241b35 100644
--- a/test/parallel/test-crypto-key-objects.js
+++ b/test/parallel/test-crypto-key-objects.js
@@ -200,6 +200,27 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
library: 'BIO routines',
function: 'BIO_new_mem_buf',
});
+
+ // This should not abort either: https://github.com/nodejs/node/issues/29904
+ assert.throws(() => {
+ createPrivateKey({ key: Buffer.alloc(0), format: 'der', type: 'spki' });
+ }, {
+ code: 'ERR_INVALID_OPT_VALUE',
+ message: 'The value "spki" is invalid for option "type"'
+ });
+
+ // Unlike SPKI, PKCS#1 is a valid encoding for private keys (and public keys),
+ // so it should be accepted by createPrivateKey, but OpenSSL won't parse it.
+ assert.throws(() => {
+ const key = createPublicKey(publicPem).export({
+ format: 'der',
+ type: 'pkcs1'
+ });
+ createPrivateKey({ key, format: 'der', type: 'pkcs1' });
+ }, {
+ message: /asn1 encoding/,
+ library: 'asn1 encoding routines'
+ });
}
[