Files
node/test/parallel/test-crypto-openssl-error-queue.js
Matteo Collina be6f8f800a crypto: prevent stale OpenSSL errors
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>
2026-11-06 07:28:07 +00:00

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();