mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Clear errors raised by key comparison, SPKAC parsing, and JWK import. Ensure TLS and private-key parsing only inspect errors from their own OpenSSL calls. Assisted-by: Codex Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/67225 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('node:assert');
|
|
const {
|
|
Certificate,
|
|
createPrivateKey,
|
|
createPublicKey,
|
|
diffieHellman,
|
|
generateKeyPairSync,
|
|
} = require('node:crypto');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const privateKeyPem = fixtures.readKey('rsa_private.pem');
|
|
const rsaPublicKey = createPublicKey(fixtures.readKey('rsa_public.pem'));
|
|
const ec = generateKeyPairSync('ec', { namedCurve: 'P-256' });
|
|
|
|
function parseValidPrivateKey() {
|
|
// This must not pick up an error from the preceding operation.
|
|
createPrivateKey(privateKeyPem);
|
|
}
|
|
|
|
assert.strictEqual(rsaPublicKey.equals(ec.publicKey), false);
|
|
parseValidPrivateKey();
|
|
|
|
for (const method of ['verifySpkac', 'exportPublicKey', 'exportChallenge']) {
|
|
Certificate[method](Buffer.from('garbage'));
|
|
parseValidPrivateKey();
|
|
}
|
|
|
|
assert.throws(() => diffieHellman({
|
|
privateKey: ec.privateKey,
|
|
publicKey: {
|
|
key: {
|
|
kty: 'EC',
|
|
crv: 'P-256',
|
|
x: 'AAAA',
|
|
y: 'AAAA',
|
|
},
|
|
format: 'jwk',
|
|
},
|
|
}), { code: 'ERR_CRYPTO_INVALID_JWK' });
|
|
parseValidPrivateKey();
|