diff options
author | Tobias Nießen <tniessen@tnie.de> | 2018-12-23 15:13:32 +0100 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2019-03-30 10:31:43 +0100 |
commit | 2e2c015422dce973f15acb42571486e4003efddb (patch) | |
tree | 8e40aee5afd38fb10a5ebe64447256689b7e288b /test/parallel/test-crypto-key-objects.js | |
parent | 61ef9df958f98bed5159d9d4553ea5b2f894272f (diff) | |
download | android-node-v8-2e2c015422dce973f15acb42571486e4003efddb.tar.gz android-node-v8-2e2c015422dce973f15acb42571486e4003efddb.tar.bz2 android-node-v8-2e2c015422dce973f15acb42571486e4003efddb.zip |
crypto: decode missing passphrase errors
When a user attempts to load an encrypted key without supplying a
passphrase, a cryptic OpenSSL error is thrown. This change intercepts
the OpenSSL error and throws a nice error code instead.
PR-URL: https://github.com/nodejs/node/pull/25208
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'test/parallel/test-crypto-key-objects.js')
-rw-r--r-- | test/parallel/test-crypto-key-objects.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index c9cb90d408..e8f6cc3c96 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -21,6 +21,10 @@ const fixtures = require('../common/fixtures'); const publicPem = fixtures.readSync('test_rsa_pubkey.pem', 'ascii'); const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii'); +const publicDsa = fixtures.readKey('dsa_public_1025.pem', 'ascii'); +const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', + 'ascii'); + { // Attempting to create an empty key should throw. common.expectsError(() => { @@ -210,3 +214,26 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii'); }); } }); + +{ + // Reading an encrypted key without a passphrase should fail. + common.expectsError(() => createPrivateKey(privateDsa), { + type: TypeError, + code: 'ERR_MISSING_PASSPHRASE', + message: 'Passphrase required for encrypted key' + }); + + const publicKey = createPublicKey(publicDsa); + assert.strictEqual(publicKey.type, 'public'); + assert.strictEqual(publicKey.asymmetricKeyType, 'dsa'); + assert.strictEqual(publicKey.symmetricKeySize, undefined); + + const privateKey = createPrivateKey({ + key: privateDsa, + format: 'pem', + passphrase: 'secret' + }); + assert.strictEqual(privateKey.type, 'private'); + assert.strictEqual(privateKey.asymmetricKeyType, 'dsa'); + assert.strictEqual(privateKey.symmetricKeySize, undefined); +} |