• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5
6const fixtures = require('../common/fixtures');
7const https = require('https');
8const crypto = require('crypto');
9
10const options = {
11  key: fixtures.readKey('agent1-key.pem'),
12  cert: fixtures.readKey('agent1-cert.pem'),
13  ca: fixtures.readKey('ca1-cert.pem')
14};
15
16const server = https.createServer(options, function(req, res) {
17  res.end('hello');
18});
19
20const aes = Buffer.alloc(16, 'S');
21const hmac = Buffer.alloc(16, 'H');
22
23server._sharedCreds.context.enableTicketKeyCallback();
24server._sharedCreds.context.onticketkeycallback = function(name, iv, enc) {
25  if (enc) {
26    const newName = Buffer.alloc(16, 'A');
27    const newIV = crypto.randomBytes(16);
28    return [ 1, hmac, aes, newName, newIV ];
29  }
30  // Renew
31  return [ 2, hmac, aes ];
32};
33
34server.listen(0, function() {
35  const addr = this.address();
36
37  function doReq(callback) {
38    https.request({
39      method: 'GET',
40      port: addr.port,
41      servername: 'agent1',
42      ca: options.ca
43    }, function(res) {
44      res.resume();
45      res.once('end', callback);
46    }).end();
47  }
48
49  doReq(function() {
50    doReq(function() {
51      server.close();
52    });
53  });
54});
55