Skip to content

Commit 66b97e6

Browse files
pimterryaduh95
authored andcommitted
tls: docs-deprecate TLS renegotiation, add allowRenegotiation opt-in
For now this changes very little, but offers an option to directly control whether this is supported. In future, this will default to 'false' (disabling by default) and eventually be mostly removed, except opt-in client support for accepting renegotiation requests from servers. Signed-off-by: Tim Perry <pimterry@gmail.com> PR-URL: #67532 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 7f45cb7 commit 66b97e6

12 files changed

Lines changed: 441 additions & 7 deletions

‎doc/api/deprecations.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4861,6 +4861,55 @@ Type: Documentation-only
48614861
`node:util`'s `util.TextDecoder` and `util.TextEncoder` are deprecated.
48624862
Use global `TextDecoder` and `TextEncoder` instead.
48634863
4864+
### DEP0213: TLS renegotiation
4865+
4866+
<!-- YAML
4867+
changes:
4868+
- version: REPLACEME
4869+
pr-url: https://github.com/nodejs/node/pull/67532
4870+
description: Documentation-only deprecation
4871+
with `--pending-deprecation` support.
4872+
-->
4873+
4874+
Type: Documentation-only (supports [`--pending-deprecation`][])
4875+
4876+
TLS renegotiation is deprecated and will be disabled by default in future.
4877+
This functionality will be largely removed in a subsequent release. Only a
4878+
client accepting server-initiated renegotiation requests is expected to
4879+
remain supported, and on an opt-in basis for legacy server compatibility.
4880+
4881+
This only affects TLS 1.2. TLS 1.3 removed renegotiation from the standard,
4882+
and so this has never been supported.
4883+
4884+
Avoid using TLS renegotiation. A server that needs a client certificate should
4885+
request it in the initial configuration, with the `requestCert` option of
4886+
[`tls.createServer()`][]. A client that needs to change the configuration of
4887+
an existing connection should create a new connection.
4888+
4889+
This affects multiple TLS APIs:
4890+
4891+
* Node.js TLS clients needing to initiate renegotiation locally, or accept
4892+
renegotiation requested by the server, should opt in by setting the
4893+
`allowRenegotiation` option of [`tls.connect()`][].
4894+
* Node.js TLS servers needing to initiate renegotiation locally, or accept
4895+
renegotiation requested by the client, should opt in by setting the
4896+
`allowRenegotiation` option of [`tls.createServer()`][].
4897+
If renegotiation by clients is removed in future, setting this option to
4898+
`true` on a server will throw an error.
4899+
* In either case, initiating renegotiation ([`tlsSocket.renegotiate()`][])
4900+
should be avoided by using alternative mechanisms. When renegotiation is
4901+
disabled by default this method will only work on connections created
4902+
with the `allowRenegotiation` option, and will throw an error if not.
4903+
If initiating renegotiation is removed in future, this method will throw
4904+
an error.
4905+
* Using [`tlsSocket.disableRenegotiation()`][] to disable renegotiation will
4906+
no longer be necessary when it is disabled by default. This will become a
4907+
no-op in most configurations.
4908+
* The `tls.CLIENT_RENEG_LIMIT` and `tls.CLIENT_RENEG_WINDOW` properties which
4909+
limit renegotiation will become unused in default configurations.
4910+
If renegotiation by clients is removed in future these are likely to be
4911+
removed.
4912+
48644913
[DEP0142]: #dep0142-repl_builtinlibs
48654914
[DEP0156]: #dep0156-aborted-property-and-abort-aborted-event-in-http
48664915
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
@@ -4985,8 +5034,11 @@ Use global `TextDecoder` and `TextEncoder` instead.
49855034
[`tls.SecureContext`]: tls.md#tlscreatesecurecontextoptions
49865035
[`tls.TLSSocket`]: tls.md#class-tlstlssocket
49875036
[`tls.checkServerIdentity()`]: tls.md#tlscheckserveridentityhostname-cert
5037+
[`tls.connect()`]: tls.md#tlsconnectoptions-callback
49885038
[`tls.createSecureContext()`]: tls.md#tlscreatesecurecontextoptions
49895039
[`tls.createServer()`]: tls.md#tlscreateserveroptions-secureconnectionlistener
5040+
[`tlsSocket.disableRenegotiation()`]: tls.md#tlssocketdisablerenegotiation
5041+
[`tlsSocket.renegotiate()`]: tls.md#tlssocketrenegotiateoptions-callback
49905042
[`url.format()`]: url.md#urlformaturlobject
49915043
[`url.format(urlString)`]: url.md#urlformaturlstring
49925044
[`url.parse()`]: url.md#urlparseurlstring-parsequerystring-slashesdenotehost

