utils: delete the TLS key-log scratch file after loading it - #5131
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5131 +/- ##
==========================================
- Coverage 80.81% 80.80% -0.01%
==========================================
Files 390 390
Lines 96966 96965 -1
==========================================
- Hits 78364 78355 -9
- Misses 18602 18610 +8
🚀 New features to boost your workflow:
|
|
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 |
|
This PR has conflicts, sorry. I think you don't need tests for this one |
The Decryption Secrets Block was written to a temporary file only so that load_nss_keys() could open it by path. Split the parsing out so the key log is never written to disk. load_nss_keys(filename) is unchanged for callers. AI-Assisted: yes (GPT-5.6-Cyber)
f1ce210 to
84ac6c4
Compare
|
Rebased, and the tests are gone as you suggested. It also does something different now: the key log never reaches the disk at all. |
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.