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: cleanup onhandshakestart callback #20466

Closed
Closed
Changes from all commits
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
34 changes: 15 additions & 19 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,28 @@ const noop = () => {};
function onhandshakestart(now) {
debug('onhandshakestart');

assert(now >= this.lastHandshakeTime);
const { lastHandshakeTime } = this;
assert(now >= lastHandshakeTime);

const owner = this.owner;
this.lastHandshakeTime = now;

if ((now - this.lastHandshakeTime) >= tls.CLIENT_RENEG_WINDOW * 1000) {
this.handshakes = 0;
}
// If this is the first handshake we can skip the rest of the checks.
if (lastHandshakeTime === 0)
return;

const first = (this.lastHandshakeTime === 0);
this.lastHandshakeTime = now;
if (first) return;
if ((now - lastHandshakeTime) >= tls.CLIENT_RENEG_WINDOW * 1000)
this.handshakes = 1;
else
this.handshakes++;

if (++this.handshakes > tls.CLIENT_RENEG_LIMIT) {
// Defer the error event to the next tick. We're being called from OpenSSL's
// state machine and OpenSSL is not re-entrant. We cannot allow the user's
// callback to destroy the connection right now, it would crash and burn.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary. We already defer the actual cleanup within destroy by using setImmediate. This is also backed up by the way renegotiation errors are handled below (which we also have tests for).

setImmediate(emitSessionAttackError, owner);
const { owner } = this;
if (this.handshakes > tls.CLIENT_RENEG_LIMIT) {
owner._emitTLSError(new ERR_TLS_SESSION_ATTACK());
return;
}

if (owner[kDisableRenegotiation] && this.handshakes > 0) {
if (owner[kDisableRenegotiation])
owner._emitTLSError(new ERR_TLS_RENEGOTIATION_DISABLED());
}
}

function emitSessionAttackError(socket) {
socket._emitTLSError(new ERR_TLS_SESSION_ATTACK());
}

function onhandshakedone() {
Expand Down