1// Flags: --tls-min-v1.0 2'use strict'; 3 4const common = require('../common'); 5const { readKey } = require('../common/fixtures'); 6 7if (!common.hasCrypto) 8 common.skip('missing crypto'); 9 10const https = require('https'); 11const { SSL_OP_NO_TICKET } = require('crypto').constants; 12 13const options = { 14 key: readKey('agent1-key.pem'), 15 cert: readKey('agent1-cert.pem'), 16 secureOptions: SSL_OP_NO_TICKET 17}; 18 19// Create TLS1.2 server 20https.createServer(options, function(req, res) { 21 res.end('ohai'); 22}).listen(0, function() { 23 first(this); 24}); 25 26// Do request and let agent cache the session 27function first(server) { 28 const port = server.address().port; 29 const req = https.request({ 30 port: port, 31 rejectUnauthorized: false 32 }, function(res) { 33 res.resume(); 34 35 server.close(function() { 36 faultyServer(port); 37 }); 38 }); 39 req.end(); 40} 41 42// Create TLS1 server 43function faultyServer(port) { 44 options.secureProtocol = 'TLSv1_method'; 45 https.createServer(options, function(req, res) { 46 res.end('hello faulty'); 47 }).listen(port, function() { 48 second(this); 49 }); 50} 51 52// Attempt to request using cached session 53function second(server, session) { 54 const req = https.request({ 55 port: server.address().port, 56 rejectUnauthorized: false 57 }, function(res) { 58 res.resume(); 59 }); 60 61 // Although we have a TLS 1.2 session to offer to the TLS 1.0 server, 62 // connection to the TLS 1.0 server should work. 63 req.on('response', common.mustCall(function(res) { 64 // The test is now complete for OpenSSL 1.1.0. 65 server.close(); 66 })); 67 68 req.end(); 69} 70