GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: update tests to run with OpenSSL >= 3.0 FIPS mode · nodejs/node@fd7e904

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/crypto
    • webcrypto.js
  • test
    • common
      • crypto.js
    • fixtures/keys
      • Makefile
      • agent1-fips.pfx
      • ec-fips.pfx
    • parallel
      • test-crypto-argon2-job.js
      • test-crypto-argon2.js
      • test-crypto-async-sign-verify.js
      • test-crypto-authenticated-stream.js
      • test-crypto-authenticated.js
      • test-crypto-certificate.js
      • test-crypto-cipheriv-decipheriv.js
      • test-crypto-classes.js
      • test-crypto-dh-constructor.js
      • test-crypto-dh-curves.js
      • test-crypto-dh-generate-keys.js
      • test-crypto-dh-leak.js
      • test-crypto-dh-modp2-views.js
      • test-crypto-dh-modp2.js
      • test-crypto-dh-odd-key.js
      • test-crypto-dh-shared.js
      • test-crypto-dh.js
      • test-crypto-ecdh-convert-key.js
      • test-crypto-eddsa-variants.js
      • test-crypto-encap-decap.js
      • test-crypto-getcipherinfo.js
      • test-crypto-hkdf.js
      • test-crypto-hmac.js
      • test-crypto-job-error-parity.js
      • test-crypto-key-objects-messageport.js
      • test-crypto-key-objects-to-crypto-key.js
      • test-crypto-key-objects.js
      • test-crypto-key-store.js
      • test-crypto-keygen-async-dsa.js
      • test-crypto-keygen-async-elliptic-curve-jwk-ec.js
      • test-crypto-keygen-async-elliptic-curve-jwk-rsa.js
      • test-crypto-keygen-async-elliptic-curve-jwk.js
      • test-crypto-keygen-async-encrypted-private-key-der.js
      • test-crypto-keygen-async-encrypted-private-key.js
      • test-crypto-keygen-async-explicit-elliptic-curve-encrypted.js.js
      • test-crypto-keygen-async-named-elliptic-curve-encrypted.js
      • test-crypto-keygen-async-rsa.js
      • test-crypto-keygen-bit-length.js
      • test-crypto-keygen-dh-classic.js
      • test-crypto-keygen-eddsa.js
      • test-crypto-keygen-empty-passphrase-no-error.js
      • test-crypto-keygen-empty-passphrase-no-prompt.js
      • test-crypto-keygen-invalid-parameter-encoding-dsa.js
      • test-crypto-keygen-key-object-without-encoding.js
      • test-crypto-keygen-key-objects.js
      • test-crypto-keygen-missing-oid.js
      • test-crypto-keygen-no-rsassa-pss-params.js
      • test-crypto-keygen-non-standard-public-exponent.js
      • test-crypto-keygen-promisify.js
      • test-crypto-keygen-raw.js
      • test-crypto-keygen-rfc8017-9-1.js
      • test-crypto-keygen-rfc8017-a-2-3.js
      • test-crypto-keygen-rsa-pss.js
      • test-crypto-keygen-sync.js
      • test-crypto-keyobject-brand-check.js
      • test-crypto-keyobject-clone-transfer.js
      • test-crypto-keyobject-hidden-slots.js
      • test-crypto-keyobject-no-own-symbols.js
      • test-crypto-pbkdf2.js
      • test-crypto-pqc-encrypted-pkcs8.js
      • test-crypto-private-decrypt-gh32240.js
      • test-crypto-publicDecrypt-fails-first-time.js
      • test-crypto-rsa-dsa.js
      • test-crypto-scrypt.js
      • test-crypto-secure-heap.js
      • test-crypto-sign-verify.js
      • test-crypto-worker-thread.js
      • test-crypto.js
      • test-https-agent-additional-options.js
      • test-https-agent-pfx-object-array-reuse.js
      • test-https-agent-session-eviction.js
      • test-https-pfx.js
      • test-https-selfsigned-no-keycertsign-no-crash.js
      • test-tls-alert.js
      • test-tls-client-getephemeralkeyinfo.js
      • test-tls-client-mindhsize.js
      • test-tls-dhe.js
      • test-tls-ecdh-multiple.js
      • test-tls-env-extra-ca-with-options.js
      • test-tls-getprotocol.js
      • test-tls-honorcipherorder.js
      • test-tls-invalid-pfx.js
      • test-tls-min-max-version.js
      • test-tls-multi-key.js
      • test-tls-multi-pfx.js
      • test-tls-passphrase.js
      • test-tls-pfx-authorizationerror.js
      • test-tls-session-cache.js
      • test-tls-set-ciphers.js
      • test-tls-write-error.js
      • test-webcrypto-aead-decrypt-detached-buffer.js
      • test-webcrypto-constructors.js
      • test-webcrypto-cryptokey-hidden-slots.js
      • test-webcrypto-deduplicate-usages.js
      • test-webcrypto-derivebits-argon2.js
      • test-webcrypto-derivebits-cfrg.js
      • test-webcrypto-derivebits.js
      • test-webcrypto-derivekey-cfrg.js
      • test-webcrypto-derivekey.js
      • test-webcrypto-digest.js
      • test-webcrypto-encrypt-decrypt-aes.js
      • test-webcrypto-encrypt-decrypt-chacha20-poly1305.js
      • test-webcrypto-encrypt-decrypt.js
      • test-webcrypto-export-import-cfrg.js
      • test-webcrypto-export-import.js
      • test-webcrypto-get-public-key.mjs
      • test-webcrypto-keygen.js
      • test-webcrypto-promise-prototype-pollution.mjs
      • test-webcrypto-raw-format-aliases.js
      • test-webcrypto-sign-verify-ecdsa.js
      • test-webcrypto-sign-verify-eddsa.js
      • test-webcrypto-sign-verify-hmac.js
      • test-webcrypto-sign-verify-kmac.js
      • test-webcrypto-sign-verify-ml-dsa.js
      • test-webcrypto-sign-verify-rsa.js
      • test-webcrypto-sign-verify.js
      • test-webcrypto-supports.mjs
      • test-webcrypto-wrap-unwrap.js
    • pummel
      • test-crypto-argon2-nonblocking-constructor.js
      • test-crypto-dh-keys.js
      • test-dh-regr.js
      • test-webcrypto-derivebits-pbkdf2.js
    • sequential
      • test-async-wrap-getasyncid.js
    • wpt
      • status
        • WebCryptoAPI.cjs
      • test-webcrypto.js

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/crypto/webcrypto.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/webcrypto.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,7 @@ class SubtleCrypto {
16171617
}
16181618

