Skip to content

Commit 3000af8

Browse files
committed
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 <jasnell@gmail.com>
1 parent 6545c34 commit 3000af8

8 files changed

Lines changed: 77 additions & 3 deletions

File tree

‎doc/api/cli.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,15 @@ added: v4.0.0
36203620
Specify an alternative default TLS cipher list. Requires Node.js to be built
36213621
with crypto support (default).
36223622

3623+
### `--tls-groups=list`
3624+
3625+
<!-- YAML
3626+
added: REPLACEME
3627+
-->
3628+
3629+
Set [`tls.DEFAULT_ECDH_CURVE`][], the default colon-separated list of TLS
3630+
groups used for key agreement. **Default:** `'auto'`.
3631+
36233632
### `--tls-keylog=file`
36243633

36253634
<!-- YAML
@@ -4513,6 +4522,7 @@ one is included in the list below.
45134522
* `--throw-deprecation`
45144523
* `--title`
45154524
* `--tls-cipher-list`
4525+
* `--tls-groups`
45164526
* `--tls-keylog`
45174527
* `--tls-max-v1.2`
45184528
* `--tls-max-v1.3`
@@ -5107,6 +5117,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
51075117
[`permission.drop()`]: permissions.md#permissiondropscope-reference
51085118
[`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn
51095119
[`session.connectToMainThread()`]: inspector.md#sessionconnecttomainthread
5120+
[`tls.DEFAULT_ECDH_CURVE`]: tls.md#tlsdefault_ecdh_curve
51105121
[`tls.DEFAULT_MAX_VERSION`]: tls.md#tlsdefault_max_version
51115122
[`tls.DEFAULT_MIN_VERSION`]: tls.md#tlsdefault_min_version
51125123
[`unhandledRejection`]: process.md#event-unhandledrejection

‎doc/api/tls.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,8 +2596,9 @@ changes:
25962596
-->
25972597

25982598
The default named curve or TLS group list to use for key agreement in a TLS
2599-
server. The default value is `'auto'`. See [`tls.createSecureContext()`][] for
2600-
further information.
2599+
server. The default value is `'auto'`, or the value of the [`--tls-groups`][]
2600+
command-line option. See [`tls.createSecureContext()`][] for further
2601+
information.
26012602

26022603
## `tls.DEFAULT_MAX_VERSION`
26032604

@@ -2673,6 +2674,7 @@ added: v0.11.3
26732674
[`'session'`]: #event-session
26742675
[`'tlsClientError'`]: #event-tlsclienterror
26752676
[`--tls-cipher-list`]: cli.md#--tls-cipher-listlist
2677+
[`--tls-groups`]: cli.md#--tls-groupslist
26762678
[`--use-bundled-ca`]: cli.md#--use-bundled-ca---use-openssl-ca
26772679
[`--use-openssl-ca`]: cli.md#--use-bundled-ca---use-openssl-ca
26782680
[`--use-system-ca`]: cli.md#--use-system-ca

‎doc/node-config-schema.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@
791791
"type": "string",
792792
"description": "use an alternative default TLS cipher list"
793793
},
794+
"tls-groups": {
795+
"type": "string",
796+
"description": "set the default TLS key exchange group list (default: auto)"
797+
},
794798
"tls-keylog": {
795799
"type": "string",
796800
"description": "log TLS decryption keys to named file for traffic analysis"

‎doc/node.1‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,10 @@ Set \fBprocess.title\fR on startup.
18101810
Specify an alternative default TLS cipher list. Requires Node.js to be built
18111811
with crypto support (default).
18121812
.
1813+
.It Fl -tls-groups Ns = Ns Ar list
1814+
Set \fBtls.DEFAULT_ECDH_CURVE\fR, the default colon-separated list of TLS
1815+
groups used for key agreement.
1816+
.
18131817
.It Fl -tls-keylog Ns = Ns Ar file
18141818
Log TLS key material to a file. The key material is in NSS \fBSSLKEYLOGFILE\fR
18151819
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.
25462550
.It
25472551
\fB--tls-cipher-list\fR
25482552
.It
2553+
\fB--tls-groups\fR
2554+
.It
25492555
\fB--tls-keylog\fR
25502556
.It
25512557
\fB--tls-max-v1.2\fR

‎lib/tls.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ defineRenegotiationLimit('CLIENT_RENEG_WINDOW', 'window');
112112

113113
exports.DEFAULT_CIPHERS = getOptionValue('--tls-cipher-list');
114114

115-
exports.DEFAULT_ECDH_CURVE = 'auto';
115+
exports.DEFAULT_ECDH_CURVE = getOptionValue('--tls-groups');
116116

117117
if (getOptionValue('--tls-min-v1.0'))
118118
exports.DEFAULT_MIN_VERSION = 'TLSv1';

‎src/node_options.cc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
15091509

15101510
AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvvar);
15111511

1512+
AddOption("--tls-groups",
1513+
"set the default TLS key exchange group list (default: auto)",
1514+
&EnvironmentOptions::tls_groups,
1515+
kAllowedInEnvvar);
1516+
15121517
AddOption("--tls-keylog",
15131518
"log TLS decryption keys to named file for traffic analysis",
15141519
&EnvironmentOptions::tls_keylog,

‎src/node_options.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class EnvironmentOptions : public Options {
153153
std::string unhandled_rejections;
154154
std::string watch_mode_kill_signal = "SIGTERM";
155155
std::string eval_string;
156+
std::string tls_groups = "auto";
156157
std::string tls_keylog;
157158
std::string config_file_path;
158159
std::string experimental_package_map_path;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
6+
// Test that --tls-groups sets tls.DEFAULT_ECDH_CURVE.
7+
8+
const { spawnSyncAndAssert } = require('../common/child_process');
9+
const fixtures = require('../common/fixtures');
10+
11+
spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], {
12+
stdout: 'auto',
13+
trim: true,
14+
});
15+
16+
spawnSyncAndAssert(process.execPath,
17+
['--tls-groups=P-384:P-256', '-p', 'tls.DEFAULT_ECDH_CURVE'],
18+
{ stdout: 'P-384:P-256', trim: true });
19+
20+
spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], {
21+
env: { ...process.env, NODE_OPTIONS: '--tls-groups=P-384' },
22+
}, { stdout: 'P-384', trim: true });
23+
24+
// The option applies to servers and clients that do not set ecdhCurve.
25+
const script = `
26+
const tls = require('tls');
27+
const server = tls.createServer({
28+
key: ${JSON.stringify(fixtures.readKey('agent2-key.pem', 'utf8'))},
29+
cert: ${JSON.stringify(fixtures.readKey('agent2-cert.pem', 'utf8'))},
30+
}, (conn) => conn.end());
31+
server.listen(0, () => {
32+
const client = tls.connect({
33+
port: server.address().port,
34+
rejectUnauthorized: false,
35+
}, () => {
36+
console.log(client.getEphemeralKeyInfo().name);
37+
client.end();
38+
server.close();
39+
});
40+
});
41+
`;
42+
spawnSyncAndAssert(process.execPath, ['--tls-groups=P-384', '-e', script], {
43+
stdout: 'secp384r1',
44+
trim: true,
45+
});

0 commit comments

Comments
 (0)