11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst https = require('https');
91cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst server = https.createServer({
121cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent2-key.pem'),
131cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent2-cert.pem'),
141cb0ef41Sopenharmony_ci  // Amount of keylog events depends on negotiated protocol
151cb0ef41Sopenharmony_ci  // version, so force a specific one:
161cb0ef41Sopenharmony_ci  minVersion: 'TLSv1.3',
171cb0ef41Sopenharmony_ci  maxVersion: 'TLSv1.3',
181cb0ef41Sopenharmony_ci}, (req, res) => {
191cb0ef41Sopenharmony_ci  res.end('bye');
201cb0ef41Sopenharmony_ci}).listen(() => {
211cb0ef41Sopenharmony_ci  https.get({
221cb0ef41Sopenharmony_ci    port: server.address().port,
231cb0ef41Sopenharmony_ci    rejectUnauthorized: false,
241cb0ef41Sopenharmony_ci  }, (res) => {
251cb0ef41Sopenharmony_ci    res.resume();
261cb0ef41Sopenharmony_ci    res.on('end', () => {
271cb0ef41Sopenharmony_ci      // Trigger TLS connection reuse
281cb0ef41Sopenharmony_ci      https.get({
291cb0ef41Sopenharmony_ci        port: server.address().port,
301cb0ef41Sopenharmony_ci        rejectUnauthorized: false,
311cb0ef41Sopenharmony_ci      }, (res) => {
321cb0ef41Sopenharmony_ci        server.close();
331cb0ef41Sopenharmony_ci        res.resume();
341cb0ef41Sopenharmony_ci      });
351cb0ef41Sopenharmony_ci    });
361cb0ef41Sopenharmony_ci  });
371cb0ef41Sopenharmony_ci});
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciconst verifyKeylog = (line, tlsSocket) => {
401cb0ef41Sopenharmony_ci  assert(Buffer.isBuffer(line));
411cb0ef41Sopenharmony_ci  assert.strictEqual(tlsSocket.encrypted, true);
421cb0ef41Sopenharmony_ci};
431cb0ef41Sopenharmony_ciserver.on('keylog', common.mustCall(verifyKeylog, 10));
441cb0ef41Sopenharmony_cihttps.globalAgent.on('keylog', common.mustCall(verifyKeylog, 10));
45