diff options
author | Tobias Nießen <tniessen@tnie.de> | 2019-03-30 00:19:39 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-04 16:09:11 +0200 |
commit | 73bca57988c847a4b17b923686eee8e04e4fa13c (patch) | |
tree | 826a7cf8cce84fe8e974f68314f81bb109468425 /test/parallel/test-crypto-key-objects.js | |
parent | 608878c95692e12a42d97f2b7cfd839453bc815d (diff) | |
download | android-node-v8-73bca57988c847a4b17b923686eee8e04e4fa13c.tar.gz android-node-v8-73bca57988c847a4b17b923686eee8e04e4fa13c.tar.bz2 android-node-v8-73bca57988c847a4b17b923686eee8e04e4fa13c.zip |
crypto: fail early if passphrase is too long
This causes OpenSSL to fail early if the decryption passphrase is too
long, and produces a somewhat helpful error message.
PR-URL: https://github.com/nodejs/node/pull/27010
Refs: https://github.com/nodejs/node/pull/25208
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
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 | 21 |
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 fb35b9ae92..8d4767f617 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -230,6 +230,27 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', message: 'Passphrase required for encrypted key' }); + // Reading an encrypted key with a passphrase that exceeds OpenSSL's buffer + // size limit should fail with an appropriate error code. + common.expectsError(() => createPrivateKey({ + key: privateDsa, + format: 'pem', + passphrase: Buffer.alloc(1025, 'a') + }), { + code: 'ERR_OSSL_PEM_BAD_PASSWORD_READ', + type: Error + }); + + // The buffer has a size of 1024 bytes, so this passphrase should be permitted + // (but will fail decryption). + common.expectsError(() => createPrivateKey({ + key: privateDsa, + format: 'pem', + passphrase: Buffer.alloc(1024, 'a') + }), { + message: /bad decrypt/ + }); + const publicKey = createPublicKey(publicDsa); assert.strictEqual(publicKey.type, 'public'); assert.strictEqual(publicKey.asymmetricKeyType, 'dsa'); |