| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f15a3b0 commit 01fa18c
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -679,6 +679,15 @@ added: v4.0.0 | |||
| 679 | 679 | Specify an alternative default TLS cipher list. Requires Node.js to be built | |
| 680 | 680 | with crypto support (default). | |
| 681 | 681 | ||
| 682 | + ### `--tls-keylog=file` | ||
| 683 | + <!-- YAML | ||
| 684 | + added: REPLACEME | ||
| 685 | + --> | ||
| 686 | + | ||
| 687 | + Log TLS key material to a file. The key material is in NSS `SSLKEYLOGFILE` | ||
| 688 | + format and can be used by software (such as Wireshark) to decrypt the TLS | ||
| 689 | + traffic. | ||
| 690 | + | ||
| 682 | 691 | ### `--tls-max-v1.2` | |
| 683 | 692 | <!-- YAML | |
| 684 | 693 | added: v12.0.0 | |
@@ -1073,6 +1082,7 @@ Node.js options that are allowed are: | |||
| 1073 | 1082 | * `--throw-deprecation` | |
| 1074 | 1083 | * `--title` | |
| 1075 | 1084 | * `--tls-cipher-list` | |
| 1085 | + * `--tls-keylog` | ||
| 1076 | 1086 | * `--tls-max-v1.2` | |
| 1077 | 1087 | * `--tls-max-v1.3` | |
| 1078 | 1088 | * `--tls-min-v1.0` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -302,6 +302,11 @@ Specify process.title on startup. | |||
| 302 | 302 | Specify an alternative default TLS cipher list. | |
| 303 | 303 | Requires Node.js to be built with crypto support. (Default) | |
| 304 | 304 | . | |
| 305 | + .It Fl -tls-keylog Ns = Ns Ar file | ||
| 306 | + Log TLS key material to a file. The key material is in NSS SSLKEYLOGFILE | ||
| 307 | + format and can be used by software (such as Wireshark) to decrypt the TLS | ||
| 308 | + traffic. | ||
| 309 | + . | ||
| 305 | 310 | .It Fl -tls-max-v1.2 | |
| 306 | 311 | Set default maxVersion to 'TLSv1.2'. Use to disable support for TLSv1.3. | |
| 307 | 312 | . | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,8 @@ const { | |||
| 60 | 60 | const { getOptionValue } = require('internal/options'); | |
| 61 | 61 | const { validateString } = require('internal/validators'); | |
| 62 | 62 | const traceTls = getOptionValue('--trace-tls'); | |
| 63 | + const tlsKeylog = getOptionValue('--tls-keylog'); | ||
| 64 | + const { appendFile } = require('fs'); | ||
| 63 | 65 | const kConnectOptions = Symbol('connect-options'); | |
| 64 | 66 | const kDisableRenegotiation = Symbol('disable-renegotiation'); | |
| 65 | 67 | const kErrorEmitted = Symbol('error-emitted'); | |
@@ -560,6 +562,8 @@ TLSSocket.prototype._destroySSL = function _destroySSL() { | |||
| 560 | 562 | }; | |
| 561 | 563 | ||
| 562 | 564 | // Constructor guts, arbitrarily factored out. | |
| 565 | + let warnOnTlsKeylog = true; | ||
| 566 | + let warnOnTlsKeylogError = true; | ||
| 563 | 567 | TLSSocket.prototype._init = function(socket, wrap) { | |
| 564 | 568 | const options = this._tlsOptions; | |
| 565 | 569 | const ssl = this._handle; | |
@@ -643,6 +647,24 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 643 | 647 | } | |
| 644 | 648 | } | |
| 645 | 649 | ||
| 650 | + if (tlsKeylog) { | ||
| 651 | + if (warnOnTlsKeylog) { | ||
| 652 | + warnOnTlsKeylog = false; | ||
| 653 | + process.emitWarning('Using --tls-keylog makes TLS connections insecure ' + | ||
| 654 | + 'by writing secret key material to file ' + tlsKeylog); | ||
| 655 | + ssl.enableKeylogCallback(); | ||
| 656 | + this.on('keylog', (line) => { | ||
| 657 | + appendFile(tlsKeylog, line, { mode: 0o600 }, (err) => { | ||
| 658 | + if (err && warnOnTlsKeylogError) { | ||
| 659 | + warnOnTlsKeylogError = false; | ||
| 660 | + process.emitWarning('Failed to write TLS keylog (this warning ' + | ||
| 661 | + 'will not be repeated): ' + err); | ||
| 662 | + } | ||
| 663 | + }); | ||
| 664 | + }); | ||
| 665 | + } | ||
| 666 | + } | ||
| 667 | + | ||
| 646 | 668 | ssl.onerror = onerror; | |
| 647 | 669 | ||
| 648 | 670 | // If custom SNICallback was given, or if | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -506,6 +506,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 506 | 506 | ||
| 507 | 507 | AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvironment); | |
| 508 | 508 | ||
| 509 | + AddOption("--tls-keylog", | ||
| 510 | + "log TLS decryption keys to named file for traffic analysis", | ||
| 511 | + &EnvironmentOptions::tls_keylog, kAllowedInEnvironment); | ||
| 512 | + | ||
| 509 | 513 | AddOption("--tls-min-v1.0", | |
| 510 | 514 | "set default TLS minimum to TLSv1.0 (default: TLSv1.2)", | |
| 511 | 515 | &EnvironmentOptions::tls_min_v1_0, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,6 +161,7 @@ class EnvironmentOptions : public Options { | |||
| 161 | 161 | bool tls_min_v1_3 = false; | |
| 162 | 162 | bool tls_max_v1_2 = false; | |
| 163 | 163 | bool tls_max_v1_3 = false; | |
| 164 | + std::string tls_keylog; | ||
| 164 | 165 | ||
| 165 | 166 | std::vector<std::string> preload_modules; | |
| 166 | 167 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,57 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + if (!common.hasCrypto) common.skip('missing crypto'); | ||
| 4 | + const fixtures = require('../common/fixtures'); | ||
| 5 | + | ||
| 6 | + // Test --tls-keylog CLI flag. | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const path = require('path'); | ||
| 10 | + const fs = require('fs'); | ||
| 11 | + const { fork } = require('child_process'); | ||
| 12 | + | ||
| 13 | + if (process.argv[2] === 'test') | ||
| 14 | + return test(); | ||
| 15 | + | ||
| 16 | + const tmpdir = require('../common/tmpdir'); | ||
| 17 | + tmpdir.refresh(); | ||
| 18 | + const file = path.resolve(tmpdir.path, 'keylog.log'); | ||
| 19 | + | ||
| 20 | + const child = fork(__filename, ['test'], { | ||
| 21 | + execArgv: ['--tls-keylog=' + file] | ||
| 22 | + }); | ||
| 23 | + | ||
| 24 | + child.on('close', common.mustCall((code, signal) => { | ||
| 25 | + assert.strictEqual(code, 0); | ||
| 26 | + assert.strictEqual(signal, null); | ||
| 27 | + const log = fs.readFileSync(file, 'utf8'); | ||
| 28 | + assert(/SECRET/.test(log)); | ||
| 29 | + })); | ||
| 30 | + | ||
| 31 | + function test() { | ||
| 32 | + const { | ||
| 33 | + connect, keys | ||
| 34 | + } = require(fixtures.path('tls-connect')); | ||
| 35 | + | ||
| 36 | + connect({ | ||
| 37 | + client: { | ||
| 38 | + checkServerIdentity: (servername, cert) => { }, | ||
| 39 | + ca: `${keys.agent1.cert}\n${keys.agent6.ca}`, | ||
| 40 | + }, | ||
| 41 | + server: { | ||
| 42 | + cert: keys.agent6.cert, | ||
| 43 | + key: keys.agent6.key | ||
| 44 | + }, | ||
| 45 | + }, common.mustCall((err, pair, cleanup) => { | ||
| 46 | + if (pair.server.err) { | ||
| 47 | + console.trace('server', pair.server.err); | ||
| 48 | + } | ||
| 49 | + if (pair.client.err) { | ||
| 50 | + console.trace('client', pair.client.err); | ||
| 51 | + } | ||
| 52 | + assert.ifError(pair.server.err); | ||
| 53 | + assert.ifError(pair.client.err); | ||
| 54 | + | ||
| 55 | + return cleanup(); | ||
| 56 | + })); | ||
| 57 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments