2019-10-22 03:44:20 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto) common.skip('missing crypto');
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
|
|
|
|
// Test --tls-keylog CLI flag.
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
|
|
|
const { fork } = require('child_process');
|
|
|
|
|
|
|
|
if (process.argv[2] === 'test')
|
|
|
|
return test();
|
|
|
|
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2023-08-15 13:45:44 +00:00
|
|
|
const file = tmpdir.resolve('keylog.log');
|
2019-10-22 03:44:20 +00:00
|
|
|
|
|
|
|
const child = fork(__filename, ['test'], {
|
|
|
|
execArgv: ['--tls-keylog=' + file]
|
|
|
|
});
|
|
|
|
|
|
|
|
child.on('close', common.mustCall((code, signal) => {
|
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
assert.strictEqual(signal, null);
|
2020-05-12 12:53:12 +00:00
|
|
|
const log = fs.readFileSync(file, 'utf8').trim().split('\n');
|
|
|
|
// Both client and server should log their secrets,
|
|
|
|
// so we should have two identical lines in the log
|
|
|
|
assert.strictEqual(log.length, 2);
|
|
|
|
assert.strictEqual(log[0], log[1]);
|
2019-10-22 03:44:20 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
const {
|
|
|
|
connect, keys
|
|
|
|
} = require(fixtures.path('tls-connect'));
|
|
|
|
|
|
|
|
connect({
|
|
|
|
client: {
|
|
|
|
checkServerIdentity: (servername, cert) => { },
|
|
|
|
ca: `${keys.agent1.cert}\n${keys.agent6.ca}`,
|
|
|
|
},
|
|
|
|
server: {
|
|
|
|
cert: keys.agent6.cert,
|
2020-05-12 12:53:12 +00:00
|
|
|
key: keys.agent6.key,
|
|
|
|
// Number of keylog events is dependent on protocol version
|
|
|
|
maxVersion: 'TLSv1.2',
|
2019-10-22 03:44:20 +00:00
|
|
|
},
|
|
|
|
}, common.mustCall((err, pair, cleanup) => {
|
|
|
|
if (pair.server.err) {
|
|
|
|
console.trace('server', pair.server.err);
|
|
|
|
}
|
|
|
|
if (pair.client.err) {
|
|
|
|
console.trace('client', pair.client.err);
|
|
|
|
}
|
|
|
|
assert.ifError(pair.server.err);
|
|
|
|
assert.ifError(pair.client.err);
|
|
|
|
|
|
|
|
return cleanup();
|
|
|
|
}));
|
|
|
|
}
|