Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls,cli: add --trace-tls command-line flag #27497

Merged
merged 3 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
cjihrig committed May 2, 2019
commit c6a2fdf3aa8f8db7344ae7c530468b9feb715086
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