utils: delete the TLS key-log scratch file after loading it - #5131
utils: delete the TLS key-log scratch file after loading it#5131KernelClint wants to merge 1 commit into
Conversation
AI-Assisted: yes (GPT-5.6-Cyber)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5131 +/- ##
==========================================
- Coverage 80.63% 80.12% -0.52%
==========================================
Files 390 390
Lines 96936 96937 +1
==========================================
- Hits 78168 77672 -496
- Misses 18768 19265 +497
🚀 New features to boost your workflow:
|
| filename = get_temp_file(keep=True) | ||
| try: | ||
| with open(filename, "wb") as fd: | ||
| fd.write(secrets_data) |
|
Two CI notes, both worth stating rather than leaving for a reviewer to work out. CodeQL flags The change makes the exposure shorter, not longer. Before, the file was created through The macOS TLS job failure looks unrelated to this change. It is |
A pcapng capture can carry Decryption Secrets Blocks holding TLS key material.
load_nss_keys()reads a key log from a path, so
scapy/utils.py:1994-2010writes each block out to a temporary file first.
get_temp_file()registers what it creates for deletion at interpreter exit(
scapy/utils.py:194-207,scapy/config.py:1255-1265). Nothing deletes it earlier, so the filesurvives the reader that made it. A capture with many secret blocks leaves one file per block for
the life of the process: a 1,991-byte gzipped capture containing 200 blocks left 200 files and
232,600 bytes on disk after the reader was closed. The same capture with only the block type
changed left none.
The file is needed only for the duration of one call, so the change scopes it to that:
keep=Truestops the exit-time registration; thefinallyremoves the file immediately. Valid keylogs load exactly as before.
The added regression reads a capture with several secret blocks and asserts the temporary directory
is unchanged afterwards. Without the source change it fails.
Performance was measured on one computer, before and after the fix: reading a capture took 147.6 µs
before and 150.7 µs after. Repeat runs moved by about 2%, so that difference is smaller than the
test can distinguish.