diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2019-01-30 12:18:04 -0800 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2019-02-01 19:06:58 -0800 |
commit | 0f8e8f7c6b9e7a8bdae53c831f37b2034d1c9fa7 (patch) | |
tree | 2b7d72ab24c8b9538e4e1da9a3fa5c71482fdb01 /test/parallel/test-tls-client-resume.js | |
parent | e1aa9438ead2093a536e5981da7097c9196e7113 (diff) | |
download | android-node-v8-0f8e8f7c6b9e7a8bdae53c831f37b2034d1c9fa7.tar.gz android-node-v8-0f8e8f7c6b9e7a8bdae53c831f37b2034d1c9fa7.tar.bz2 android-node-v8-0f8e8f7c6b9e7a8bdae53c831f37b2034d1c9fa7.zip |
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>
Diffstat (limited to 'test/parallel/test-tls-client-resume.js')
-rw-r--r-- | test/parallel/test-tls-client-resume.js | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/test/parallel/test-tls-client-resume.js b/test/parallel/test-tls-client-resume.js index db4c898d74..9f868fdcdc 100644 --- a/test/parallel/test-tls-client-resume.js +++ b/test/parallel/test-tls-client-resume.js @@ -20,9 +20,9 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -// Create an ssl server. First connection, validate that not resume. -// Cache session and close connection. Use session on second connection. -// ASSERT resumption. + +// Check that the ticket from the first connection causes session resumption +// when used to make a second connection. const common = require('../common'); if (!common.hasCrypto) @@ -43,20 +43,28 @@ const server = tls.Server(options, common.mustCall((socket) => { }, 2)); // start listening -server.listen(0, function() { +server.listen(0, common.mustCall(function() { + let sessionx = null; let session1 = null; const client1 = tls.connect({ port: this.address().port, rejectUnauthorized: false - }, () => { + }, common.mustCall(() => { console.log('connect1'); - assert.ok(!client1.isSessionReused(), 'Session *should not* be reused.'); - session1 = client1.getSession(); - }); + assert.strictEqual(client1.isSessionReused(), false); + sessionx = client1.getSession(); + })); + + client1.once('session', common.mustCall((session) => { + console.log('session1'); + session1 = session; + })); - client1.on('close', () => { - console.log('close1'); + client1.on('close', common.mustCall(() => { + assert(sessionx); + assert(session1); + assert.strictEqual(sessionx.compare(session1), 0); const opts = { port: server.address().port, @@ -64,18 +72,18 @@ server.listen(0, function() { session: session1 }; - const client2 = tls.connect(opts, () => { + const client2 = tls.connect(opts, common.mustCall(() => { console.log('connect2'); - assert.ok(client2.isSessionReused(), 'Session *should* be reused.'); - }); + assert.strictEqual(client2.isSessionReused(), true); + })); - client2.on('close', () => { + client2.on('close', common.mustCall(() => { console.log('close2'); server.close(); - }); + })); client2.resume(); - }); + })); client1.resume(); -}); +})); |