From 0f8e8f7c6b9e7a8bdae53c831f37b2034d1c9fa7 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 30 Jan 2019 12:18:04 -0800 Subject: tls: introduce client 'session' event OpenSSL has supported async notification of sessions and tickets since 1.1.0 using SSL_CTX_sess_set_new_cb(), for all versions of TLS. Using the async API is optional for TLS1.2 and below, but for TLS1.3 it will be mandatory. Future-proof applications should start to use async notification immediately. In the future, for TLS1.3, applications that don't use the async API will silently, but gracefully, fail to resume sessions and instead do a full handshake. See: https://wiki.openssl.org/index.php/TLS1.3#Sessions PR-URL: https://github.com/nodejs/node/pull/25831 Reviewed-By: Anna Henningsen Reviewed-By: Fedor Indutny --- lib/https.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'lib/https.js') diff --git a/lib/https.js b/lib/https.js index 9ac4cfd0d3..041bd41edd 100644 --- a/lib/https.js +++ b/lib/https.js @@ -117,18 +117,20 @@ function createConnection(port, host, options) { } } - const socket = tls.connect(options, () => { - if (!options._agentKey) - return; + const socket = tls.connect(options); - this._cacheSession(options._agentKey, socket.getSession()); - }); - - // Evict session on error - socket.once('close', (err) => { - if (err) - this._evictSession(options._agentKey); - }); + if (options._agentKey) { + // Cache new session for reuse + socket.on('session', (session) => { + this._cacheSession(options._agentKey, session); + }); + + // Evict session on error + socket.once('close', (err) => { + if (err) + this._evictSession(options._agentKey); + }); + } return socket; } -- cgit v1.2.3