2015-07-23 06:18:38 +02:00
|
|
|
'use strict';
|
2016-12-03 17:21:11 +01:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2015-07-23 06:18:38 +02:00
|
|
|
|
2017-07-01 01:29:09 +02:00
|
|
|
if (!common.hasCrypto)
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2015-07-23 06:18:38 +02:00
|
|
|
|
2016-12-03 17:21:11 +01:00
|
|
|
const https = require('https');
|
|
|
|
const crypto = require('crypto');
|
2017-10-06 19:58:33 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2015-07-23 06:18:38 +02:00
|
|
|
|
2016-12-03 17:21:11 +01:00
|
|
|
const options = {
|
2017-10-06 19:58:33 +02:00
|
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
2015-07-23 06:18:38 +02:00
|
|
|
};
|
|
|
|
|
2017-10-06 19:58:33 +02:00
|
|
|
const ca = fixtures.readKey('ca1-cert.pem');
|
2015-07-23 06:18:38 +02:00
|
|
|
|
2016-12-03 17:21:11 +01:00
|
|
|
const clientSessions = {};
|
|
|
|
let serverRequests = 0;
|
2015-07-23 06:18:38 +02:00
|
|
|
|
2016-12-03 17:21:11 +01:00
|
|
|
const agent = new https.Agent({
|
2015-07-23 06:18:38 +02:00
|
|
|
maxCachedSessions: 1
|
|
|
|
});
|
|
|
|
|
2016-12-03 17:21:11 +01:00
|
|
|
const server = https.createServer(options, function(req, res) {
|
2015-07-23 06:18:38 +02:00
|
|
|
if (req.url === '/drop-key')
|
|
|
|
server.setTicketKeys(crypto.randomBytes(48));
|
|
|
|
|
|
|
|
serverRequests++;
|
|
|
|
res.end('ok');
|
2016-05-29 09:06:56 +02:00
|
|
|
}).listen(0, function() {
|
2016-12-03 17:21:11 +01:00
|
|
|
const queue = [
|
2015-07-23 06:18:38 +02:00
|
|
|
{
|
|
|
|
name: 'first',
|
|
|
|
|
|
|
|
method: 'GET',
|
|
|
|
path: '/',
|
|
|
|
servername: 'agent1',
|
|
|
|
ca: ca,
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port
|
2015-07-23 06:18:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'first-reuse',
|
|
|
|
|
|
|
|
method: 'GET',
|
|
|
|
path: '/',
|
|
|
|
servername: 'agent1',
|
|
|
|
ca: ca,
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port
|
2015-07-23 06:18:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'cipher-change',
|
|
|
|
|
|
|
|
method: 'GET',
|
|
|
|
path: '/',
|
|
|
|
servername: 'agent1',
|
|
|
|
|
|
|
|
// Choose different cipher to use different cache entry
|
|
|
|
ciphers: 'AES256-SHA',
|
|
|
|
ca: ca,
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port
|
2015-07-23 06:18:38 +02:00
|
|
|
},
|
|
|
|
// Change the ticket key to ensure session is updated in cache
|
|
|
|
{
|
|
|
|
name: 'before-drop',
|
|
|
|
|
|
|
|
method: 'GET',
|
|
|
|
path: '/drop-key',
|
|
|
|
servername: 'agent1',
|
|
|
|
ca: ca,
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port
|
2015-07-23 06:18:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Ticket will be updated starting from this
|
|
|
|
{
|
|
|
|
name: 'after-drop',
|
|
|
|
|
|
|
|
method: 'GET',
|
|
|
|
path: '/',
|
|
|
|
servername: 'agent1',
|
|
|
|
ca: ca,
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port
|
2015-07-23 06:18:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'after-drop-reuse',
|
|
|
|
|
|
|
|
method: 'GET',
|
|
|
|
path: '/',
|
|
|
|
servername: 'agent1',
|
|
|
|
ca: ca,
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port
|
2015-07-23 06:18:38 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
function request() {
|
2016-12-03 17:21:11 +01:00
|
|
|
const options = queue.shift();
|
2015-07-23 06:18:38 +02:00
|
|
|
options.agent = agent;
|
|
|
|
https.request(options, function(res) {
|
|
|
|
clientSessions[options.name] = res.socket.getSession();
|
|
|
|
|
|
|
|
res.resume();
|
|
|
|
res.on('end', function() {
|
|
|
|
if (queue.length !== 0)
|
|
|
|
return request();
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
}).end();
|
|
|
|
}
|
|
|
|
request();
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
2016-12-03 17:21:11 +01:00
|
|
|
assert.strictEqual(serverRequests, 6);
|
2018-02-13 06:09:31 +01:00
|
|
|
assert.strictEqual(clientSessions.first.toString('hex'),
|
2016-12-03 17:21:11 +01:00
|
|
|
clientSessions['first-reuse'].toString('hex'));
|
2018-02-13 06:09:31 +01:00
|
|
|
assert.notStrictEqual(clientSessions.first.toString('hex'),
|
2016-12-30 16:09:13 +01:00
|
|
|
clientSessions['cipher-change'].toString('hex'));
|
2018-02-13 06:09:31 +01:00
|
|
|
assert.notStrictEqual(clientSessions.first.toString('hex'),
|
2016-12-30 16:09:13 +01:00
|
|
|
clientSessions['before-drop'].toString('hex'));
|
|
|
|
assert.notStrictEqual(clientSessions['cipher-change'].toString('hex'),
|
|
|
|
clientSessions['before-drop'].toString('hex'));
|
|
|
|
assert.notStrictEqual(clientSessions['before-drop'].toString('hex'),
|
|
|
|
clientSessions['after-drop'].toString('hex'));
|
2016-12-03 17:21:11 +01:00
|
|
|
assert.strictEqual(clientSessions['after-drop'].toString('hex'),
|
|
|
|
clientSessions['after-drop-reuse'].toString('hex'));
|
2015-07-23 06:18:38 +02:00
|
|
|
});
|