Skip to content

Commit 79261f3

Browse files
mannanali413joyeecheung
authored andcommitted
tls: migrate errors in _tls_wrap.js
This migrates the old style error in _tls_wrap.js to the new style error ERR_TLS_RENEGOTIATION_DISABLED. Refs: #17709 PR-URL: #17792 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 0b78895 commit 79261f3

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

doc/api/errors.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,11 @@ a hostname in the first parameter.
15131513
An excessive amount of TLS renegotiations is detected, which is a potential
15141514
vector for denial-of-service attacks.
15151515

1516+
<a id="ERR_TLS_RENEGOTIATION_DISABLED"></a>
1517+
### ERR_TLS_RENEGOTIATION_DISABLED
1518+
1519+
An attempt was made to renegotiate TLS on a socket instance with TLS disabled.
1520+
15161521
<a id="ERR_TRANSFORM_ALREADY_TRANSFORMING"></a>
15171522
### ERR_TRANSFORM_ALREADY_TRANSFORMING
15181523

lib/_tls_wrap.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ function onhandshakestart() {
7070
}
7171

7272
if (owner[kDisableRenegotiation] && this.handshakes > 0) {
73-
const err = new Error('TLS session renegotiation disabled for this socket');
74-
owner._emitTLSError(err);
73+
owner._emitTLSError(new errors.Error('ERR_TLS_RENEGOTIATION_DISABLED'));
7574
}
7675
}
7776

lib/internal/errors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ E('ERR_TLS_CERT_ALTNAME_INVALID',
474474
'Hostname/IP does not match certificate\'s altnames: %s');
475475
E('ERR_TLS_DH_PARAM_SIZE', 'DH parameter size %s is less than 2048');
476476
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
477+
E('ERR_TLS_RENEGOTIATION_DISABLED',
478+
'TLS session renegotiation disabled for this socket');
477479
E('ERR_TLS_RENEGOTIATION_FAILED', 'Failed to renegotiate');
478480
E('ERR_TLS_REQUIRED_SERVER_NAME',
479481
'"servername" is required parameter for Server.addContext');

test/parallel/test-tls-disable-renegotiation.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ const options = {
1717

1818
const server = tls.Server(options, common.mustCall((socket) => {
1919
socket.on('error', common.mustCall((err) => {
20-
assert.strictEqual(
21-
err.message,
22-
'TLS session renegotiation disabled for this socket');
20+
common.expectsError({
21+
type: Error,
22+
code: 'ERR_TLS_RENEGOTIATION_DISABLED',
23+
message: 'TLS session renegotiation disabled for this socket'
24+
})(err);
2325
socket.destroy();
2426
server.close();
2527
}));

0 commit comments

Comments
 (0)