| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8db791d commit 7393e37
57 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -443,6 +443,44 @@ added: v4.0.0 | |||
| 443 | 443 | Specify an alternative default TLS cipher list. Requires Node.js to be built | |
| 444 | 444 | with crypto support (default). | |
| 445 | 445 | ||
| 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 | + | ||
| 446 | 484 | ### `--trace-deprecation` | |
| 447 | 485 | <!-- YAML | |
| 448 | 486 | added: v0.8.0 | |
@@ -880,6 +918,8 @@ greater than `4` (its current default value). For more information, see the | |||
| 880 | 918 | [`--openssl-config`]: #cli_openssl_config_file | |
| 881 | 919 | [`Buffer`]: buffer.html#buffer_class_buffer | |
| 882 | 920 | [`SlowBuffer`]: buffer.html#buffer_class_slowbuffer | |
| 921 | + [`maxVersion`]: tls.html#tls_tls_createsecurecontext_options | ||
| 922 | + [`minVersion`]: tls.html#tls_tls_createsecurecontext_options | ||
| 883 | 923 | [`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn | |
| 884 | 924 | [Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/ | |
| 885 | 925 | [REPL]: repl.html | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,6 +104,9 @@ not required and a default ECDHE curve will be used. The `ecdhCurve` property | |||
| 104 | 104 | can be used when creating a TLS Server to specify the list of names of supported | |
| 105 | 105 | curves to use, see [`tls.createServer()`] for more info. | |
| 106 | 106 | ||
| 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 | + | ||
| 107 | 110 | ### ALPN and SNI | |
| 108 | 111 | ||
| 109 | 112 | <!-- type=misc --> | |
@@ -136,6 +139,8 @@ threshold is exceeded. The limits are configurable: | |||
| 136 | 139 | The default renegotiation limits should not be modified without a full | |
| 137 | 140 | understanding of the implications and risks. | |
| 138 | 141 | ||
| 142 | + TLSv1.3 does not support renegotiation. | ||
| 143 | + | ||
| 139 | 144 | ### Session Resumption | |
| 140 | 145 | ||
| 141 | 146 | 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 | |||
| 176 | 181 | [`tls.TLSSocket.getTLSTicket()`][] returns a value, the session data contains a | |
| 177 | 182 | ticket, otherwise it contains client-side session state. | |
| 178 | 183 | ||
| 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 | + | ||
| 179 | 188 | Single process servers need no specific implementation to use session tickets. | |
| 180 | 189 | To use session tickets across server restarts or load balancers, servers must | |
| 181 | 190 | 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. | |||
| 230 | 239 | Currently, the default cipher suite is: | |
| 231 | 240 | ||
| 232 | 241 | ```txt | |
| 242 | + TLS_AES_256_GCM_SHA384: | ||
| 243 | + TLS_CHACHA20_POLY1305_SHA256: | ||
| 244 | + TLS_AES_128_GCM_SHA256: | ||
| 233 | 245 | ECDHE-RSA-AES128-GCM-SHA256: | |
| 234 | 246 | ECDHE-ECDSA-AES128-GCM-SHA256: | |
| 235 | 247 | ECDHE-RSA-AES256-GCM-SHA384: | |
@@ -270,7 +282,19 @@ The default can also be replaced on a per client or server basis using the | |||
| 270 | 282 | in [`tls.createServer()`], [`tls.connect()`], and when creating new | |
| 271 | 283 | [`tls.TLSSocket`]s. | |
| 272 | 284 | ||
| 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. | ||
| 274 | 298 | ||
| 275 | 299 | The default cipher suite included within Node.js has been carefully | |
| 276 | 300 | 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 | |||
| 289 | 313 | (like Internet Explorer 6) cannot complete the handshaking process with | |
| 290 | 314 | the default configuration. If these clients _must_ be supported, the | |
| 291 | 315 | [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. | ||
| 293 | 328 | ||
| 294 | 329 | ## Class: tls.Server | |
| 295 | 330 | <!-- YAML | |
@@ -634,11 +669,11 @@ On the client, the `session` can be provided to the `session` option of | |||
| 634 | 669 | ||
| 635 | 670 | See [Session Resumption][] for more information. | |
| 636 | 671 | ||
| 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 | ||
| 639 | 674 | by the protocol, multiple tickets are sent, and the tickets aren't sent until | |
| 640 | 675 | 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 | ||
| 642 | 677 | recommended to use the `'session'` event instead of `getSession()` to ensure | |
| 643 | 678 | they will work for all TLS protocol versions. Applications that only expect to | |
| 644 | 679 | get or use 1 session should listen for this event only once: | |
@@ -724,7 +759,7 @@ added: v0.11.4 | |||
| 724 | 759 | Returns an object representing the cipher name. The `version` key is a legacy | |
| 725 | 760 | field which always contains the value `'TLSv1/SSLv3'`. | |
| 726 | 761 | ||
| 727 | - For example: `{ name: 'AES256-SHA', version: 'TLSv1/SSLv3' }`. | ||
| 762 | + For example: `{ name: 'AES256-SHA', version: 'TLSv1.2' }`. | ||
| 728 | 763 | ||
| 729 | 764 | See `SSL_CIPHER_get_name()` in | |
| 730 | 765 | <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. | |||
| 897 | 932 | ||
| 898 | 933 | Protocol versions are: | |
| 899 | 934 | ||
| 935 | + * `'SSLv3'` | ||
| 900 | 936 | * `'TLSv1'` | |
| 901 | 937 | * `'TLSv1.1'` | |
| 902 | 938 | * `'TLSv1.2'` | |
| 903 | - * `'SSLv3'` | ||
| 939 | + * `'TLSv1.3'` | ||
| 904 | 940 | ||
| 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 | ||
| 906 | 942 | information. | |
| 907 | 943 | ||
| 908 | 944 | ### tlsSocket.getSession() | |
@@ -919,8 +955,8 @@ for debugging. | |||
| 919 | 955 | ||
| 920 | 956 | See [Session Resumption][] for more information. | |
| 921 | 957 | ||
| 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). | ||
| 924 | 960 | ||
| 925 | 961 | ### tlsSocket.getTLSTicket() | |
| 926 | 962 | <!-- YAML | |
@@ -1002,8 +1038,12 @@ added: v0.11.8 | |||
| 1002 | 1038 | verification fails; `err.code` contains the OpenSSL error code. **Default:** | |
| 1003 | 1039 | `true`. | |
| 1004 | 1040 | * `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. | ||
| 1007 | 1047 | ||
| 1008 | 1048 | The `tlsSocket.renegotiate()` method initiates a TLS renegotiation process. | |
| 1009 | 1049 | Upon completion, the `callback` function will be passed a single argument | |
@@ -1015,6 +1055,9 @@ connection has been established. | |||
| 1015 | 1055 | When running as the server, the socket will be destroyed with an error after | |
| 1016 | 1056 | `handshakeTimeout` timeout. | |
| 1017 | 1057 | ||
| 1058 | + For TLSv1.3, renegotiation cannot be initiated, it is not supported by the | ||
| 1059 | + protocol. | ||
| 1060 | + | ||
| 1018 | 1061 | ### tlsSocket.setMaxSendFragment(size) | |
| 1019 | 1062 | <!-- YAML | |
| 1020 | 1063 | added: v0.11.11 | |
@@ -1213,6 +1256,9 @@ argument. | |||
| 1213 | 1256 | <!-- YAML | |
| 1214 | 1257 | added: v0.11.13 | |
| 1215 | 1258 | changes: | |
| 1259 | + - version: REPLACEME | ||
| 1260 | + pr-url: https://github.com/nodejs/node/pull/26209 | ||
| 1261 | + description: TLSv1.3 support added. | ||
| 1216 | 1262 | - version: v11.5.0 | |
| 1217 | 1263 | pr-url: https://github.com/nodejs/node/pull/24733 | |
| 1218 | 1264 | description: The `ca:` option now supports `BEGIN TRUSTED CERTIFICATE`. | |
@@ -1303,13 +1349,22 @@ changes: | |||
| 1303 | 1349 | `object.passphrase` is optional. Encrypted keys will be decrypted with | |
| 1304 | 1350 | `object.passphrase` if provided, or `options.passphrase` if it is not. | |
| 1305 | 1351 | * `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. | ||
| 1308 | 1358 | * `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. | ||
| 1313 | 1368 | * `passphrase` {string} Shared passphrase used for a single private key and/or | |
| 1314 | 1369 | a PFX. | |
| 1315 | 1370 | * `pfx` {string|string[]|Buffer|Buffer[]|Object[]} PFX or PKCS12 encoded | |
@@ -1325,12 +1380,15 @@ changes: | |||
| 1325 | 1380 | which is not usually necessary. This should be used carefully if at all! | |
| 1326 | 1381 | Value is a numeric bitmask of the `SSL_OP_*` options from | |
| 1327 | 1382 | [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`. | ||
| 1334 | 1392 | * `sessionIdContext` {string} Opaque identifier used by servers to ensure | |
| 1335 | 1393 | session state is not shared between applications. Unused by clients. | |
| 1336 | 1394 | ||
@@ -1450,10 +1508,15 @@ added: v0.10.2 | |||
| 1450 | 1508 | ||
| 1451 | 1509 | * Returns: {string[]} | |
| 1452 | 1510 | ||
| 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. | ||
| 1454 | 1517 | ||
| 1455 | 1518 | ```js | |
| 1456 | - console.log(tls.getCiphers()); // ['AES128-SHA', 'AES256-SHA', ...] | ||
| 1519 | + console.log(tls.getCiphers()); // ['aes128-gcm-sha256', 'aes128-sha', ...] | ||
| 1457 | 1520 | ``` | |
| 1458 | 1521 | ||
| 1459 | 1522 | ## tls.DEFAULT_ECDH_CURVE | |
@@ -1613,16 +1676,16 @@ where `secureSocket` has the same API as `pair.cleartext`. | |||
| 1613 | 1676 | [Forward secrecy]: https://en.wikipedia.org/wiki/Perfect_forward_secrecy | |
| 1614 | 1677 | [OCSP request]: https://en.wikipedia.org/wiki/OCSP_stapling | |
| 1615 | 1678 | [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 | ||
| 1617 | 1679 | [Perfect Forward Secrecy]: #tls_perfect_forward_secrecy | |
| 1618 | 1680 | [RFC 2246]: https://www.ietf.org/rfc/rfc2246.txt | |
| 1619 | 1681 | [RFC 5077]: https://tools.ietf.org/html/rfc5077 | |
| 1620 | 1682 | [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 | ||
| 1622 | 1684 | [Session Resumption]: #tls_session_resumption | |
| 1623 | 1685 | [Stream]: stream.html#stream_stream | |
| 1624 | 1686 | [TLS recommendations]: https://wiki.mozilla.org/Security/Server_Side_TLS | |
| 1625 | 1687 | [asn1.js]: https://www.npmjs.com/package/asn1.js | |
| 1626 | 1688 | [certificate object]: #tls_certificate_object | |
| 1689 | + [cipher list format]: https://www.openssl.org/docs/man1.1.1/man1/ciphers.html#CIPHER-LIST-FORMAT | ||
| 1627 | 1690 | [modifying the default cipher suite]: #tls_modifying_the_default_tls_cipher_suite | |
| 1628 | 1691 | [specific attacks affecting larger AES key sizes]: https://www.schneier.com/blog/archives/2009/07/another_new_aes.html | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,6 +236,24 @@ Specify process.title on startup. | |||
| 236 | 236 | Specify an alternative default TLS cipher list. | |
| 237 | 237 | Requires Node.js to be built with crypto support. (Default) | |
| 238 | 238 | . | |
| 239 | + .It Fl -tls-max-v1.2 | ||
| 240 | + Set default maxVersion to 'TLSv1.2'. Use to disable support for TLSv1.3. | ||
| 241 | + . | ||
| 242 | + .It Fl -tls-max-v1.3 | ||
| 243 | + Set default maxVersion to 'TLSv1.3'. Use to enable support for TLSv1.3. | ||
| 244 | + . | ||
| 245 | + .It Fl -tls-min-v1.0 | ||
| 246 | + Set default minVersion to 'TLSv1'. Use for compatibility with old TLS clients | ||
| 247 | + or servers. | ||
| 248 | + . | ||
| 249 | + .It Fl -tls-min-v1.1 | ||
| 250 | + Set default minVersion to 'TLSv1.1'. Use for compatibility with old TLS clients | ||
| 251 | + or servers. | ||
| 252 | + . | ||
| 253 | + .It Fl -tls-min-v1.3 | ||
| 254 | + Set default minVersion to 'TLSv1.3'. Use to disable support for TLSv1.2 in | ||
| 255 | + favour of TLSv1.3, which is more secure. | ||
| 256 | + . | ||
| 239 | 257 | .It Fl -trace-deprecation | |
| 240 | 258 | Print stack traces for deprecations. | |
| 241 | 259 | . | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ const tls = require('tls'); | |||
| 27 | 27 | const { | |
| 28 | 28 | ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED, | |
| 29 | 29 | ERR_INVALID_ARG_TYPE, | |
| 30 | + ERR_INVALID_OPT_VALUE, | ||
| 30 | 31 | ERR_TLS_INVALID_PROTOCOL_VERSION, | |
| 31 | 32 | ERR_TLS_PROTOCOL_VERSION_CONFLICT, | |
| 32 | 33 | } = require('internal/errors').codes; | |
@@ -35,6 +36,7 @@ const { | |||
| 35 | 36 | TLS1_VERSION, | |
| 36 | 37 | TLS1_1_VERSION, | |
| 37 | 38 | TLS1_2_VERSION, | |
| 39 | + TLS1_3_VERSION, | ||
| 38 | 40 | } = internalBinding('constants').crypto; | |
| 39 | 41 | ||
| 40 | 42 | // Lazily loaded from internal/crypto/util. | |
@@ -45,6 +47,7 @@ function toV(which, v, def) { | |||
| 45 | 47 | if (v === 'TLSv1') return TLS1_VERSION; | |
| 46 | 48 | if (v === 'TLSv1.1') return TLS1_1_VERSION; | |
| 47 | 49 | if (v === 'TLSv1.2') return TLS1_2_VERSION; | |
| 50 | + if (v === 'TLSv1.3') return TLS1_3_VERSION; | ||
| 48 | 51 | throw new ERR_TLS_INVALID_PROTOCOL_VERSION(v, which); | |
| 49 | 52 | } | |
| 50 | 53 | ||
@@ -156,10 +159,35 @@ exports.createSecureContext = function createSecureContext(options, context) { | |||
| 156 | 159 | } | |
| 157 | 160 | } | |
| 158 | 161 | ||
| 159 | - if (options.ciphers) | ||
| 160 | - c.context.setCiphers(options.ciphers); | ||
| 161 | - else | ||
| 162 | - c.context.setCiphers(tls.DEFAULT_CIPHERS); | ||
| 162 | + if (options.ciphers && typeof options.ciphers !== 'string') { | ||
| 163 | + throw new ERR_INVALID_ARG_TYPE( | ||
| 164 | + 'options.ciphers', 'string', options.ciphers); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + // Work around an OpenSSL API quirk. cipherList is for TLSv1.2 and below, | ||
| 168 | + // cipherSuites is for TLSv1.3 (and presumably any later versions). TLSv1.3 | ||
| 169 | + // cipher suites all have a standard name format beginning with TLS_, so split | ||
| 170 | + // the ciphers and pass them to the appropriate API. | ||
| 171 | + const ciphers = (options.ciphers || tls.DEFAULT_CIPHERS).split(':'); | ||
| 172 | + const cipherList = ciphers.filter((_) => !_.match(/^TLS_/)).join(':'); | ||
| 173 | + const cipherSuites = ciphers.filter((_) => _.match(/^TLS_/)).join(':'); | ||
| 174 | + | ||
| 175 | + if (cipherSuites === '' && cipherList === '') { | ||
| 176 | + // Specifying empty cipher suites for both TLS1.2 and TLS1.3 is invalid, its | ||
| 177 | + // not possible to handshake with no suites. | ||
| 178 | + throw ERR_INVALID_OPT_VALUE('ciphers', ciphers); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + c.context.setCipherSuites(cipherSuites); | ||
| 182 | + c.context.setCiphers(cipherList); | ||
| 183 | + | ||
| 184 | + if (cipherSuites === '' && c.context.getMaxProto() > TLS1_2_VERSION && | ||
| 185 | + c.context.getMinProto() < TLS1_3_VERSION) | ||
| 186 | + c.context.setMaxProto(TLS1_2_VERSION); | ||
| 187 | + | ||
| 188 | + if (cipherList === '' && c.context.getMinProto() < TLS1_3_VERSION && | ||
| 189 | + c.context.getMaxProto() > TLS1_2_VERSION) | ||
| 190 | + c.context.setMinProto(TLS1_3_VERSION); | ||
| 163 | 191 | ||
| 164 | 192 | if (options.ecdhCurve === undefined) | |
| 165 | 193 | c.context.setECDHCurve(tls.DEFAULT_ECDH_CURVE); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments