Files
node/test/parallel/test-crypto-private-decrypt-gh32240.js
T
Filip Skokan acbc3ff133 test,benchmark: drop OpenSSL 1.x-only coverage
Delete test-crypto-ecb.js, which can no longer run anywhere: Blowfish
is available only from OpenSSL's legacy provider and is absent from
BoringSSL.

The addon and cctest version guards become OPENSSL_IS_BORINGSSL checks.
Remove legacy digest-alias coverage and unreachable OpenSSL 1.x
branches. JavaScript test and benchmark gates, skip reasons, and TLS
error expectations that distinguished OpenSSL 1.x from provider-backed
OpenSSL now distinguish BoringSSL, including PKCS12 parsing, named DH
groups, private-key serialization, RSA-PSS parameters, consolidated
provider caches, FIPS availability, and empty KMAC output. Keep the CCM
alternate finalization error only for BoringSSL.

Provider-only test skips use version-neutral terminology or state the
actual minimum OpenSSL version.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/64777
Fixes: https://github.com/nodejs/node/issues/56733
Refs: https://github.com/nodejs/node/pull/64211
Refs: https://github.com/nodejs/node/pull/63966
Refs: https://github.com/nodejs/node/pull/53329
Refs: https://github.com/nodejs/node/pull/48950
Refs: https://github.com/nodejs/node/issues/45465
Refs: https://github.com/nodejs/node/issues/42827
Refs: https://github.com/nodejs/node/issues/47076
Refs: https://github.com/nodejs/node/pull/62862
Refs: https://github.com/nodejs/node/pull/38512
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-10-25 22:36:32 +01:00

72 lines
1.8 KiB
JavaScript

'use strict';
// Verify that privateDecrypt() does not leave an error on the
// openssl error stack that is visible to subsequent operations.
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPairSync,
publicEncrypt,
privateDecrypt,
} = require('crypto');
const {
hasFIPS,
isBoringSSL,
} = require('../common/crypto');
const fips3 = hasFIPS(3);
const fips4 = hasFIPS(4);
const pair = generateKeyPairSync('rsa', {
modulusLength: fips3 ? 2048 : 512,
});
const expected = Buffer.from('shibboleth');
const options = fips3 ? { oaepHash: 'sha256' } : {};
const encrypted = publicEncrypt({ key: pair.publicKey, ...options }, expected);
const pkey = pair.privateKey.export({ type: 'pkcs1', format: 'pem' });
if (fips3) {
assert.throws(() => pair.privateKey.export({
type: 'pkcs1',
format: 'pem',
cipher: 'aes-128-cbc',
passphrase: 'secret',
}), {
code: 'ERR_OSSL_EVP_UNSUPPORTED',
});
}
if (fips4) {
assert.throws(() => pair.privateKey.export({
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'secret',
}), {
code: 'ERR_OSSL_PASSWORD_STRENGTH_TOO_WEAK',
});
}
const pkeyEncrypted =
pair.privateKey.export({
type: fips3 ? 'pkcs8' : 'pkcs1',
format: 'pem',
cipher: fips3 ? 'aes-256-cbc' : 'aes-128-cbc',
passphrase: 'password',
});
function decrypt(key) {
const decrypted = privateDecrypt({ key, ...options }, encrypted);
assert.deepStrictEqual(decrypted, expected);
}
decrypt(pkey);
assert.throws(() => decrypt(pkeyEncrypted), isBoringSSL ?
{ code: 'ERR_MISSING_PASSPHRASE' } :
{ message: 'error:07880109:common libcrypto routines::interrupted or ' +
'cancelled' });
decrypt(pkey); // Should not throw.