1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
if (!process.versions.openssl) {
console.error('Skipping because node compiled without OpenSSL.');
process.exit(0);
}
var assert = require('assert');
var fs = require('fs');
var net = require('net');
var tls = require('tls');
var crypto = require('crypto');
var common = require('../common');
var keys = crypto.randomBytes(48);
var serverLog = [];
var ticketLog = [];
var serverCount = 0;
function createServer() {
var id = serverCount++;
var server = tls.createServer({
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
ticketKeys: keys
}, function(c) {
serverLog.push(id);
c.end();
});
return server;
}
var servers = [ createServer(), createServer(), createServer(), createServer(), createServer(), createServer() ];
// Create one TCP server and balance sockets to multiple TLS server instances
var shared = net.createServer(function(c) {
servers.shift().emit('connection', c);
}).listen(common.PORT, function() {
start(function() {
shared.close();
});
});
function start(callback) {
var sess = null;
var left = servers.length;
function connect() {
var s = tls.connect(common.PORT, {
session: sess,
rejectUnauthorized: false
}, function() {
sess = s.getSession() || sess;
ticketLog.push(s.getTLSTicket().toString('hex'));
});
s.on('close', function() {
if (--left === 0)
callback();
else
connect();
});
}
connect();
}
process.on('exit', function() {
assert.equal(ticketLog.length, serverLog.length);
for (var i = 0; i < serverLog.length - 1; i++) {
assert.notEqual(serverLog[i], serverLog[i + 1]);
assert.equal(ticketLog[i], ticketLog[i + 1]);
}
});
|