Skip to content

Commit

Permalink
tls: support enableTrace in TLSSocket()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and targos committed May 4, 2019
1 parent 576fe33 commit 84a2768
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
9 changes: 9 additions & 0 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ connection is open.
<!-- YAML
added: v0.11.4
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/27497
description: The `enableTrace` option is now supported.
- version: v5.0.0
pr-url: https://github.com/nodejs/node/pull/2564
description: ALPN options are supported now.
Expand All @@ -596,6 +599,7 @@ changes:
instance of [`net.Socket`][] (for generic `Duplex` stream support
on the client side, [`tls.connect()`][] must be used).
* `options` {Object}
* `enableTrace`: See [`tls.createServer()`][]
* `isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if
they are to behave as a server or a client. If `true` the TLS socket will be
instantiated as a server. **Default:** `false`.
Expand Down Expand Up @@ -1125,6 +1129,9 @@ being issued by trusted CA (`options.ca`).
<!-- YAML
added: v0.11.3
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/27497
description: The `enableTrace` option is now supported.
- version: v11.8.0
pr-url: https://github.com/nodejs/node/pull/25517
description: The `timeout` option is supported now.
Expand All @@ -1144,6 +1151,7 @@ changes:
-->

* `options` {Object}
* `enableTrace`: See [`tls.createServer()`][]
* `host` {string} Host the client should connect to. **Default:**
`'localhost'`.
* `port` {number} Port the client should connect to.
Expand Down Expand Up @@ -1647,6 +1655,7 @@ changes:
* `rejectUnauthorized` {boolean} If not `false` a server automatically reject
clients with invalid certificates. Only applies when `isServer` is `true`.
* `options`
* `enableTrace`: See [`tls.createServer()`][]
* `secureContext`: A TLS context object from [`tls.createSecureContext()`][]
* `isServer`: If `true` the TLS socket will be instantiated in server-mode.
**Default:** `false`.
Expand Down
25 changes: 14 additions & 11 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ function initRead(tlsSocket, socket) {

function TLSSocket(socket, opts) {
const tlsOptions = { ...opts };
const enableTrace = tlsOptions.enableTrace;

if (typeof enableTrace !== 'boolean' && enableTrace != null) {
throw new ERR_INVALID_ARG_TYPE(
'options.enableTrace', 'boolean', enableTrace);
}

if (tlsOptions.ALPNProtocols)
tls.convertALPNProtocols(tlsOptions.ALPNProtocols, tlsOptions);
Expand Down Expand Up @@ -397,6 +403,9 @@ function TLSSocket(socket, opts) {
this.readable = true;
this.writable = true;

if (enableTrace && this._handle)
this._handle.enableTrace();

// Read on next tick so the caller has a chance to setup listeners
process.nextTick(initRead, this, socket);
}
Expand Down Expand Up @@ -872,10 +881,9 @@ function tlsConnectionListener(rawSocket) {
rejectUnauthorized: this.rejectUnauthorized,
handshakeTimeout: this[kHandshakeTimeout],
ALPNProtocols: this.ALPNProtocols,
SNICallback: this[kSNICallback] || SNICallback
SNICallback: this[kSNICallback] || SNICallback,
enableTrace: this[kEnableTrace]
});
if (this[kEnableTrace] && socket._handle)
socket._handle.enableTrace();

socket.on('secure', onServerSocketSecure);

Expand Down Expand Up @@ -997,13 +1005,7 @@ function Server(options, listener) {
this.on('secureConnection', listener);
}

const enableTrace = options.enableTrace;
if (typeof enableTrace === 'boolean') {
this[kEnableTrace] = enableTrace;
} else if (enableTrace != null) {
throw new ERR_INVALID_ARG_TYPE(
'options.enableTrace', 'boolean', enableTrace);
}
this[kEnableTrace] = options.enableTrace;
}

Object.setPrototypeOf(Server.prototype, net.Server.prototype);
Expand Down Expand Up @@ -1364,7 +1366,8 @@ exports.connect = function connect(...args) {
rejectUnauthorized: options.rejectUnauthorized !== false,
session: options.session,
ALPNProtocols: options.ALPNProtocols,
requestOCSP: options.requestOCSP
requestOCSP: options.requestOCSP,
enableTrace: options.enableTrace
});

tlssock[kConnectOptions] = options;
Expand Down

0 comments on commit 84a2768

Please sign in to comment.