Skip to content

Commit 60eca6a

Browse files
bnoordhuisaddaleax
authored andcommitted
tls: disable TLS v1.0 and v1.1 by default
Refs: https://blog.mozilla.org/security/2018/10/15/removing-old-versions-of-tls/ PR-URL: #23814 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent fcd7a72 commit 60eca6a

11 files changed

+57
-5
lines changed

doc/api/cli.md

+16
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,22 @@ added: v4.0.0
342342
Specify an alternative default TLS cipher list. Requires Node.js to be built
343343
with crypto support (default).
344344

345+
### `--tls-v1.0`
346+
<!-- YAML
347+
added: REPLACEME
348+
-->
349+
350+
Enable TLSv1.0. This should only be used for compatibility with old TLS
351+
clients or servers.
352+
353+
### `--tls-v1.1`
354+
<!-- YAML
355+
added: REPLACEME
356+
-->
357+
358+
Enable TLSv1.1. This should only be used for compatibility with old TLS
359+
clients or servers.
360+
345361
### `--trace-deprecation`
346362
<!-- YAML
347363
added: v0.8.0

doc/api/tls.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,8 @@ changes:
11021102
[OpenSSL Options][].
11031103
* `secureProtocol` {string} SSL method to use. The possible values are listed
11041104
as [SSL_METHODS][], use the function names as strings. For example,
1105-
`'TLSv1_2_method'` to force TLS version 1.2. **Default:** `'TLS_method'`.
1105+
`'TLSv1_2_method'` to force TLS version 1.2.
1106+
**Default:** `'TLSv1_2_method'`.
11061107
* `sessionIdContext` {string} Opaque identifier used by servers to ensure
11071108
session state is not shared between applications. Unused by clients.
11081109

doc/node.1

+8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ Specify process.title on startup.
183183
Specify an alternative default TLS cipher list.
184184
Requires Node.js to be built with crypto support. (Default)
185185
.
186+
.It Fl -tls-v1.0
187+
Enable TLSv1.0. This should only be used for compatibility with old TLS
188+
clients or servers.
189+
.
190+
.It Fl -tls-v1.1
191+
Enable TLSv1.1. This should only be used for compatibility with old TLS
192+
clients or servers.
193+
.
186194
.It Fl -trace-deprecation
187195
Print stack traces for deprecations.
188196
.

src/node_crypto.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,13 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
396396
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
397397
Environment* env = sc->env();
398398

399-
int min_version = 0;
399+
int min_version = TLS1_2_VERSION;
400400
int max_version = 0;
401401
const SSL_METHOD* method = TLS_method();
402402

403+
if (env->options()->tls_v1_1) min_version = TLS1_1_VERSION;
404+
if (env->options()->tls_v1_0) min_version = TLS1_VERSION;
405+
403406
if (args.Length() == 1 && args[0]->IsString()) {
404407
const node::Utf8Value sslmethod(env->isolate(), args[0]);
405408

@@ -425,6 +428,9 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
425428
method = TLS_server_method();
426429
} else if (strcmp(*sslmethod, "SSLv23_client_method") == 0) {
427430
method = TLS_client_method();
431+
} else if (strcmp(*sslmethod, "TLS_method") == 0) {
432+
min_version = 0;
433+
max_version = 0;
428434
} else if (strcmp(*sslmethod, "TLSv1_method") == 0) {
429435
min_version = TLS1_VERSION;
430436
max_version = TLS1_VERSION;

src/node_options.cc

+11
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
189189

190190
AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvironment);
191191

192+
#if HAVE_OPENSSL
193+
AddOption("--tls-v1.0",
194+
"enable TLSv1.0",
195+
&EnvironmentOptions::tls_v1_0,
196+
kAllowedInEnvironment);
197+
AddOption("--tls-v1.1",
198+
"enable TLSv1.1",
199+
&EnvironmentOptions::tls_v1_1,
200+
kAllowedInEnvironment);
201+
#endif
202+
192203
Insert(&DebugOptionsParser::instance,
193204
&EnvironmentOptions::get_debug_options);
194205
}

src/node_options.h

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ class EnvironmentOptions : public Options {
9292
bool print_eval = false;
9393
bool force_repl = false;
9494

95+
#if HAVE_OPENSSL
96+
bool tls_v1_0 = false;
97+
bool tls_v1_1 = false;
98+
#endif
99+
95100
std::vector<std::string> preload_modules;
96101

97102
std::vector<std::string> user_argv;

test/parallel/test-https-agent-additional-options.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --tls-v1.1
12
'use strict';
23
const common = require('../common');
34
if (!common.hasCrypto)
@@ -34,7 +35,7 @@ const updatedValues = new Map([
3435
['ecdhCurve', 'secp384r1'],
3536
['honorCipherOrder', true],
3637
['secureOptions', crypto.constants.SSL_OP_CIPHER_SERVER_PREFERENCE],
37-
['secureProtocol', 'TLSv1_method'],
38+
['secureProtocol', 'TLSv1_1_method'],
3839
['sessionIdContext', 'sessionIdContext'],
3940
]);
4041

test/parallel/test-https-agent-session-eviction.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --tls-v1.0
12
'use strict';
23

34
const common = require('../common');

test/parallel/test-process-env-allowed-flags.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ require('../common');
5151
// assert all "canonical" flags begin with dash(es)
5252
{
5353
process.allowedNodeEnvironmentFlags.forEach((flag) => {
54-
assert(/^--?[a-z8_-]+$/.test(flag), `Unexpected format for flag ${flag}`);
54+
assert(/^--?[a-z0-9._-]+$/.test(flag),
55+
`Unexpected format for flag ${flag}`);
5556
});
5657
}
5758

test/parallel/test-tls-getprotocol.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const clientConfigs = [
1717
];
1818

1919
const serverConfig = {
20+
secureProtocol: 'TLS_method',
2021
key: fixtures.readSync('/keys/agent2-key.pem'),
2122
cert: fixtures.readSync('/keys/agent2-cert.pem')
2223
};

test/parallel/test-tls-session-cache.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function doTest(testOptions, callback) {
4848
cert,
4949
ca: [cert],
5050
requestCert: true,
51-
rejectUnauthorized: false
51+
rejectUnauthorized: false,
52+
secureProtocol: 'TLS_method',
5253
};
5354
let requestCount = 0;
5455
let resumeCount = 0;

0 commit comments

Comments
 (0)