-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: cli option to enable TLS key logging to file
Debugging HTTPS or TLS connections from a Node.js app with (for example) Wireshark is unreasonably difficult without the ability to get the TLS key log. In theory, the application can be modified to use the `'keylog'` event directly, but for complex apps, or apps that define there own HTTPS Agent (like npm), this is unreasonably difficult. Use of the option triggers a warning to be emitted so the user is clearly notified of what is happening and its effect. PR-URL: #30055 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
f15a3b0
commit 01fa18c
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'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 path = require('path'); | ||
const fs = require('fs'); | ||
const { fork } = require('child_process'); | ||
|
||
if (process.argv[2] === 'test') | ||
return test(); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
const file = path.resolve(tmpdir.path, 'keylog.log'); | ||
|
||
const child = fork(__filename, ['test'], { | ||
execArgv: ['--tls-keylog=' + file] | ||
}); | ||
|
||
child.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
const log = fs.readFileSync(file, 'utf8'); | ||
assert(/SECRET/.test(log)); | ||
})); | ||
|
||
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, | ||
key: keys.agent6.key | ||
}, | ||
}, 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(); | ||
})); | ||
} |