Skip to content

Commit 7393e37

Browse files
sam-githubBethGriggs
authored andcommittedApr 15, 2019
tls: support TLSv1.3
This introduces TLS1.3 support and makes it the default max protocol, but also supports CLI/NODE_OPTIONS switches to disable it if necessary. TLS1.3 is a major update to the TLS protocol, with many security enhancements. It should be preferred over TLS1.2 whenever possible. TLS1.3 is different enough that even though the OpenSSL APIs are technically API/ABI compatible, that when TLS1.3 is negotiated, the timing of protocol records and of callbacks broke assumptions hard-coded into the 'tls' module. This change introduces no API incompatibilities when TLS1.2 is negotiated. It is the intention that it be backported to current and LTS release lines with the default maximum TLS protocol reset to 'TLSv1.2'. This will allow users of those lines to explicitly enable TLS1.3 if they want. API incompatibilities between TLS1.2 and TLS1.3 are: - Renegotiation is not supported by TLS1.3 protocol, attempts to call `.renegotiate()` will always fail. - Compiling against a system OpenSSL lower than 1.1.1 is no longer supported (OpenSSL-1.1.0 used to be supported with configure flags). - Variations of `conn.write('data'); conn.destroy()` have undefined behaviour according to the streams API. They may or may not send the 'data', and may or may not cause a ERR_STREAM_DESTROYED error to be emitted. This has always been true, but conditions under which the write suceeds is slightly but observably different when TLS1.3 is negotiated vs when TLS1.2 or below is negotiated. - If TLS1.3 is negotiated, and a server calls `conn.end()` in its 'secureConnection' listener without any data being written, the client will not receive session tickets (no 'session' events will be emitted, and `conn.getSession()` will never return a resumable session). - The return value of `conn.getSession()` API may not return a resumable session if called right after the handshake. The effect will be that clients using the legacy `getSession()` API will resume sessions if TLS1.2 is negotiated, but will do full handshakes if TLS1.3 is negotiated. See #25831 for more information. Backport-PR-URL: #26951 PR-URL: #26209 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
1 parent 8db791d commit 7393e37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1051
-206
lines changed
 

‎doc/api/cli.md

+40
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,44 @@ added: v4.0.0
443443
Specify an alternative default TLS cipher list. Requires Node.js to be built
444444
with crypto support (default).
445445

