fix: require a body + matching END for PEM private-key findings - #27
Merged
Merged
Conversation
The secrets pass reported a private key from a bare PEM begin-header alone. Crypto libraries (mbedtls, OpenSSL, wolfSSL) embed the PEM label strings back to back in .rodata with no key body between them, so every such binary produced false positives, and a PUBLIC KEY label sitting next to a private-key end marker was even classified as a private key. Gate match_pem_private on three properties a real key has that a bare label does not: the begin header's own type must be a private-key type (never PUBLIC KEY / CERTIFICATE), at least 64 base64 body chars must follow, and the block must close with the matching end marker of the same type. Bounded 64 KiB window, all reads through Reader; the finding still reports the header marker, not key bytes. Add test_pem_label_false_positives (bare header; begin-then-end with no body; PUBLIC KEY with a body; begin/end type mismatch; and the exact NUL-separated mbedtls .rodata label layout). Update the positive PEM tests and the id_rsa integration fixture to carry a realistic body. Fixes #26
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
The secrets pass reported a
private-keyfinding from a bare PEM begin-header with no key body. Crypto libraries (mbedtls, OpenSSL, wolfSSL) embed the PEM label strings back to back in.rodata, so any binary carrying a TLS library produced false positives. APUBLIC KEYlabel sitting next to a private-key end marker was even classified as a private key.Fixes #26.
Fix
match_pem_privatenow gates on three properties a real key has that a bare label string does not:PUBLIC KEY/CERTIFICATE);Bounded 64 KiB scan window, all reads go through
Reader, and the finding still reports the header line as a marker (never key bytes).Tests
test_pem_label_false_positives: bare header; begin-then-end with no body; aPUBLIC KEYblock with a real body; begin/end type mismatch; and the exact NUL-separated label layout a TLS library packs into.rodata.id_rsaintegration fixture to carry a realistic multi-line body (they previously asserted on header-only stubs).Verification
/etc/shadowhash) are unaffected.