‎doc/api/errors.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3366,8 +3366,8 @@ disabled.
33663366

33673367
### `ERR_TLS_RENEGOTIATION_UNSUPPORTED`
33683368

3369-
An attempt was made to renegotiate TLS, but the TLS implementation does not
3370-
support caller-initiated renegotiation.
3369+
An attempt was made to renegotiate TLS, or to allow renegotiation on a server,
3370+
but the TLS implementation does not support it.
33713371

33723372
<a id="ERR_TLS_REQUIRED_SERVER_NAME"></a>
33733373

‎doc/api/https.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ Makes a request to a secure web server.
474474
The following additional `options` from [`tls.connect()`][] are also accepted:
475475
`ca`, `cert`, `ciphers`, `crl`, `dhparam`, `ecdhCurve`, `honorCipherOrder`,
476476
`key`, `passphrase`, `pfx`, `rejectUnauthorized`, `secureOptions`,
477-
`secureProtocol`, `servername`, `sessionIdContext`, `highWaterMark`.
477+
`secureProtocol`, `servername`, `sessionIdContext`, `highWaterMark`,
478+
`allowRenegotiation`.
478479

479480
`options` can be an object, a string, or a [`URL`][] object. If `options` is a
480481
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][]

‎doc/api/tls.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ understanding of the implications and risks.
235235

236236
TLSv1.3 does not support renegotiation.
237237

238+
Renegotiation is deprecated (see [DEP0213][]). A future version of Node.js will
239+
disable it by default, for servers and clients. The `allowRenegotiation` option
240+
of [`tls.createServer()`][] and [`tls.connect()`][] can be set to `false` to
241+
disable it now, or to `true` to keep it enabled when that default changes.
242+
238243
### Session resumption
239244

240245
Establishing a TLS session can be relatively slow. The process can be sped
@@ -901,6 +906,9 @@ connection is open.
901906
<!-- YAML
902907
added: v0.11.4
903908
changes:
909+
- version: REPLACEME
910+
pr-url: https://github.com/nodejs/node/pull/67532
911+
description: The `allowRenegotiation` option is now supported.
904912
- version: v12.2.0
905913
pr-url: https://github.com/nodejs/node/pull/27497
906914
description: The `enableTrace` option is now supported.
@@ -927,6 +935,7 @@ changes:
927935
* `ALPNProtocols`: See [`tls.createServer()`][]
928936
* `SNICallback`: See [`tls.createServer()`][]
929937
* `ALPNCallback`: See [`tls.createServer()`][]
938+
* `allowRenegotiation`: See [`tls.createServer()`][]
930939
* `session` {Buffer} A `Buffer` instance containing a TLS session.
931940
* `requestOCSP` {boolean} If `true`, specifies that the OCSP status request
932941
extension will be added to the client hello and an `'OCSPResponse'` event
@@ -1119,11 +1128,18 @@ certificate at all.
11191128

11201129
<!-- YAML
11211130
added: v8.4.0
1131+
deprecated: REPLACEME
11221132
-->
11231133

1134+
> Stability: 0 - Deprecated. See [DEP0213][].
1135+
11241136
Disables TLS renegotiation for this `TLSSocket` instance. Once called, attempts
11251137
to renegotiate will trigger an `'error'` event on the `TLSSocket`.
11261138

1139+
Set `allowRenegotiation: false` when creating the server or connection
1140+
instead. This method has no effect on a connection created that way, where the
1141+
peer's attempts to renegotiate are refused without an error.
1142+
11271143
### `tlsSocket.enableTrace()`
11281144

