mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Refresh conditional algorithm registration on FIPS changes and use the current state for parameter restrictions. Use per-algorithm availability checks in normalization and native named key generation. Remove getPqcKeyTypes(). Enable supports() tests under FIPS and cover state transitions in warmed workers. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66160 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
68 lines
1.4 KiB
JavaScript
68 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
|
|
const { subtle } = globalThis.crypto;
|
|
const fips3 = hasFIPS(3);
|
|
|
|
async function test(
|
|
algorithmName,
|
|
keyLength,
|
|
ivLength,
|
|
format = 'raw',
|
|
) {
|
|
if (fips3 && algorithmName === 'AES-OCB') {
|
|
await assert.rejects(
|
|
subtle.importKey(format, new Uint8Array(keyLength), algorithmName, false, ['decrypt']),
|
|
{ name: 'NotSupportedError', message: 'Unrecognized algorithm name' });
|
|
return;
|
|
}
|
|
const key = await subtle.importKey(
|
|
format,
|
|
new Uint8Array(keyLength),
|
|
{ name: algorithmName },
|
|
false,
|
|
['encrypt', 'decrypt'],
|
|
);
|
|
|
|
const data = new Uint8Array(32);
|
|
data.buffer.transfer();
|
|
|
|
await assert.rejects(
|
|
subtle.decrypt({ name: algorithmName, iv: new Uint8Array(ivLength) }, key, data),
|
|
{ name: 'OperationError' },
|
|
);
|
|
}
|
|
|
|
const tests = [
|
|
test('AES-GCM', 32, 12),
|
|
];
|
|
|
|
if (fips3) {
|
|
tests.push(assert.rejects(
|
|
subtle.importKey(
|
|
'raw-secret',
|
|
new Uint8Array(32),
|
|
'ChaCha20-Poly1305',
|
|
false,
|
|
['encrypt', 'decrypt']),
|
|
{ name: 'NotSupportedError' }));
|
|
} else {
|
|
tests.push(test('ChaCha20-Poly1305', 32, 12, 'raw-secret'));
|
|
}
|
|
|
|
if (hasOpenSSL(3)) {
|
|
tests.push(test(
|
|
'AES-OCB',
|
|
32,
|
|
12,
|
|
'raw-secret'));
|
|
}
|
|
|
|
Promise.all(tests).then(common.mustCall());
|