Files
node/test/parallel/test-crypto-dh-modp2-views.js
Filip Skokan 9b5d938fad test: remove obsolete BoringSSL skips
Run supported DH, ECDH, legacy TLS, TLS 1.2 PSK, cipher metadata,
raw key, and X.509 date cases with BoringSSL. Assert its DH flags,
curve format errors, and name-constraint behavior. Narrow key/cert
array exclusions to the failing multi-identity cases.

Use modp5 for the DH group setter checks and remove the unused legacy
protocol fallback helper.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66922
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-10-24 22:04:16 +00:00

40 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const { hasFIPS, modp2buf, isBoringSSL } = require('../common/crypto');
if (isBoringSSL) {
// BoringSSL omits this named group but accepts its raw parameters.
assert.throws(() => crypto.createDiffieHellmanGroup('modp2'), {
code: 'ERR_CRYPTO_UNKNOWN_DH_GROUP',
message: 'Unknown DH group',
});
}
if (hasFIPS(3)) {
assert.throws(() => crypto.createDiffieHellman(1024), {
code: 'ERR_INVALID_ARG_VALUE',
});
} else {
const modp2 = isBoringSSL ? crypto.createDiffieHellman(modp2buf, 2) :
crypto.createDiffieHellmanGroup('modp2');
const views = common.getArrayBufferViews(modp2buf);
for (const buf of [modp2buf, ...views]) {
// Ensure specific generator (string with encoding) works as expected with
// any ArrayBufferViews as the first argument to createDiffieHellman().
const exmodp2 = crypto.createDiffieHellman(buf, '02', 'hex');
modp2.generateKeys();
exmodp2.generateKeys();
const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey())
.toString('hex');
const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
.toString('hex');
assert.strictEqual(modp2Secret, exmodp2Secret);
}
}