11291145
<!-- YAML
@@ -1586,6 +1602,7 @@ Returns the numeric representation of the remote port. For example, `443`.
15861602

15871603
<!-- YAML
15881604
added: v0.11.8
1605+
deprecated: REPLACEME
15891606
changes:
15901607
- version: v18.0.0
15911608
pr-url: https://github.com/nodejs/node/pull/41678
@@ -1594,6 +1611,8 @@ changes:
15941611
`ERR_INVALID_CALLBACK`.
15951612
-->
15961613

1614+
> Stability: 0 - Deprecated. See [DEP0213][].
1615+
15971616
* `options` {Object}
15981617
* `rejectUnauthorized` {boolean} If not `false`, the server certificate is
15991618
verified against the list of supplied CAs. An `'error'` event is emitted if
@@ -1622,6 +1641,12 @@ When running as the server, the socket will be destroyed with an error after
16221641
For TLSv1.3, renegotiation cannot be initiated, it is not supported by the
16231642
protocol.
16241643

1644+
If the connection was created with `allowRenegotiation: false`, this method
1645+
returns `false` and `callback` is called with an
1646+
[`ERR_TLS_RENEGOTIATION_DISABLED`][] error. A future version of Node.js will
1647+
disable renegotiation by default, and this method will then only work on
1648+
connections created with `allowRenegotiation: true`.
1649+
16251650
### `tlsSocket.servername`
16261651

16271652
<!-- YAML
@@ -1740,6 +1765,9 @@ was present (see [CVE-2021-44531][]). Applications that wish to accept
17401765
<!-- YAML
17411766
added: v0.11.3
17421767
changes:
1768+
- version: REPLACEME
1769+
pr-url: https://github.com/nodejs/node/pull/67532
1770+
description: The `allowRenegotiation` option is now supported.
17431771
- version:
17441772
- v15.1.0
17451773
- v14.18.0
@@ -1837,6 +1865,9 @@ changes:
18371865
TLS connection. When a server offers a DH parameter with a size less
18381866
than `minDHSize`, the TLS connection is destroyed and an error is thrown.
18391867
**Default:** `1024`.
1868+
* `allowRenegotiation` {boolean} If `true`, the client accepts renegotiation
1869+
requested by the server. A future version of Node.js will change this default
1870+
to `false` (see [DEP0213][]). **Default:** `true`.
18401871
* `highWaterMark` {number} Consistent with the readable stream `highWaterMark` parameter.
18411872
**Default:** `16 * 1024`.
18421873
* `timeout`: {number} If set and if a socket is created internally, will call
@@ -2209,6 +2240,9 @@ permissible, use 2048 bits or larger for stronger security.
22092240
<!-- YAML
22102241
added: v0.3.2
22112242
changes:
2243+
- version: REPLACEME
2244+
pr-url: https://github.com/nodejs/node/pull/67532
2245+
description: The `allowRenegotiation` option is now supported.
22122246
- version: v27.0.0-alpha.0.0.0
22132247
pr-url: https://github.com/nodejs/node/pull/64777
22142248
description: Using the `clientCertEngine` option now throws
@@ -2246,6 +2280,13 @@ changes:
22462280
-->
22472281

22482282
* `options` {Object}
2283+
* `allowRenegotiation` {boolean} If `true`, connections to the server may be
2284+
renegotiated, either when requested by the client or through local calls to
2285+
[`tlsSocket.renegotiate()`][]. Renegotiation is deprecated (see
2286+
[DEP0213][]) and future versions will set this default to `false`.
2287+
Setting this to `true` throws [`ERR_TLS_RENEGOTIATION_UNSUPPORTED`][]
2288+
where the TLS library does not support renegotiation on servers.
2289+
**Default:** `true`.
22492290
* `ALPNProtocols` {string\[]|Buffer|TypedArray|DataView} An array of strings,
22502291
or a single `Buffer`, `TypedArray`, or `DataView` containing the supported
22512292
ALPN protocols. Buffers should have the format `[len][name][len][name]...`
@@ -2585,6 +2626,7 @@ added: v0.11.3
25852626

