1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23// Create an ssl server. First connection, validate that not resume. 24// Cache session and close connection. Use session on second connection. 25// ASSERT resumption. 26const common = require('../common'); 27if (!common.hasCrypto) 28 common.skip('missing crypto'); 29 30const assert = require('assert'); 31const https = require('https'); 32const tls = require('tls'); 33const fixtures = require('../common/fixtures'); 34 35const options = { 36 key: fixtures.readKey('agent2-key.pem'), 37 cert: fixtures.readKey('agent2-cert.pem') 38}; 39 40// create server 41const server = https.createServer(options, common.mustCall((req, res) => { 42 res.end('Goodbye'); 43}, 2)); 44 45// start listening 46server.listen(0, common.mustCall(function() { 47 const client1 = tls.connect({ 48 port: this.address().port, 49 rejectUnauthorized: false 50 }, common.mustCall(() => { 51 console.log('connect1'); 52 assert.strictEqual(client1.isSessionReused(), false); 53 client1.write('GET / HTTP/1.0\r\n' + 54 'Server: 127.0.0.1\r\n' + 55 '\r\n'); 56 })); 57 58 // TLS1.2 servers issue 1 ticket, TLS1.3 issues more, but only use the first. 59 client1.once('session', common.mustCall((session) => { 60 console.log('session'); 61 62 const opts = { 63 port: server.address().port, 64 rejectUnauthorized: false, 65 session, 66 }; 67 68 const client2 = tls.connect(opts, common.mustCall(() => { 69 console.log('connect2'); 70 assert.strictEqual(client2.isSessionReused(), true); 71 client2.write('GET / HTTP/1.0\r\n' + 72 'Server: 127.0.0.1\r\n' + 73 '\r\n'); 74 })); 75 76 client2.on('close', () => { 77 console.log('close2'); 78 server.close(); 79 }); 80 81 client2.resume(); 82 })); 83 84 client1.resume(); 85})); 86