summaryrefslogtreecommitdiff
path: root/test/parallel/test-crypto-keygen.js
diff options
context:
space:
mode:
authoroksana <ok.semonenko@gmail.com>2019-05-26 16:37:10 +0300
committerRich Trott <rtrott@gmail.com>2019-05-30 09:23:52 +0200
commit76cffddf82603a6060840d5c20064b7aa0a5e9dd (patch)
tree7157b658f3ccafbf7219534b002b342ae5f41638 /test/parallel/test-crypto-keygen.js
parent24950985df4e55293efecd393d09d18abd94ed05 (diff)
downloadandroid-node-v8-76cffddf82603a6060840d5c20064b7aa0a5e9dd.tar.gz
android-node-v8-76cffddf82603a6060840d5c20064b7aa0a5e9dd.tar.bz2
android-node-v8-76cffddf82603a6060840d5c20064b7aa0a5e9dd.zip
test: add test cases for paramEncoding 'explicit'
PR-URL: https://github.com/nodejs/node/pull/27900 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-crypto-keygen.js')
-rw-r--r--test/parallel/test-crypto-keygen.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js
index d2614e0c76..19afd715e4 100644
--- a/test/parallel/test-crypto-keygen.js
+++ b/test/parallel/test-crypto-keygen.js
@@ -378,6 +378,30 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
testSignVerify(publicKey, privateKey);
}));
+ // Test async elliptic curve key generation, e.g. for ECDSA, with a SEC1
+ // private key with paramEncoding explicit.
+ generateKeyPair('ec', {
+ namedCurve: 'prime256v1',
+ paramEncoding: 'explicit',
+ publicKeyEncoding: {
+ type: 'spki',
+ format: 'pem'
+ },
+ privateKeyEncoding: {
+ type: 'sec1',
+ format: 'pem'
+ }
+ }, common.mustCall((err, publicKey, privateKey) => {
+ assert.ifError(err);
+
+ assert.strictEqual(typeof publicKey, 'string');
+ assert(spkiExp.test(publicKey));
+ assert.strictEqual(typeof privateKey, 'string');
+ assert(sec1Exp.test(privateKey));
+
+ testSignVerify(publicKey, privateKey);
+ }));
+
// Do the same with an encrypted private key.
generateKeyPair('ec', {
namedCurve: 'prime256v1',
@@ -409,6 +433,38 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
testSignVerify(publicKey, { key: privateKey, passphrase: 'secret' });
}));
+
+ // Do the same with an encrypted private key with paramEncoding explicit.
+ generateKeyPair('ec', {
+ namedCurve: 'prime256v1',
+ paramEncoding: 'explicit',
+ publicKeyEncoding: {
+ type: 'spki',
+ format: 'pem'
+ },
+ privateKeyEncoding: {
+ type: 'sec1',
+ format: 'pem',
+ cipher: 'aes-128-cbc',
+ passphrase: 'secret'
+ }
+ }, common.mustCall((err, publicKey, privateKey) => {
+ assert.ifError(err);
+
+ assert.strictEqual(typeof publicKey, 'string');
+ assert(spkiExp.test(publicKey));
+ assert.strictEqual(typeof privateKey, 'string');
+ assert(sec1EncExp('AES-128-CBC').test(privateKey));
+
+ // Since the private key is encrypted, signing shouldn't work anymore.
+ common.expectsError(() => testSignVerify(publicKey, privateKey), {
+ type: TypeError,
+ code: 'ERR_MISSING_PASSPHRASE',
+ message: 'Passphrase required for encrypted key'
+ });
+
+ testSignVerify(publicKey, { key: privateKey, passphrase: 'secret' });
+ }));
}
{
@@ -447,6 +503,42 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
passphrase: 'top secret'
});
}));
+
+ // Test async elliptic curve key generation, e.g. for ECDSA, with an encrypted
+ // private key with paramEncoding explicit.
+ generateKeyPair('ec', {
+ namedCurve: 'P-256',
+ paramEncoding: 'explicit',
+ publicKeyEncoding: {
+ type: 'spki',
+ format: 'pem'
+ },
+ privateKeyEncoding: {
+ type: 'pkcs8',
+ format: 'pem',
+ cipher: 'aes-128-cbc',
+ passphrase: 'top secret'
+ }
+ }, common.mustCall((err, publicKey, privateKey) => {
+ assert.ifError(err);
+
+ assert.strictEqual(typeof publicKey, 'string');
+ assert(spkiExp.test(publicKey));
+ assert.strictEqual(typeof privateKey, 'string');
+ assert(pkcs8EncExp.test(privateKey));
+
+ // Since the private key is encrypted, signing shouldn't work anymore.
+ common.expectsError(() => testSignVerify(publicKey, privateKey), {
+ type: TypeError,
+ code: 'ERR_MISSING_PASSPHRASE',
+ message: 'Passphrase required for encrypted key'
+ });
+
+ testSignVerify(publicKey, {
+ key: privateKey,
+ passphrase: 'top secret'
+ });
+ }));
}
// Test invalid parameter encoding.