16191619
// Implements https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-supports
1620+
// TODO(panva): Make supports() account for the active FIPS state.
16201621
static supports(operation, algorithm, lengthOrAdditionalAlgorithm = null) {
16211622
emitExperimentalWarning('The supports Web Crypto API method');
16221623
if (this !== SubtleCrypto) throw new ERR_INVALID_THIS('SubtleCrypto constructor');
Collapse file

‎test/common/crypto.js‎

Copy file name to clipboardExpand all lines: test/common/crypto.js
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ function assertApproximateSize(key, expectedSize) {
5050
function testEncryptDecrypt(publicKey, privateKey) {
5151
const message = 'Hello Node.js world!';
5252
const plaintext = Buffer.from(message, 'utf8');
53+
const withOaepHash = (key) => {
54+
if (!hasFIPS(3)) return key;
55+
if (key?.key !== undefined) return { ...key, oaepHash: 'sha256' };
56+
return { key, oaepHash: 'sha256' };
57+
};
5358
for (const key of [publicKey, privateKey]) {
54-
const ciphertext = publicEncrypt(key, plaintext);
55-
const received = privateDecrypt(privateKey, ciphertext);
59+
const ciphertext = publicEncrypt(withOaepHash(key), plaintext);
60+
const received = privateDecrypt(withOaepHash(privateKey), ciphertext);
5661
assert.strictEqual(received.toString('utf8'), message);
5762
}
5863
}
@@ -118,6 +123,10 @@ const hasOpenSSL = (major = 0, minor = 0, patch = 0) => {
118123
return OPENSSL_VERSION_NUMBER >= opensslVersionNumber(major, minor, patch);
119124
};
120125

126+
const hasFIPS = (major = 0, minor = 0, patch = 0) => {
127+
return crypto.getFips() === 1 && hasOpenSSL(major, minor, patch);
128+
};
129+
121130
let opensslCli = null;
122131

123132
module.exports = {
@@ -134,6 +143,7 @@ module.exports = {
134143
sec1Exp,
135144
sec1EncExp,
136145
hasOpenSSL,
146+
hasFIPS,
137147
get hasOpenSSL3() {
138148
return hasOpenSSL(3);
139149
},
Collapse file

‎test/fixtures/keys/Makefile‎

Copy file name to clipboardExpand all lines: test/fixtures/keys/Makefile
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ all: \
88
ca5-cert.pem \
99
ca6-cert.pem \
1010
agent1-cert.pem \
11+
agent1-fips.pfx \
1112
agent1.pfx \
1213
agent2-cert.pem \
1314
agent3-cert.pem \
@@ -39,6 +40,7 @@ all: \
3940
dsa_private_encrypted_1025.pem \
4041
dsa_public_1025.pem \
4142
ec-cert.pem \
43+
ec-fips.pfx \
4244
ec.pfx \
4345
fake-cnnic-root-cert.pem \
4446
intermediate-ca-cert.pem \
@@ -444,6 +446,20 @@ agent1.pfx: agent1-cert.pem agent1-key.pem ca1-cert.pem
444446
-out agent1.pfx \
445447
-password pass:sample
446448

449+
# PKCS12KDF is unavailable under FIPS properties. Use PBMAC1 with PBKDF2
450+
# instead, alongside AES-256/PBKDF2 key protection.
451+
agent1-fips.pfx: agent1-cert.pem agent1-key.pem ca1-cert.pem
452+
openssl pkcs12 -export \
453+
-keypbe AES-256-CBC \
454+
-certpbe AES-256-CBC \
455+
-iter 2048 \
456+
-pbmac1_pbkdf2 \
457+
-in agent1-cert.pem \
458+
-inkey agent1-key.pem \
459+
-certfile ca1-cert.pem \
460+
-out agent1-fips.pfx \
461+
-password pass:password
462+
447463
agent1-verify: agent1-cert.pem ca1-cert.pem
448464
openssl verify -CAfile ca1-cert.pem agent1-cert.pem
449465

@@ -787,6 +803,18 @@ ec.pfx: ec-cert.pem ec-key.pem
787803
-out ec.pfx \
788804
-password pass:
789805

806+
# See agent1-fips.pfx for why the FIPS fixture uses PBMAC1.
807+
ec-fips.pfx: ec-cert.pem ec-key.pem
808+
openssl pkcs12 -export \
809+
-keypbe AES-256-CBC \
810+
-certpbe AES-256-CBC \
811+
-iter 2048 \
812+
-pbmac1_pbkdf2 \
813+
-in ec-cert.pem \
814+
-inkey ec-key.pem \
815+
-out ec-fips.pfx \
816+
-password pass:password
817+
790818
dh512.pem:
791819
openssl dhparam -out dh512.pem 512
792820

Collapse file

‎test/fixtures/keys/agent1-fips.pfx‎

Copy file name to clipboard
3.72 KB
Binary file not shown.
Collapse file

‎test/fixtures/keys/ec-fips.pfx‎

Copy file name to clipboard
1.23 KB
Binary file not shown.
Collapse file

‎test/parallel/test-crypto-argon2-job.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-argon2-job.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7-
const { hasOpenSSL } = require('../common/crypto');
7+
const { hasFIPS, hasOpenSSL } = require('../common/crypto');
88

99
if (!hasOpenSSL(3, 2))
1010
common.skip('requires OpenSSL >= 3.2');
11+
if (hasFIPS(3))
12+
common.skip('Argon2 is not available in FIPS mode');
1113

1214
// Exercises the native Argon2 job directly via internalBinding, bypassing
1315
// the JS validators, to ensure that if invalid parameters ever reach the
Collapse file

‎test/parallel/test-crypto-argon2.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-argon2.js
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../common');
33
if (!common.hasCrypto)
44
common.skip('missing crypto');
55

6-
const { hasOpenSSL } = require('../common/crypto');
6+
const { hasFIPS, hasOpenSSL } = require('../common/crypto');
77

88
if (!hasOpenSSL(3, 2))
99
common.skip('requires OpenSSL >= 3.2');
@@ -28,6 +28,17 @@ const secret = Buffer.alloc(8, 0x03);
2828
const associatedData = Buffer.alloc(12, 0x04);
2929
const defaults = { message, nonce, parallelism: 1, tagLength: 64, memory: 8, passes: 3 };
3030

31+
if (hasFIPS(3)) {
32+
assert.throws(() => crypto.argon2Sync('argon2id', defaults), {
33+
code: 'ERR_OSSL_EVP_UNSUPPORTED',
34+
});
35+
crypto.argon2('argon2id', defaults, common.mustCall((err, result) => {
36+
assert.strictEqual(err?.code, 'ERR_OSSL_EVP_UNSUPPORTED');
37+
assert.strictEqual(result, undefined);
38+
}));
39+
return;
40+
}
41+
3142
const good = [
3243
// Test vectors from RFC 9106 https://www.rfc-editor.org/rfc/rfc9106.html#name-test-vectors
3344
// and OpenSSL 3.2 https://github.com/openssl/openssl/blob/6dfa998f7ea150f9c6d4e4727cf6d5c82a68a8da/test/recipes/30-test_evp_data/evpkdf_argon2.txt
Collapse file

‎test/parallel/test-crypto-async-sign-verify.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-async-sign-verify.js
+43-18Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ const common = require('../common');
33
if (!common.hasCrypto)
44
common.skip('missing crypto');
55

6-
const { hasOpenSSL3 } = require('../common/crypto');
6+
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
77
const assert = require('assert');
88
const util = require('util');
99
const crypto = require('crypto');
1010
const fixtures = require('../common/fixtures');
1111

12+
const fips3 = hasFIPS(3);
13+
1214
function test(
1315
publicFixture,
1416
privateFixture,
@@ -65,6 +67,15 @@ function test(
6567
}
6668
}
6769

70+
function testSignFailure(privateFixture, algorithm, options, code) {
71+
const key = { key: fixtures.readKey(privateFixture), ...options };
72+
const data = Buffer.from('Hello world');
73+
assert.throws(() => crypto.sign(algorithm, data, key), { code });
74+
crypto.sign(algorithm, data, key, common.mustCall((err) => {
75+
assert.strictEqual(err?.code, code);
76+
}));
77+
}
78+
6879
// RSA w/ default padding
6980
test('rsa_public.pem', 'rsa_private.pem', 'sha256', true);
7081
test('rsa_public.pem', 'rsa_private.pem', 'sha256', true,
@@ -94,14 +105,19 @@ if (!process.features.openssl_is_boringssl) {
94105
test('ed448_public.pem', 'ed448_private.pem', undefined, true);
95106

96107
// ECDSA w/ der signature encoding
97-
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
98-
false);
99-
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
100-
false, { dsaEncoding: 'der' });
101-
102-
// ECDSA w/ ieee-p1363 signature encoding
103-
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384', false,
104-
{ dsaEncoding: 'ieee-p1363' });
108+
if (fips3) {
109+
testSignFailure('ec_secp256k1_private.pem', 'sha384', {},
110+
'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE');
111+
} else {
112+
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
113+
false);
114+
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384',
115+
false, { dsaEncoding: 'der' });
116+
117+
// ECDSA w/ ieee-p1363 signature encoding
118+
test('ec_secp256k1_public.pem', 'ec_secp256k1_private.pem', 'sha384', false,
119+
{ dsaEncoding: 'ieee-p1363' });
120+
}
105121

106122
// DSA w/ der signature encoding
107123
test('dsa_public.pem', 'dsa_private.pem', 'sha256',
@@ -157,7 +173,7 @@ MCowBQYDK2VuAyEA6pwGRbadNQAI/tYN8+/p/0/hbsdHfOEGr1ADiLVk/Gc=
157173

158174
let expected = /no default digest/;
159175
let expectedCode = 'ERR_OSSL_EVP_NO_DEFAULT_DIGEST';
160-
if (hasOpenSSL3 || process.features.openssl_is_boringssl) {
176+
if (hasOpenSSL(3) || process.features.openssl_is_boringssl) {
161177
expected = /operation[\s_]not[\s_]supported[\s_]for[\s_]this[\s_]keytype/i;
162178
expectedCode = 'ERR_OSSL_EVP_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE';
163179
}
@@ -170,12 +186,21 @@ MCowBQYDK2VuAyEA6pwGRbadNQAI/tYN8+/p/0/hbsdHfOEGr1ADiLVk/Gc=
170186
}
171187

172188
{
173-
const { privateKey } = crypto.generateKeyPairSync('rsa', {
174-
modulusLength: 512
175-
});
176-
crypto.sign('sha512', 'message', privateKey, common.mustCall((err) => {
177-
assert.ok(err);
178-
assert.match(err.message, /digest[\s_]too[\s_]big[\s_]for[\s_]rsa[\s_]key/i);
179-
assert.match(err.code, /^ERR_OSSL_.*DIGEST_TOO_BIG_FOR_RSA_KEY$/);
180-
}));
189+
if (fips3) {
190+
crypto.generateKeyPair('rsa', { modulusLength: 512 },
191+
common.mustCall((err) => {
192+
assert.strictEqual(
193+
err?.code, 'ERR_OSSL_RSA_INVALID_MODULUS');
194+
}));
195+
} else {
196+
const { privateKey } = crypto.generateKeyPairSync('rsa', {
197+
modulusLength: 512
198+
});
199+
crypto.sign('sha512', 'message', privateKey, common.mustCall((err) => {
200+
assert.ok(err);
201+
assert.match(
202+
err.message, /digest[\s_]too[\s_]big[\s_]for[\s_]rsa[\s_]key/i);
203+
assert.match(err.code, /^ERR_OSSL_.*DIGEST_TOO_BIG_FOR_RSA_KEY$/);
204+
}));
205+
}
181206
}
Collapse file

‎test/parallel/test-crypto-authenticated-stream.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-authenticated-stream.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (!common.hasCrypto)
66

77
const assert = require('assert');
88
const crypto = require('crypto');
9+
const { hasFIPS } = require('../common/crypto');
910
const fs = require('fs');
1011
const stream = require('stream');
1112
const tmpdir = require('../common/tmpdir');
@@ -120,6 +121,16 @@ function test(config) {
120121
return;
121122
}
122123

124+
if (hasFIPS(3)) {
125+
assert.throws(() => crypto.createDecipheriv(
126+
config.cipher, config.key, config.iv, {
127+
authTagLength: config.authTagLength,
128+
}), {
129+
code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION',
130+
});
131+
return;
132+
}
133+
123134
direct(config);
124135
mstream(config);
125136
fstream(config);
Collapse file

‎test/parallel/test-crypto-authenticated.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-authenticated.js
+37-14Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ const assert = require('assert');
2929
const crypto = require('crypto');
3030
const { inspect } = require('util');
3131
const fixtures = require('../common/fixtures');
32-
const { hasOpenSSL3 } = require('../common/crypto');
32+
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
3333

34-
const isFipsEnabled = crypto.getFips();
34+
const isFipsEnabled = crypto.getFips() === 1;
35+
const fips3 = hasFIPS(3);
3536

3637
//
3738
// Test authenticated encryption modes.
@@ -559,6 +560,14 @@ for (const test of TEST_CASES) {
559560
const ciphertext = Buffer.concat([cipher.update(plain), cipher.final()]);
560561
const tag = cipher.getAuthTag();
561562

563+
if (fips3 && mode === 'ccm') {
564+
assert.throws(() => crypto.createDecipheriv(
565+
`aes-128-${mode}`, key, iv, opts), {
566+
code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION',
567+
});
568+
continue;
569+
}
570+
562571
const decipher = crypto.createDecipheriv(`aes-128-${mode}`, key, iv, opts);
563572
decipher.setAuthTag(tag);
564573
assert.throws(() => {
@@ -636,15 +645,22 @@ for (const test of TEST_CASES) {
636645
const cipher = crypto.createCipheriv('aes-128-ccm', key, iv, opts);
637646
assert.throws(() => {
638647
cipher.final();
639-
}, hasOpenSSL3 ? {
648+
}, hasOpenSSL(3) ? {
640649
code: 'ERR_OSSL_TAG_NOT_SET'
641650
} : {
642651
message: /Unsupported state/
643652
});
644653
}
645654
}
646655

647-
if (!process.features.openssl_is_boringssl) {
656+
if (fips3) {
657+
assert.throws(() => crypto.createCipheriv(
658+
'chacha20-poly1305', Buffer.alloc(32), Buffer.alloc(12), {
659+
authTagLength: 16,
660+
}), {
661+
code: 'ERR_OSSL_EVP_UNSUPPORTED',
662+
});
663+
} else if (!process.features.openssl_is_boringssl) {
648664
const key = Buffer.alloc(32);
649665
const iv = Buffer.alloc(12);
650666

@@ -662,7 +678,7 @@ if (!process.features.openssl_is_boringssl) {
662678

663679
// ChaCha20-Poly1305 should respect the authTagLength option and should not
664680
// require the authentication tag before calls to update() during decryption.
665-
if (!process.features.openssl_is_boringssl) {
681+
if (!fips3 && !process.features.openssl_is_boringssl) {
666682
const key = Buffer.alloc(32);
667683
const iv = Buffer.alloc(12);
668684

@@ -713,7 +729,7 @@ if (!process.features.openssl_is_boringssl) {
713729
// shorter tags as long as their length was valid according to NIST SP 800-38D.
714730
// For ChaCha20-Poly1305, we intentionally deviate from that because there are
715731
// no recommended or approved authentication tag lengths below 16 bytes.
716-
if (!process.features.openssl_is_boringssl) {
732+
if (!fips3 && !process.features.openssl_is_boringssl) {
717733
const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
718734
return algo === 'chacha20-poly1305' && tampered === false;
719735
});
@@ -752,7 +768,7 @@ if (!process.features.openssl_is_boringssl) {
752768
}
753769

754770
// https://github.com/nodejs/node/issues/45874
755-
if (!process.features.openssl_is_boringssl) {
771+
if (!fips3 && !process.features.openssl_is_boringssl) {
756772
const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
757773
return algo === 'chacha20-poly1305' && tampered === false;
758774
});
@@ -798,13 +814,20 @@ if (ciphers.includes('aes-128-ccm')) {
798814
const tag = cipher.getAuthTag();
799815
assert.strictEqual(tag.length, 16);
800816

801-
const decipher = crypto.createDecipheriv('aes-128-ccm', key, nonce, {
802-
authTagLength: 16,
803-
});
804-
decipher.setAuthTag(tag);
805-
decipher.setAAD(Buffer.alloc(0), { plaintextLength: 0 });
806-
decipher.update(new DataView(new ArrayBuffer(0)));
807-
decipher.final();
817+
if (fips3) {
818+
assert.throws(() => crypto.createDecipheriv(
819+
'aes-128-ccm', key, nonce, { authTagLength: 16 }), {
820+
code: 'ERR_CRYPTO_UNSUPPORTED_OPERATION',
821+
});
822+
} else {
823+
const decipher = crypto.createDecipheriv('aes-128-ccm', key, nonce, {
824+
authTagLength: 16,
825+
});
826+
decipher.setAuthTag(tag);
827+
decipher.setAAD(Buffer.alloc(0), { plaintextLength: 0 });
828+
decipher.update(new DataView(new ArrayBuffer(0)));
829+
decipher.final();
830+
}
808831
} else {
809832
common.printSkipMessage('Skipping unsupported aes-128-ccm test');
810833
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.