2016-01-31 00:49:11 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2016-01-31 00:49:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const https = require('https');
|
|
|
|
const fs = require('fs');
|
2016-05-02 19:27:12 +02:00
|
|
|
const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET;
|
2016-01-31 00:49:11 +01:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
|
2016-05-02 19:27:12 +02:00
|
|
|
secureOptions: SSL_OP_NO_TICKET
|
2016-01-31 00:49:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create TLS1.2 server
|
|
|
|
https.createServer(options, function(req, res) {
|
|
|
|
res.end('ohai');
|
2016-05-29 09:06:56 +02:00
|
|
|
}).listen(0, function() {
|
2016-01-31 00:49:11 +01:00
|
|
|
first(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Do request and let agent cache the session
|
2016-05-09 08:04:17 +02:00
|
|
|
function first(server) {
|
2016-05-29 09:06:56 +02:00
|
|
|
const port = server.address().port;
|
2016-01-31 00:49:11 +01:00
|
|
|
const req = https.request({
|
2016-05-29 09:06:56 +02:00
|
|
|
port: port,
|
2016-01-31 00:49:11 +01:00
|
|
|
rejectUnauthorized: false
|
|
|
|
}, function(res) {
|
|
|
|
res.resume();
|
|
|
|
|
|
|
|
server.close(function() {
|
2016-05-29 09:06:56 +02:00
|
|
|
faultyServer(port);
|
2016-01-31 00:49:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
req.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create TLS1 server
|
2016-05-29 09:06:56 +02:00
|
|
|
function faultyServer(port) {
|
2016-01-31 00:49:11 +01:00
|
|
|
options.secureProtocol = 'TLSv1_method';
|
|
|
|
https.createServer(options, function(req, res) {
|
|
|
|
res.end('hello faulty');
|
2016-05-29 09:06:56 +02:00
|
|
|
}).listen(port, function() {
|
2016-01-31 00:49:11 +01:00
|
|
|
second(this);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to request using cached session
|
|
|
|
function second(server, session) {
|
|
|
|
const req = https.request({
|
2016-05-29 09:06:56 +02:00
|
|
|
port: server.address().port,
|
2016-01-31 00:49:11 +01:00
|
|
|
rejectUnauthorized: false
|
|
|
|
}, function(res) {
|
|
|
|
res.resume();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Let it fail
|
|
|
|
req.on('error', common.mustCall(function(err) {
|
|
|
|
assert(/wrong version number/.test(err.message));
|
|
|
|
|
|
|
|
req.on('close', function() {
|
|
|
|
third(server);
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
req.end();
|
|
|
|
}
|
|
|
|
|
2016-05-29 09:06:56 +02:00
|
|
|
// Try one more time - session should be evicted!
|
2016-01-31 00:49:11 +01:00
|
|
|
function third(server) {
|
|
|
|
const req = https.request({
|
2016-05-29 09:06:56 +02:00
|
|
|
port: server.address().port,
|
2016-01-31 00:49:11 +01:00
|
|
|
rejectUnauthorized: false
|
|
|
|
}, function(res) {
|
|
|
|
res.resume();
|
|
|
|
assert(!req.socket.isSessionReused());
|
|
|
|
server.close();
|
|
|
|
});
|
2017-02-03 20:54:19 +01:00
|
|
|
req.on('error', common.mustNotCall());
|
2016-01-31 00:49:11 +01:00
|
|
|
req.end();
|
|
|
|
}
|