Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

<!-- YAML
added: REPLACEME
-->

Set [`tls.DEFAULT_ECDH_CURVE`][], the default colon-separated list of TLS
groups used for key agreement. **Default:** `'auto'`.

### `--tls-keylog=file`

<!-- YAML
Expand Down Expand Up @@ -4513,6 +4522,7 @@ one is included in the list below.
* `--throw-deprecation`
* `--title`
* `--tls-cipher-list`
* `--tls-groups`
* `--tls-keylog`
* `--tls-max-v1.2`
* `--tls-max-v1.3`
Expand Down Expand Up @@ -5107,6 +5117,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[`permission.drop()`]: permissions.md#permissiondropscope-reference
[`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn
[`session.connectToMainThread()`]: inspector.md#sessionconnecttomainthread
[`tls.DEFAULT_ECDH_CURVE`]: tls.md#tlsdefault_ecdh_curve
[`tls.DEFAULT_MAX_VERSION`]: tls.md#tlsdefault_max_version
[`tls.DEFAULT_MIN_VERSION`]: tls.md#tlsdefault_min_version
[`unhandledRejection`]: process.md#event-unhandledrejection
Expand Down
6 changes: 4 additions & 2 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -2596,8 +2596,9 @@ changes:
-->

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`

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions doc/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
47 changes: 47 additions & 0 deletions test/parallel/test-tls-groups-cli.js
Original file line number Diff line number Diff line change
@@ -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,
});
Loading