Skip to content

Commit 84a2768

Browse files
cjihrigtargos
authored andcommitted
tls: support enableTrace in TLSSocket()
This commit adds the enableTrace option to the TLSSocket constructor. It also plumbs the option through other relevant APIs. PR-URL: #27497 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 576fe33 commit 84a2768

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

‎doc/api/tls.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ connection is open.
586586
<!-- YAML
587587
added: v0.11.4
588588
changes:
589+
- version: REPLACEME
590+
pr-url: https://github.com/nodejs/node/pull/27497
591+
description: The `enableTrace` option is now supported.
589592
- version: v5.0.0
590593
pr-url: https://github.com/nodejs/node/pull/2564
591594
description: ALPN options are supported now.
@@ -596,6 +599,7 @@ changes:
596599
instance of [`net.Socket`][] (for generic `Duplex` stream support
597600
on the client side, [`tls.connect()`][] must be used).
598601
*`options` {Object}
602+
*`enableTrace`: See [`tls.createServer()`][]
599603
*`isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if
600604
they are to behave as a server or a client. If `true` the TLS socket will be
601605
instantiated as a server. **Default:**`false`.
@@ -1125,6 +1129,9 @@ being issued by trusted CA (`options.ca`).
11251129
<!-- YAML
11261130
added: v0.11.3
11271131
changes:
1132+
- version: REPLACEME
1133+
pr-url: https://github.com/nodejs/node/pull/27497
1134+
description: The `enableTrace` option is now supported.
11281135
- version: v11.8.0
11291136
pr-url: https://github.com/nodejs/node/pull/25517
11301137
description: The `timeout` option is supported now.
@@ -1144,6 +1151,7 @@ changes:
11441151
-->
11451152

11461153
*`options` {Object}
1154+
*`enableTrace`: See [`tls.createServer()`][]
11471155
*`host` {string} Host the client should connect to. **Default:**
11481156
`'localhost'`.
11491157
*`port` {number} Port the client should connect to.
@@ -1647,6 +1655,7 @@ changes:
16471655
*`rejectUnauthorized` {boolean} If not `false` a server automatically reject
16481656
clients with invalid certificates. Only applies when `isServer` is `true`.
16491657
*`options`
1658+
*`enableTrace`: See [`tls.createServer()`][]
16501659
*`secureContext`: A TLS context object from [`tls.createSecureContext()`][]
16511660
*`isServer`: If `true` the TLS socket will be instantiated in server-mode.
16521661
**Default:**`false`.

‎lib/_tls_wrap.js‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ function initRead(tlsSocket, socket) {
343343

344344
functionTLSSocket(socket,opts){
345345
consttlsOptions={ ...opts};
346+
constenableTrace=tlsOptions.enableTrace;
347+
348+
if(typeofenableTrace!=='boolean'&&enableTrace!=null){
349+
thrownewERR_INVALID_ARG_TYPE(
350+
'options.enableTrace','boolean',enableTrace);
351+
}
346352

347353
if(tlsOptions.ALPNProtocols)
348354
tls.convertALPNProtocols(tlsOptions.ALPNProtocols,tlsOptions);
@@ -397,6 +403,9 @@ function TLSSocket(socket, opts) {
397403
this.readable=true;
398404
this.writable=true;
399405

406+
if(enableTrace&&this._handle)
407+
this._handle.enableTrace();
408+
400409
// Read on next tick so the caller has a chance to setup listeners
401410
process.nextTick(initRead,this,socket);
402411
}
@@ -872,10 +881,9 @@ function tlsConnectionListener(rawSocket) {
872881
rejectUnauthorized: this.rejectUnauthorized,
873882
handshakeTimeout: this[kHandshakeTimeout],
874883
ALPNProtocols: this.ALPNProtocols,
875-
SNICallback: this[kSNICallback]||SNICallback
884+
SNICallback: this[kSNICallback]||SNICallback,
885+
enableTrace: this[kEnableTrace]
876886
});
877-
if(this[kEnableTrace]&&socket._handle)
878-
socket._handle.enableTrace();
879887

880888
socket.on('secure',onServerSocketSecure);
881889

@@ -997,13 +1005,7 @@ function Server(options, listener) {
9971005
this.on('secureConnection',listener);
9981006
}
9991007

1000-
constenableTrace=options.enableTrace;
1001-
if(typeofenableTrace==='boolean'){
1002-
this[kEnableTrace]=enableTrace;
1003-
}elseif(enableTrace!=null){
1004-
thrownewERR_INVALID_ARG_TYPE(
1005-
'options.enableTrace','boolean',enableTrace);
1006-
}
1008+
this[kEnableTrace]=options.enableTrace;
10071009
}
10081010

10091011
Object.setPrototypeOf(Server.prototype,net.Server.prototype);
@@ -1364,7 +1366,8 @@ exports.connect = function connect(...args) {
13641366
rejectUnauthorized: options.rejectUnauthorized!==false,
13651367
session: options.session,
13661368
ALPNProtocols: options.ALPNProtocols,
1367-
requestOCSP: options.requestOCSP
1369+
requestOCSP: options.requestOCSP,
1370+
enableTrace: options.enableTrace
13681371
});
13691372

13701373
tlssock[kConnectOptions]=options;

0 commit comments

Comments
 (0)