From 000d7d1560503ec3340fbc04e4342c62abdaf2b1 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 3 Dec 2026 16:05:59 +0000 Subject: [PATCH] tls: add --tls-groups command-line option Set tls.DEFAULT_ECDH_CURVE from the command line or NODE_OPTIONS. Assisted-by: Claude Opus 5.5 Signed-off-by: James M Snell --- doc/api/cli.md | 11 +++++++ doc/api/tls.md | 6 ++-- doc/node-config-schema.json | 4 +++ doc/node.1 | 6 ++++ lib/tls.js | 2 +- src/node_options.cc | 5 +++ src/node_options.h | 1 + test/parallel/test-tls-groups-cli.js | 47 ++++++++++++++++++++++++++++ 8 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-tls-groups-cli.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 293c5286aa60..606e86f4e3e3 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -3620,6 +3620,15 @@ added: v4.0.0 Specify an alternative default TLS cipher list. Requires Node.js to be built with crypto support (default). +### `--tls-groups=list` + + + +Set [`tls.DEFAULT_ECDH_CURVE`][], the default colon-separated list of TLS +groups used for key agreement. **Default:** `'auto'`. + ### `--tls-keylog=file` The default named curve or TLS group list to use for key agreement in a TLS -server. The default value is `'auto'`. See [`tls.createSecureContext()`][] for -further information. +server. The default value is `'auto'`, or the value of the [`--tls-groups`][] +command-line option. See [`tls.createSecureContext()`][] for further +information. ## `tls.DEFAULT_MAX_VERSION` @@ -2673,6 +2674,7 @@ added: v0.11.3 [`'session'`]: #event-session [`'tlsClientError'`]: #event-tlsclienterror [`--tls-cipher-list`]: cli.md#--tls-cipher-listlist +[`--tls-groups`]: cli.md#--tls-groupslist [`--use-bundled-ca`]: cli.md#--use-bundled-ca---use-openssl-ca [`--use-openssl-ca`]: cli.md#--use-bundled-ca---use-openssl-ca [`--use-system-ca`]: cli.md#--use-system-ca diff --git a/doc/node-config-schema.json b/doc/node-config-schema.json index 098bae8efd3e..160ad48e59d0 100644 --- a/doc/node-config-schema.json +++ b/doc/node-config-schema.json @@ -791,6 +791,10 @@ "type": "string", "description": "use an alternative default TLS cipher list" }, + "tls-groups": { + "type": "string", + "description": "set the default TLS key exchange group list (default: auto)" + }, "tls-keylog": { "type": "string", "description": "log TLS decryption keys to named file for traffic analysis" diff --git a/doc/node.1 b/doc/node.1 index c7b49c61603a..bd9095df799a 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -1810,6 +1810,10 @@ Set \fBprocess.title\fR on startup. Specify an alternative default TLS cipher list. Requires Node.js to be built with crypto support (default). . +.It Fl -tls-groups Ns = Ns Ar list +Set \fBtls.DEFAULT_ECDH_CURVE\fR, the default colon-separated list of TLS +groups used for key agreement. \fBDefault:\fR \fB'auto'\fR. +. .It Fl -tls-keylog Ns = Ns Ar file Log TLS key material to a file. The key material is in NSS \fBSSLKEYLOGFILE\fR format and can be used by software (such as Wireshark) to decrypt the TLS @@ -2546,6 +2550,8 @@ one is included in the list below. .It \fB--tls-cipher-list\fR .It +\fB--tls-groups\fR +.It \fB--tls-keylog\fR .It \fB--tls-max-v1.2\fR diff --git a/lib/tls.js b/lib/tls.js index 13171847c7e8..ee6c34daea7b 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -112,7 +112,7 @@ defineRenegotiationLimit('CLIENT_RENEG_WINDOW', 'window'); exports.DEFAULT_CIPHERS = getOptionValue('--tls-cipher-list'); -exports.DEFAULT_ECDH_CURVE = 'auto'; +exports.DEFAULT_ECDH_CURVE = getOptionValue('--tls-groups'); if (getOptionValue('--tls-min-v1.0')) exports.DEFAULT_MIN_VERSION = 'TLSv1'; diff --git a/src/node_options.cc b/src/node_options.cc index cece3acc4a90..79d60c2b8542 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -1509,6 +1509,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvvar); + AddOption("--tls-groups", + "set the default TLS key exchange group list (default: auto)", + &EnvironmentOptions::tls_groups, + kAllowedInEnvvar); + AddOption("--tls-keylog", "log TLS decryption keys to named file for traffic analysis", &EnvironmentOptions::tls_keylog, diff --git a/src/node_options.h b/src/node_options.h index 6392c39cd3da..00c6eeb50de4 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -153,6 +153,7 @@ class EnvironmentOptions : public Options { std::string unhandled_rejections; std::string watch_mode_kill_signal = "SIGTERM"; std::string eval_string; + std::string tls_groups = "auto"; std::string tls_keylog; std::string config_file_path; std::string experimental_package_map_path; diff --git a/test/parallel/test-tls-groups-cli.js b/test/parallel/test-tls-groups-cli.js new file mode 100644 index 000000000000..6a1a40fb7f01 --- /dev/null +++ b/test/parallel/test-tls-groups-cli.js @@ -0,0 +1,47 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +// Test that --tls-groups sets tls.DEFAULT_ECDH_CURVE. + +const { spawnSyncAndAssert } = require('../common/child_process'); +const fixtures = require('../common/fixtures'); + +spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], { + stdout: 'auto', + trim: true, +}); + +spawnSyncAndAssert(process.execPath, + ['--tls-groups=P-384:P-256', '-p', 'tls.DEFAULT_ECDH_CURVE'], + { stdout: 'P-384:P-256', trim: true }); + +if (!process.config.variables.node_without_node_options) { + spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], { + env: { ...process.env, NODE_OPTIONS: '--tls-groups=P-384' }, + }, { stdout: 'P-384', trim: true }); +} + +// The option applies to servers and clients that do not set ecdhCurve. +const script = ` + const tls = require('tls'); + const server = tls.createServer({ + key: ${JSON.stringify(fixtures.readKey('agent2-key.pem', 'utf8'))}, + cert: ${JSON.stringify(fixtures.readKey('agent2-cert.pem', 'utf8'))}, + }, (conn) => conn.end()); + server.listen(0, () => { + const client = tls.connect({ + port: server.address().port, + rejectUnauthorized: false, + }, () => { + console.log(client.getEphemeralKeyInfo().name); + client.end(); + server.close(); + }); + }); +`; +spawnSyncAndAssert(process.execPath, ['--tls-groups=P-384', '-e', script], { + stdout: 'secp384r1', + trim: true, +});