1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const tls = require('tls'); 9const fixtures = require('../common/fixtures'); 10 11const server = tls.createServer({ 12 key: fixtures.readKey('agent2-key.pem'), 13 cert: fixtures.readKey('agent2-cert.pem'), 14 // Amount of keylog events depends on negotiated protocol 15 // version, so force a specific one: 16 minVersion: 'TLSv1.3', 17 maxVersion: 'TLSv1.3', 18}).listen(() => { 19 const client = tls.connect({ 20 port: server.address().port, 21 rejectUnauthorized: false, 22 }); 23 24 server.on('keylog', common.mustCall((line, tlsSocket) => { 25 assert(Buffer.isBuffer(line)); 26 assert.strictEqual(tlsSocket.encrypted, true); 27 }, 5)); 28 client.on('keylog', common.mustCall((line) => { 29 assert(Buffer.isBuffer(line)); 30 }, 5)); 31 32 client.once('secureConnect', () => { 33 server.close(); 34 client.end(); 35 }); 36}); 37