• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const tls = require('tls');
8const net = require('net');
9const fixtures = require('../common/fixtures');
10
11const bonkers = Buffer.alloc(1024, 42);
12
13const options = {
14  key: fixtures.readKey('agent1-key.pem'),
15  cert: fixtures.readKey('agent1-cert.pem')
16};
17
18const server = net.createServer(common.mustCall(function(c) {
19  setTimeout(common.mustCall(function() {
20    const s = new tls.TLSSocket(c, {
21      isServer: true,
22      secureContext: tls.createSecureContext(options)
23    });
24
25    s.on('_tlsError', common.mustCall());
26
27    s.on('close', function() {
28      server.close();
29      s.destroy();
30    });
31  }), 200);
32})).listen(0, function() {
33  const c = net.connect({ port: this.address().port }, function() {
34    c.write(bonkers);
35  });
36});
37