forked from request/request
-
Notifications
You must be signed in to change notification settings - Fork 46
feat: Add support for capturing SSL session keys via keyLog
option
#105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3e63ab
feat: Add support for capturing SSL session keys via `keyLog` option
parthverma1 4e06eeb
chore: Switch to async method for appending keylog material
parthverma1 796586e
fix: Only attach keylog event once on the socket, and partition the a…
parthverma1 c775b46
chore: add/remove logging statement
parthverma1 8835643
chore: linter fixes
parthverma1 4cdac7c
fix: Failing HTTP agents tests
parthverma1 6ba217d
chore: ignore 'fs/promises' in browser tests bundle
parthverma1 7fc166a
chore: rename option `keyLog` to `sslKeyLogFile`
parthverma1 b581f5b
chore: test for sslKeyLogFile option
parthverma1 a15cc38
chore: lint
parthverma1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
'use strict' | ||
|
||
var server = require('./server') | ||
var request = require('../index') | ||
var fs = require('fs') | ||
var path = require('path') | ||
var os = require('os') | ||
var tape = require('tape') | ||
|
||
var s = server.createSSLServer() | ||
var keylogFilePath = path.join(os.tmpdir(), 'test-keylog-' + Date.now() + '.txt') | ||
|
||
tape('setup', function (t) { | ||
s.listen(0, function () { | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('sslKeyLogFile - file creation and content', function (t) { | ||
// Clean up file if it exists from a previous test run | ||
if (fs.existsSync(keylogFilePath)) { | ||
fs.unlinkSync(keylogFilePath) | ||
} | ||
|
||
s.on('/keylogtest', function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
res.end('success') | ||
}) | ||
|
||
request({ | ||
url: s.url + '/keylogtest', | ||
rejectUnauthorized: false, | ||
sslKeyLogFile: keylogFilePath | ||
}, function (err, res, body) { | ||
t.equal(err, null, 'request should not error') | ||
t.equal(body, 'success', 'should receive correct response') | ||
|
||
// Give a small delay to ensure the keylog file has been written | ||
setTimeout(function () { | ||
// Check if file was created | ||
var fileExists = fs.existsSync(keylogFilePath) | ||
t.ok(fileExists, 'keylog file should be created') | ||
|
||
if (fileExists) { | ||
// Check if file contains content | ||
var content = fs.readFileSync(keylogFilePath, 'utf8') | ||
t.ok(content.length > 0, 'keylog file should contain content') | ||
t.ok(content.includes('CLIENT_HANDSHAKE_TRAFFIC_SECRET') || | ||
content.includes('SERVER_HANDSHAKE_TRAFFIC_SECRET') || | ||
content.includes('CLIENT_TRAFFIC_SECRET') || | ||
content.includes('SERVER_TRAFFIC_SECRET'), | ||
'keylog file should contain TLS key material') | ||
} | ||
|
||
t.end() | ||
}, 100) | ||
}) | ||
}) | ||
|
||
tape('sslKeyLogFile - multiple requests append to same file', function (t) { | ||
// Use the file from the previous test | ||
var initialSize = 0 | ||
if (fs.existsSync(keylogFilePath)) { | ||
initialSize = fs.statSync(keylogFilePath).size | ||
} | ||
|
||
s.on('/keylogtest2', function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
res.end('success2') | ||
}) | ||
|
||
request({ | ||
url: s.url + '/keylogtest2', | ||
rejectUnauthorized: false, | ||
sslKeyLogFile: keylogFilePath | ||
}, function (err, res, body) { | ||
t.equal(err, null, 'second request should not error') | ||
t.equal(body, 'success2', 'should receive correct response from second request') | ||
|
||
setTimeout(function () { | ||
if (fs.existsSync(keylogFilePath)) { | ||
var newSize = fs.statSync(keylogFilePath).size | ||
// The file size should be at least as large as before (might be same if socket is reused) | ||
t.ok(newSize >= initialSize, 'keylog file should have content from multiple requests') | ||
} | ||
|
||
t.end() | ||
}, 100) | ||
}) | ||
}) | ||
|
||
tape('cleanup', function (t) { | ||
// Clean up the keylog file | ||
if (fs.existsSync(keylogFilePath)) { | ||
fs.unlinkSync(keylogFilePath) | ||
} | ||
|
||
s.close(function () { | ||
t.end() | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.