mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
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>
181 lines
5.6 KiB
JavaScript
181 lines
5.6 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const {
|
|
createCipheriv,
|
|
createHash,
|
|
getCiphers,
|
|
getCipherInfo,
|
|
} = require('crypto');
|
|
const { hasFIPS, isBoringSSL } = require('../common/crypto');
|
|
|
|
const assert = require('assert');
|
|
|
|
const ciphers = getCiphers();
|
|
|
|
assert.strictEqual(getCipherInfo(-1), undefined);
|
|
assert.strictEqual(getCipherInfo('cipher that does not exist'), undefined);
|
|
if (!isBoringSSL) {
|
|
assert.deepStrictEqual(
|
|
ciphers.filter((cipher) => cipher.includes('cbc-hmac')), []);
|
|
for (const cipher of [
|
|
'null',
|
|
'aes-128-cbc-hmac-sha1',
|
|
'aes-256-cbc-hmac-sha1',
|
|
'aes-128-cbc-hmac-sha256',
|
|
'aes-256-cbc-hmac-sha256',
|
|
'aes-128-cbc-hmac-sha1-etm',
|
|
'aes-192-cbc-hmac-sha1-etm',
|
|
'aes-256-cbc-hmac-sha1-etm',
|
|
'aes-128-cbc-hmac-sha256-etm',
|
|
'aes-192-cbc-hmac-sha256-etm',
|
|
'aes-256-cbc-hmac-sha256-etm',
|
|
'aes-128-cbc-hmac-sha512-etm',
|
|
'aes-192-cbc-hmac-sha512-etm',
|
|
'aes-256-cbc-hmac-sha512-etm',
|
|
]) {
|
|
assert(!ciphers.includes(cipher));
|
|
assert.strictEqual(getCipherInfo(cipher), undefined);
|
|
assert.throws(
|
|
() => createCipheriv(cipher, Buffer.alloc(16), Buffer.alloc(16)), {
|
|
code: 'ERR_CRYPTO_UNKNOWN_CIPHER',
|
|
});
|
|
}
|
|
}
|
|
|
|
if (ciphers.includes('aes-128-wrap-inv')) {
|
|
const alias = 'aes128-wrap-inv';
|
|
assert(ciphers.includes(alias));
|
|
assert.deepStrictEqual(getCipherInfo(alias),
|
|
getCipherInfo('aes-128-wrap-inv'));
|
|
}
|
|
assert(!ciphers.some((cipher) => /^\d+(?:\.\d+)+$/.test(cipher)));
|
|
|
|
// A failed provider fetch must not contaminate the OpenSSL error queue.
|
|
assert.throws(() => createHash('sha256', { outputLength: 28 }), {
|
|
code: 'ERR_OSSL_EVP_NOT_XOF_OR_INVALID_LENGTH',
|
|
});
|
|
|
|
for (const cipher of ciphers) {
|
|
const info = getCipherInfo(cipher);
|
|
assert(info);
|
|
if (info.nid !== undefined) {
|
|
const info2 = getCipherInfo(info.nid);
|
|
assert.deepStrictEqual(info, info2);
|
|
}
|
|
}
|
|
|
|
const info = getCipherInfo('aes-128-cbc');
|
|
assert.strictEqual(info.name, 'aes-128-cbc');
|
|
assert.strictEqual(info.nid, 419);
|
|
assert.strictEqual(info.blockSize, 16);
|
|
assert.strictEqual(info.ivLength, 16);
|
|
assert.strictEqual(info.keyLength, 16);
|
|
assert.strictEqual(info.mode, 'cbc');
|
|
|
|
[null, undefined, [], {}].forEach((arg) => {
|
|
assert.throws(() => getCipherInfo(arg), {
|
|
code: 'ERR_INVALID_ARG_TYPE'
|
|
});
|
|
});
|
|
|
|
[null, '', 1, true].forEach((options) => {
|
|
assert.throws(
|
|
() => getCipherInfo('aes-192-cbc', options), {
|
|
code: 'ERR_INVALID_ARG_TYPE'
|
|
});
|
|
});
|
|
|
|
[null, '', {}, [], true].forEach((len) => {
|
|
assert.throws(
|
|
() => getCipherInfo('aes-192-cbc', { keyLength: len }), {
|
|
code: 'ERR_INVALID_ARG_TYPE'
|
|
});
|
|
assert.throws(
|
|
() => getCipherInfo('aes-192-cbc', { ivLength: len }), {
|
|
code: 'ERR_INVALID_ARG_TYPE'
|
|
});
|
|
});
|
|
|
|
assert(!getCipherInfo('aes-128-cbc', { keyLength: 12 }));
|
|
assert(getCipherInfo('aes-128-cbc', { keyLength: 16 }));
|
|
assert(!getCipherInfo('aes-128-cbc', { ivLength: 12 }));
|
|
assert(getCipherInfo('aes-128-cbc', { ivLength: 16 }));
|
|
|
|
assert(!getCipherInfo('aes-128-ccm', { ivLength: 1 }));
|
|
assert(!getCipherInfo('aes-128-ccm', { ivLength: 14 }));
|
|
if (!isBoringSSL) {
|
|
for (let n = 7; n <= 13; n++)
|
|
assert(getCipherInfo('aes-128-ccm', { ivLength: n }));
|
|
} else {
|
|
common.printSkipMessage('Skipping unsupported aes-128-ccm test cases');
|
|
}
|
|
|
|
assert(!getCipherInfo('aes-128-ocb', { ivLength: 16 }));
|
|
if (hasFIPS(3)) {
|
|
assert.strictEqual(
|
|
getCipherInfo('aes-128-ocb', { ivLength: 12 }), undefined);
|
|
} else if (!isBoringSSL) {
|
|
for (let n = 1; n < 16; n++)
|
|
assert(getCipherInfo('aes-128-ocb', { ivLength: n }));
|
|
} else {
|
|
common.printSkipMessage('Skipping unsupported aes-128-ocb test cases');
|
|
}
|
|
|
|
if (ciphers.includes('aes-128-cbc-cts')) {
|
|
const info = getCipherInfo('aes-128-cbc-cts');
|
|
assert.strictEqual(info.name, 'aes-128-cbc-cts');
|
|
assert.strictEqual(info.mode, 'cbc');
|
|
assert.strictEqual(info.keyLength, 16);
|
|
assert.strictEqual(info.blockSize, 16);
|
|
assert.strictEqual(info.ivLength, 16);
|
|
assert(getCipherInfo('aes-128-cbc-cts', { ivLength: 16 }));
|
|
assert(!getCipherInfo('aes-128-cbc-cts', { ivLength: 15 }));
|
|
} else {
|
|
common.printSkipMessage('Skipping unsupported aes-128-cbc-cts test cases');
|
|
}
|
|
|
|
if (ciphers.includes('aes-128-siv')) {
|
|
const info = getCipherInfo('aes-128-siv');
|
|
assert.strictEqual(info.name, 'aes-128-siv');
|
|
assert.strictEqual(info.mode, 'siv');
|
|
assert.strictEqual(info.keyLength, 32);
|
|
assert.strictEqual(info.ivLength, undefined);
|
|
assert(getCipherInfo('aes-128-siv', { ivLength: 0 }));
|
|
assert(!getCipherInfo('aes-128-siv', { ivLength: 1 }));
|
|
} else {
|
|
common.printSkipMessage('Skipping unsupported aes-128-siv test cases');
|
|
}
|
|
|
|
if (ciphers.includes('aes-128-gcm-siv')) {
|
|
const info = getCipherInfo('aes-128-gcm-siv');
|
|
assert.strictEqual(info.name, 'aes-128-gcm-siv');
|
|
assert.strictEqual(info.mode, 'gcm-siv');
|
|
assert.strictEqual(info.keyLength, 16);
|
|
assert.strictEqual(info.ivLength, 12);
|
|
assert(getCipherInfo('aes-128-gcm-siv', { ivLength: 12 }));
|
|
assert(!getCipherInfo('aes-128-gcm-siv', { ivLength: 11 }));
|
|
} else {
|
|
common.printSkipMessage('Skipping unsupported aes-128-gcm-siv test cases');
|
|
}
|
|
|
|
for (const [name, mode, keyLength, ivLength] of [
|
|
['sm4-gcm', 'gcm', 16, 12],
|
|
['sm4-ccm', 'ccm', 16, 12],
|
|
['sm4-xts', 'xts', 32, 16],
|
|
]) {
|
|
if (ciphers.includes(name)) {
|
|
const info = getCipherInfo(name);
|
|
assert.strictEqual(info.name, name);
|
|
assert.strictEqual(info.mode, mode);
|
|
assert.strictEqual(info.nid, undefined);
|
|
assert.strictEqual(info.keyLength, keyLength);
|
|
assert.strictEqual(info.ivLength, ivLength);
|
|
} else {
|
|
common.printSkipMessage(`Skipping unsupported ${name} test cases`);
|
|
}
|
|
}
|