446+
### `--tls-max-v1.2`
447+
<!-- YAML
448+
added: REPLACEME
449+
-->
450+
451+
Set default [`maxVersion`][] to `'TLSv1.2'`. Use to disable support for TLSv1.3.
452+
453+
### `--tls-max-v1.3`
454+
<!-- YAML
455+
added: REPLACEME
456+
-->
457+
458+
Set default [`maxVersion`][] to `'TLSv1.3'`. Use to enable support for TLSv1.3.
459+
460+
### `--tls-min-v1.0`
461+
<!-- YAML
462+
added: REPLACEME
463+
-->
464+
465+
Set default [`minVersion`][] to `'TLSv1'`. Use for compatibility with old TLS
466+
clients or servers.
467+
468+
### `--tls-min-v1.1`
469+
<!-- YAML
470+
added: REPLACEME
471+
-->
472+
473+
Set default [`minVersion`][] to `'TLSv1.1'`. Use for compatibility with old TLS
474+
clients or servers.
475+
476+
### `--tls-min-v1.3`
477+
<!-- YAML
478+
added: REPLACEME
479+
-->
480+
481+
Set default [`minVersion`][] to `'TLSv1.3'`. Use to disable support for TLSv1.2
482+
in favour of TLSv1.3, which is more secure.
483+
446484
### `--trace-deprecation`
447485
<!-- YAML
448486
added: v0.8.0
@@ -880,6 +918,8 @@ greater than `4` (its current default value). For more information, see the
880918
[`--openssl-config`]: #cli_openssl_config_file
881919
[`Buffer`]: buffer.html#buffer_class_buffer
882920
[`SlowBuffer`]: buffer.html#buffer_class_slowbuffer
921+
[`maxVersion`]: tls.html#tls_tls_createsecurecontext_options
922+
[`minVersion`]: tls.html#tls_tls_createsecurecontext_options
883923
[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn
884924
[Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/
885925
[REPL]: repl.html

‎doc/api/tls.md

+91-28
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ not required and a default ECDHE curve will be used. The `ecdhCurve` property
104104
can be used when creating a TLS Server to specify the list of names of supported
105105
curves to use, see [`tls.createServer()`] for more info.
106106

107+
Perfect Forward Secrecy was optional up to TLSv1.2, but it is not optional for
108+
TLSv1.3, because all TLSv1.3 cipher suites use ECDHE.
109+
107110
### ALPN and SNI
108111

109112
<!-- type=misc -->
@@ -136,6 +139,8 @@ threshold is exceeded. The limits are configurable:
136139
The default renegotiation limits should not be modified without a full
137140
understanding of the implications and risks.
138141

142+
TLSv1.3 does not support renegotiation.
143+
139144
### Session Resumption
140145

141146
Establishing a TLS session can be relatively slow. The process can be sped
@@ -176,6 +181,10 @@ as for resumption with session tickets. For debugging, if
176181
[`tls.TLSSocket.getTLSTicket()`][] returns a value, the session data contains a
177182
ticket, otherwise it contains client-side session state.
178183

184+
With TLSv1.3, be aware that multiple tickets may be sent by the server,
185+
resulting in multiple `'session'` events, see [`'session'`][] for more
186+
information.
187+
179188
Single process servers need no specific implementation to use session tickets.
180189
To use session tickets across server restarts or load balancers, servers must
181190
all have the same ticket keys. There are three 16-byte keys internally, but the
@@ -230,6 +239,9 @@ Node.js is built with a default suite of enabled and disabled TLS ciphers.
230239
Currently, the default cipher suite is:
231240

232241
```txt
242+
TLS_AES_256_GCM_SHA384:
243+
TLS_CHACHA20_POLY1305_SHA256:
244+
TLS_AES_128_GCM_SHA256:
233245
ECDHE-RSA-AES128-GCM-SHA256:
234246
ECDHE-ECDSA-AES128-GCM-SHA256:
235247
ECDHE-RSA-AES256-GCM-SHA384:
@@ -270,7 +282,19 @@ The default can also be replaced on a per client or server basis using the
270282
in [`tls.createServer()`], [`tls.connect()`], and when creating new
271283
[`tls.TLSSocket`]s.
272284

273-
Consult [OpenSSL cipher list format documentation][] for details on the format.
285+
The ciphers list can contain a mixture of TLSv1.3 cipher suite names, the ones
286+
that start with `'TLS_'`, and specifications for TLSv1.2 and below cipher
287+
suites. The TLSv1.2 ciphers support a legacy specification format, consult
288+
the OpenSSL [cipher list format][] documentation for details, but those
289+
specifications do *not* apply to TLSv1.3 ciphers. The TLSv1.3 suites can only
290+
be enabled by including their full name in the cipher list. They cannot, for
291+
example, be enabled or disabled by using the legacy TLSv1.2 `'EECDH'` or
292+
`'!EECDH'` specification.
293+
294+
Despite the relative order of TLSv1.3 and TLSv1.2 cipher suites, the TLSv1.3
295+
protocol is significantly more secure than TLSv1.2, and will always be chosen
296+
over TLSv1.2 if the handshake indicates it is supported, and if any TLSv1.3
297+
cipher suites are enabled.
274298

275299
The default cipher suite included within Node.js has been carefully
276300
selected to reflect current security best practices and risk mitigation.
@@ -289,7 +313,18 @@ Old clients that rely on insecure and deprecated RC4 or DES-based ciphers
289313
(like Internet Explorer 6) cannot complete the handshaking process with
290314
the default configuration. If these clients _must_ be supported, the
291315
[TLS recommendations] may offer a compatible cipher suite. For more details
292-
on the format, see the [OpenSSL cipher list format documentation].
316+
on the format, see the OpenSSL [cipher list format][] documentation.
317+
318+
There are only 5 TLSv1.3 cipher suites:
319+
- `'TLS_AES_256_GCM_SHA384'`
320+
- `'TLS_CHACHA20_POLY1305_SHA256'`
321+
- `'TLS_AES_128_GCM_SHA256'`
322+
- `'TLS_AES_128_CCM_SHA256'`
323+
- `'TLS_AES_128_CCM_8_SHA256'`
324+
325+
The first 3 are enabled by default. The last 2 `CCM`-based suites are supported
326+
by TLSv1.3 because they may be more performant on constrained systems, but they
327+
are not enabled by default since they offer less security.
293328

294329
## Class: tls.Server
295330
<!-- YAML
@@ -634,11 +669,11 @@ On the client, the `session` can be provided to the `session` option of
634669

635670
See [Session Resumption][] for more information.
636671

637-
Note: For TLS1.2 and below, [`tls.TLSSocket.getSession()`][] can be called once
638-
the handshake is complete. For TLS1.3, only ticket based resumption is allowed
672+
Note: For TLSv1.2 and below, [`tls.TLSSocket.getSession()`][] can be called once
673+
the handshake is complete. For TLSv1.3, only ticket based resumption is allowed
639674
by the protocol, multiple tickets are sent, and the tickets aren't sent until
640675
later, after the handshake completes, so it is necessary to wait for the
641-
`'session'` event to get a resumable session. Future-proof applications are
676+
`'session'` event to get a resumable session. Applications are
642677
recommended to use the `'session'` event instead of `getSession()` to ensure
643678
they will work for all TLS protocol versions. Applications that only expect to
644679
get or use 1 session should listen for this event only once:
@@ -724,7 +759,7 @@ added: v0.11.4
724759
Returns an object representing the cipher name. The `version` key is a legacy
725760
field which always contains the value `'TLSv1/SSLv3'`.
726761

727-
For example: `{ name: 'AES256-SHA', version: 'TLSv1/SSLv3' }`.
762+
For example: `{ name: 'AES256-SHA', version: 'TLSv1.2' }`.
728763

729764
See `SSL_CIPHER_get_name()` in
730765
<https://www.openssl.org/docs/man1.1.0/ssl/SSL_CIPHER_get_name.html> for more
@@ -897,12 +932,13 @@ be returned for server sockets or disconnected client sockets.
897932

898933
Protocol versions are:
899934

935+
* `'SSLv3'`
900936
* `'TLSv1'`
901937
* `'TLSv1.1'`
902938
* `'TLSv1.2'`
903-
* `'SSLv3'`
939+
* `'TLSv1.3'`
904940

905-
See <https://www.openssl.org/docs/man1.1.0/ssl/SSL_get_version.html> for more
941+
See <https://www.openssl.org/docs/man1.1.1/man3/SSL_get_version.html> for more
906942
information.
907943

908944
### tlsSocket.getSession()
@@ -919,8 +955,8 @@ for debugging.
919955

920956
See [Session Resumption][] for more information.
921957

922-
Note: `getSession()` works only for TLS1.2 and below. Future-proof applications
923-
should use the [`'session'`][] event.
958+
Note: `getSession()` works only for TLSv1.2 and below. For TLSv1.3, applications
959+
must use the [`'session'`][] event (it also works for TLSv1.2 and below).
924960

925961
### tlsSocket.getTLSTicket()
926962
<!-- YAML
@@ -1002,8 +1038,12 @@ added: v0.11.8
10021038
verification fails; `err.code` contains the OpenSSL error code. **Default:**
10031039
`true`.
10041040
* `requestCert`
1005-
* `callback` {Function} A function that will be called when the renegotiation
1006-
request has been completed.
1041+
* `callback` {Function} If `renegotiate()` returned `true`, callback is
1042+
attached once to the `'secure'` event. If it returned `false`, it will be
1043+
called in the next tick with `ERR_TLS_RENEGOTIATE`, unless the `tlsSocket`
1044+
has been destroyed, in which case it will not be called at all.
1045+
1046+
* Returns: {boolean} `true` if renegotiation was initiated, `false` otherwise.
10071047

10081048
The `tlsSocket.renegotiate()` method initiates a TLS renegotiation process.
10091049
Upon completion, the `callback` function will be passed a single argument
@@ -1015,6 +1055,9 @@ connection has been established.
10151055
When running as the server, the socket will be destroyed with an error after
10161056
`handshakeTimeout` timeout.
10171057

1058+
For TLSv1.3, renegotiation cannot be initiated, it is not supported by the
1059+
protocol.
1060+
10181061
### tlsSocket.setMaxSendFragment(size)
10191062
<!-- YAML
10201063
added: v0.11.11
@@ -1213,6 +1256,9 @@ argument.
12131256
<!-- YAML
12141257
added: v0.11.13
12151258
changes:
1259+
- version: REPLACEME
1260+
pr-url: https://github.com/nodejs/node/pull/26209
1261+
description: TLSv1.3 support added.
12161262
- version: v11.5.0
12171263
pr-url: https://github.com/nodejs/node/pull/24733
12181264
description: The `ca:` option now supports `BEGIN TRUSTED CERTIFICATE`.
@@ -1303,13 +1349,22 @@ changes:
13031349
`object.passphrase` is optional. Encrypted keys will be decrypted with
13041350
`object.passphrase` if provided, or `options.passphrase` if it is not.
13051351
* `maxVersion` {string} Optionally set the maximum TLS version to allow. One
1306-
of `TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
1307-
`secureProtocol` option, use one or the other. **Default:** `'TLSv1.2'`.
1352+
of `TLSv1.3`, `TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified
1353+
along with the `secureProtocol` option, use one or the other.
1354+
**Default:** `'TLSv1.3'`, unless changed using CLI options. Using
1355+
`--tls-max-v1.2` sets the default to `'TLSv1.2`'. Using `--tls-max-v1.3`
1356+
sets the default to `'TLSv1.3'`. If multiple of the options are provided,
1357+
the highest maximum is used.
13081358
* `minVersion` {string} Optionally set the minimum TLS version to allow. One
1309-
of `TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
1310-
`secureProtocol` option, use one or the other. It is not recommended to use
1311-
less than TLSv1.2, but it may be required for interoperability.
1312-
**Default:** `'TLSv1'`.
1359+
of `TLSv1.3`, `TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified
1360+
along with the `secureProtocol` option, use one or the other. It is not
1361+
recommended to use less than TLSv1.2, but it may be required for
1362+
interoperability.
1363+
**Default:** `'TLSv1.2'`, unless changed using CLI options. Using
1364+
`--tls-min-v1.0` sets the default to `'TLSv1'`. Using `--tls-min-v1.1` sets
1365+
the default to `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to
1366+
`'TLSv1.3'`. If multiple of the options are provided, the lowest minimum is
1367+
used.
13131368
* `passphrase` {string} Shared passphrase used for a single private key and/or
13141369
a PFX.
13151370
* `pfx` {string|string[]|Buffer|Buffer[]|Object[]} PFX or PKCS12 encoded
@@ -1325,12 +1380,15 @@ changes:
13251380
which is not usually necessary. This should be used carefully if at all!
13261381
Value is a numeric bitmask of the `SSL_OP_*` options from
13271382
[OpenSSL Options][].
1328-
* `secureProtocol` {string} The TLS protocol version to use. The possible
1329-
values are listed as [SSL_METHODS][], use the function names as strings. For
1330-
example, use `'TLSv1_1_method'` to force TLS version 1.1, or `'TLS_method'`
1331-
to allow any TLS protocol version. It is not recommended to use TLS versions
1332-
less than 1.2, but it may be required for interoperability. **Default:**
1333-
none, see `minVersion`.
1383+
* `secureProtocol` {string} Legacy mechanism to select the TLS protocol
1384+
version to use, it does not support independent control of the minimum and
1385+
maximum version, and does not support limiting the protocol to TLSv1.3. Use
1386+
`minVersion` and `maxVersion` instead. The possible values are listed as
1387+
[SSL_METHODS][], use the function names as strings. For example, use
1388+
`'TLSv1_1_method'` to force TLS version 1.1, or `'TLS_method'` to allow any
1389+
TLS protocol version up to TLSv1.3. It is not recommended to use TLS
1390+
versions less than 1.2, but it may be required for interoperability.
1391+
**Default:** none, see `minVersion`.
13341392
* `sessionIdContext` {string} Opaque identifier used by servers to ensure
13351393
session state is not shared between applications. Unused by clients.
13361394

@@ -1450,10 +1508,15 @@ added: v0.10.2
14501508

14511509
* Returns: {string[]}
14521510

1453-
Returns an array with the names of the supported SSL ciphers.
1511+
Returns an array with the names of the supported TLS ciphers. The names are
1512+
lower-case for historical reasons, but must be uppercased to be used in
1513+
the `ciphers` option of [`tls.createSecureContext()`][].
1514+
1515+
Cipher names that start with `'tls_'` are for TLSv1.3, all the others are for
1516+
TLSv1.2 and below.
14541517

14551518
```js
1456-
console.log(tls.getCiphers()); // ['AES128-SHA', 'AES256-SHA', ...]
1519+
console.log(tls.getCiphers()); // ['aes128-gcm-sha256', 'aes128-sha', ...]
14571520
```
14581521

14591522
## tls.DEFAULT_ECDH_CURVE
@@ -1613,16 +1676,16 @@ where `secureSocket` has the same API as `pair.cleartext`.
16131676
[Forward secrecy]: https://en.wikipedia.org/wiki/Perfect_forward_secrecy
16141677
[OCSP request]: https://en.wikipedia.org/wiki/OCSP_stapling
16151678
[OpenSSL Options]: crypto.html#crypto_openssl_options
1616-
[OpenSSL cipher list format documentation]: https://www.openssl.org/docs/man1.1.0/apps/ciphers.html#CIPHER-LIST-FORMAT
16171679
[Perfect Forward Secrecy]: #tls_perfect_forward_secrecy
16181680
[RFC 2246]: https://www.ietf.org/rfc/rfc2246.txt
16191681
[RFC 5077]: https://tools.ietf.org/html/rfc5077
16201682
[RFC 5929]: https://tools.ietf.org/html/rfc5929
1621-
[SSL_METHODS]: https://www.openssl.org/docs/man1.1.0/ssl/ssl.html#Dealing-with-Protocol-Methods
1683+
[SSL_METHODS]: https://www.openssl.org/docs/man1.1.1/man7/ssl.html#Dealing-with-Protocol-Methods
16221684
[Session Resumption]: #tls_session_resumption
16231685
[Stream]: stream.html#stream_stream
16241686
[TLS recommendations]: https://wiki.mozilla.org/Security/Server_Side_TLS
16251687
[asn1.js]: https://www.npmjs.com/package/asn1.js
16261688
[certificate object]: #tls_certificate_object
1689+
[cipher list format]: https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT
16271690
[modifying the default cipher suite]: #tls_modifying_the_default_tls_cipher_suite
16281691
[specific attacks affecting larger AES key sizes]: https://www.schneier.com/blog/archives/2009/07/another_new_aes.html

0 commit comments

Comments
 (0)
Please sign in to comment.