25862627
[CVE-2021-44531]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44531
25872628
[Chrome's 'modern cryptography' setting]: https://www.chromium.org/Home/chromium-security/education/tls#TOC-Cipher-Suites
2629+
[DEP0213]: deprecations.md#dep0213-tls-renegotiation
25882630
[DHE]: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
25892631
[ECDHE]: https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman
25902632
[IANA TLS Supported Groups registry]: https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
@@ -2617,6 +2659,8 @@ added: v0.11.3
26172659
[`--use-openssl-ca`]: cli.md#--use-bundled-ca---use-openssl-ca
26182660
[`--use-system-ca`]: cli.md#--use-system-ca
26192661
[`Duplex`]: stream.md#class-streamduplex
2662+
[`ERR_TLS_RENEGOTIATION_DISABLED`]: errors.md#err_tls_renegotiation_disabled
2663+
[`ERR_TLS_RENEGOTIATION_UNSUPPORTED`]: errors.md#err_tls_renegotiation_unsupported
26202664
[`NODE_EXTRA_CA_CERTS`]: cli.md#node_extra_ca_certsfile
26212665
[`NODE_OPTIONS`]: cli.md#node_optionsoptions
26222666
[`SSL_export_keying_material`]: https://www.openssl.org/docs/man3.0/man3/SSL_export_keying_material.html
@@ -2652,6 +2696,7 @@ added: v0.11.3
26522696
[`tls.getCACertificates()`]: #tlsgetcacertificatestype
26532697
[`tls.getCiphers()`]: #tlsgetciphers
26542698
[`tls.rootCertificates`]: #tlsrootcertificates
2699+
[`tlsSocket.renegotiate()`]: #tlssocketrenegotiateoptions-callback
26552700
[`x509.checkHost()`]: crypto.md#x509checkhostname-options
26562701
[asn1.js]: https://www.npmjs.com/package/asn1.js
26572702
[certificate object]: #certificate-object

‎lib/https.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
700700
if (options.session)
701701
name += getTlsOptionKey(options.session);
702702

703+
name += ':';
704+
if (options.allowRenegotiation !== undefined)
705+
name += getTlsOptionKey(options.allowRenegotiation);
706+
703707
if (options[kPerRequestCheckServerIdentity])
704708
name += `:${options[kPerRequestCheckServerIdentity]}`;
705709

‎lib/internal/tls/wrap.js‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const {
3434

3535
const {
3636
assertCrypto,
37+
getDeprecationWarningEmitter,
38+
isPendingDeprecation,
3739
kEmptyObject,
3840
} = require('internal/util');
3941

@@ -101,10 +103,20 @@ const {
101103
const {
102104
InternalX509Certificate,
103105
} = require('internal/crypto/x509');
106+
const emitRenegotiationDeprecation = getDeprecationWarningEmitter(
107+
'DEP0213',
108+
'TLS renegotiation is deprecated and will be disabled by default. Only ' +
109+
"clients setting allowRenegotiation to accept a server's request will " +
110+
'remain supported.',
111+
undefined,
112+
false,
113+
isPendingDeprecation,
114+
);
104115
const traceTls = getOptionValue('--trace-tls');
105116
const tlsKeylog = getOptionValue('--tls-keylog');
106117
const { appendFile } = require('fs');
107118
const kConnectOptions = Symbol('connect-options');
119+
const kAllowRenegotiation = Symbol('allowRenegotiation');
108120
const kDisableRenegotiation = Symbol('disable-renegotiation');
109121
const kErrorEmitted = Symbol('error-emitted');
110122
const kHandshakeTimeout = Symbol('handshake-timeout');
@@ -234,6 +246,15 @@ function onhandshakestart(now) {
234246
owner._emitTLSError(new ERR_TLS_RENEGOTIATION_DISABLED());
235247
}
236248

249+
function validateAllowRenegotiation(allowRenegotiation, isServer) {
250+
if (allowRenegotiation === undefined)
251+
return;
252+
validateBoolean(allowRenegotiation, 'options.allowRenegotiation');
253+
// BoringSSL servers always refuse renegotiation.
254+
if (allowRenegotiation && isServer && isBoringSSL)
255+
throw new ERR_TLS_RENEGOTIATION_UNSUPPORTED();
256+
}
257+
237258
function onhandshakedone() {
238259
debug('server onhandshakedone');
239260

@@ -655,6 +676,9 @@ function TLSSocket(socket, opts) {
655676
if (tlsOptions.ALPNProtocols)
656677
tls.convertALPNProtocols(tlsOptions.ALPNProtocols, tlsOptions);
657678

679+
validateAllowRenegotiation(tlsOptions.allowRenegotiation,
680+
tlsOptions.isServer);
681+
658682
this._tlsOptions = tlsOptions;
659683
this._secureEstablished = false;
660684
this._securePending = false;
@@ -977,6 +1001,9 @@ TLSSocket.prototype._init = function(socket, wrap) {
9771001
if (requestCert || rejectUnauthorized)
9781002
ssl.setVerifyMode(requestCert, rejectUnauthorized);
9791003

1004+
if (options.allowRenegotiation === false)
1005+
ssl.disableRenegotiation();
1006+
9801007
// Only call .onkeylog if there is a keylog listener.
9811008
ssl.onkeylog = onkeylog;
9821009

@@ -1114,6 +1141,8 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
11141141
validateFunction(callback, 'callback');
11151142
}
11161143

1144+
emitRenegotiationDeprecation();
1145+
11171146
debug('%s renegotiate()',
11181147
this._tlsOptions.isServer ? 'server' : 'client',
11191148
'destroyed?', this.destroyed,
@@ -1122,6 +1151,13 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
11221151
if (this.destroyed)
11231152
return;
11241153

1154+
if (this._tlsOptions.allowRenegotiation === false) {
1155+
if (callback) {
1156+
process.nextTick(callback, new ERR_TLS_RENEGOTIATION_DISABLED());
1157+
}
1158+
return false;
1159+
}
1160+
11251161
let requestCert = !!this._requestCert;
11261162
let rejectUnauthorized = !!this._rejectUnauthorized;
11271163

@@ -1228,6 +1264,13 @@ TLSSocket.prototype._finishInit = function() {
12281264
'alpn', this.alpnProtocol,
12291265
'servername', this.servername);
12301266

1267+
// A second completed handshake is a renegotiation.
1268+
if (this._secureEstablished &&
1269+
(this._tlsOptions.isServer ||
1270+
this._tlsOptions.allowRenegotiation !== true)) {
1271+
emitRenegotiationDeprecation();
1272+
}
1273+
12311274
this._secureEstablished = true;
12321275
if (this._tlsOptions.handshakeTimeout > 0)
12331276
this.setTimeout(0, this._handleTimeout);
@@ -1412,6 +1455,7 @@ function tlsConnectionListener(rawSocket) {
14121455
ALPNCallback: this.ALPNCallback,
14131456
SNICallback: this[kSNICallback] || SNICallback,
14141457
enableTrace: this[kEnableTrace],
1458+
allowRenegotiation: this[kAllowRenegotiation],
14151459
pauseOnConnect: this.pauseOnConnect,
14161460
pskCallback: this[kPskCallback],
14171461
pskIdentityHint: this[kPskIdentityHint],
@@ -1532,6 +1576,9 @@ function Server(options, listener) {
15321576

15331577
validateNumber(this[kHandshakeTimeout], 'options.handshakeTimeout');
15341578

1579+
validateAllowRenegotiation(options.allowRenegotiation, true);
1580+
this[kAllowRenegotiation] = options.allowRenegotiation;
1581+
15351582
if (this[kSNICallback]) {
15361583
validateFunction(this[kSNICallback], 'options.SNICallback');
15371584
}
@@ -1901,6 +1948,7 @@ exports.connect = function connect(...args) {
19011948
ALPNProtocols: options.ALPNProtocols,
19021949
requestOCSP: options.requestOCSP,
19031950
enableTrace: options.enableTrace,
1951+
allowRenegotiation: options.allowRenegotiation,
19041952
pskCallback: options.pskCallback,
19051953
highWaterMark: options.highWaterMark,
19061954
onread: options.onread,

0 commit comments

Comments
 (0)