0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-crypto-keygen-async-named-elliptic-curve-encrypted.js
Joyee Cheung 7224940e54 test: split test-crypto-keygen.js
To avoid timing out on ARM machines in the CI.

PR-URL: https://github.com/nodejs/node/pull/49221
Refs: https://github.com/nodejs/node/issues/49202
Refs: https://github.com/nodejs/node/issues/41206
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-08-31 08:50:28 +00:00

53 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
const {
testSignVerify,
spkiExp,
sec1EncExp,
} = require('../common/crypto');
{
// Test async named elliptic curve key generation with an encrypted
// private key.
generateKeyPair('ec', {
namedCurve: 'prime256v1',
paramEncoding: 'named',
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'sec1',
format: 'pem',
cipher: 'aes-128-cbc',
passphrase: 'secret'
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert.match(publicKey, spkiExp);
assert.strictEqual(typeof privateKey, 'string');
assert.match(privateKey, sec1EncExp('AES-128-CBC'));
// Since the private key is encrypted, signing shouldn't work anymore.
assert.throws(() => testSignVerify(publicKey, privateKey),
common.hasOpenSSL3 ? {
message: 'error:07880109:common libcrypto ' +
'routines::interrupted or cancelled'
} : {
name: 'TypeError',
code: 'ERR_MISSING_PASSPHRASE',
message: 'Passphrase required for encrypted key'
});
testSignVerify(publicKey, { key: privateKey, passphrase: 'secret' });
}));
}