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 <anna@addaleax.net>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
This commit is contained in:
Sam Roberts authored and Anna Henningsen committed 2019-02-06 15:50:11 +01:00
1 parent d02ad40d42
commit 7656d58eed
10 files changed
+147 -48

No files matched your search

+12 -10
View File
@@ -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());
});
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);
});
// Evict session on error
socket.once('close', (err) => {
if (err)
this._evictSession(options._agentKey);
});
}
return socket;
}