1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const https = require('https'); 9const fixtures = require('../common/fixtures'); 10 11const server = https.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}, (req, res) => { 19 res.end('bye'); 20}).listen(() => { 21 https.get({ 22 port: server.address().port, 23 rejectUnauthorized: false, 24 }, (res) => { 25 res.resume(); 26 res.on('end', () => { 27 // Trigger TLS connection reuse 28 https.get({ 29 port: server.address().port, 30 rejectUnauthorized: false, 31 }, (res) => { 32 server.close(); 33 res.resume(); 34 }); 35 }); 36 }); 37}); 38 39const verifyKeylog = (line, tlsSocket) => { 40 assert(Buffer.isBuffer(line)); 41 assert.strictEqual(tlsSocket.encrypted, true); 42}; 43server.on('keylog', common.mustCall(verifyKeylog, 10)); 44https.globalAgent.on('keylog', common.mustCall(verifyKeylog, 10)); 45