Repository navigation
fix(keys): stop reading DH parameters, signatures and other non-key DER as RSA - #47
Open
bitwize-music wants to merge 1 commit into
Open
bitwize-music wants to merge 1 commit into
bitwize-music wants to merge 1 commit into
Conversation
…ER as RSA
parse_pub_der fell back to a bare PKCS#1 RSAPublicKey for any SEQUENCE
whose first two elements are INTEGERs. Every PEM block that is not a
CERTIFICATE or a private key reached it, as did any whole-file buffer
starting with 0x30. But SEQ { INTEGER, INTEGER } is also a PKCS#3
DHParameter { p, g } and an (EC)DSA signature { r, s }, and DSA and X9.42
DH parameters, a traditional DSA public key, an SSL session and a
multi-prime RSAPrivateKey begin with it. So a bundled dh2048.pem was
reported as an RSA-2048 key with rsa-even-exponent (g = 2). A DER ECDSA
signature file became an RSA-256 key with rsa-tiny-modulus. An SSL
session's version field became a 1-bit modulus flagged roca-key. Signature
r values that shared a small factor were reported as shared-prime.
Pass the PEM label to parse_pub_der, as parse_priv_der has taken it since
nmatt0#45. A bare RSAPublicKey is read only under "RSA PUBLIC KEY" or "PUBLIC
KEY". An SPKI is still accepted under any label, because its OID names the
key type. Unlabeled whole-file DER is read as RSA only when the values fit
RSA: exactly two INTEGERs, n >= 512 bits, and e odd and < 2^256. An
unlabeled two-field DH group with an odd generator (3, 5) still passes,
since telling its prime from an RSA modulus needs a primality test.
test_keys gains 18 non-key fixtures and asserts that none produces a
finding: DH, X9.42 DH and DSA parameters, a traditional DSA public key, an
SSL session, a DH PEM string inside a binary, DER DH, DSA and session
blobs, and P-256/384/521 and DSA signature files. It also checks that
unlabeled bare PKCS#1 keys (1024-bit e=65537, 1024-bit e=3, 512-bit) are
still read as RSA. The unit tests check that the same SEQ body is a key
under RSA PUBLIC KEY but not under DH PARAMETERS, and that an unlabeled
17-bit "modulus" is not a key.
Closes nmatt0#46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 key-weakness pass reported ASN.1 structures that are not keys as RSA public keys. Every bundled dhparam file (
DH PARAMETERS) producedrsa-even-exponent[high]. DER (EC)DSA signature files producedrsa-tiny-modulusand cross-fileshared-prime. SSL session files producedroca-keyon a 1-bit "modulus". #46 has the repro, the full list of affected structures, and prevalence data.Why it happened
parse_pub_derfell back to a bare PKCS#1RSAPublicKeyfor any SEQUENCE that starts with two INTEGERs. Every PEM block other thanCERTIFICATE/*PRIVATE KEYreached it, and so did any whole-file buffer starting with0x30.SEQ { INTEGER, INTEGER }is also a PKCS#3DHParameter {p, g}and an(EC)DSA-Sig-Value {r, s}. DSA and X9.42 DH parameters, a traditionalDSAPublicKey, anSSL_SESSIONand a multi-primeRSAPrivateKeyall begin with it.Fix
parse_pub_dertakes the PEM label, asparse_priv_derhas since fix(keys): parse traditional DSA private keys as DSA, not RSA #45. A bareRSAPublicKeyis read only underRSA PUBLIC KEY/PUBLIC KEY. Under any other label only an SPKI is accepted, since its OID names the key type. SoDH PARAMETERS,DSA PARAMETERS,SSL SESSION PARAMETERS,DSA PUBLIC KEYand similar blocks yield no key.plausible_bare_rsarequires the values to fit RSA:RSA PUBLIC KEY/PUBLIC KEY, SPKI, certificates, private keys and SSH keys.Test
tests/test_keys.py: 18 non-key fixtures must produce no finding. They cover 2- and 3-field DH, X9.42 DH, DSA parameters, a traditional DSA public key and an SSL session (PEM and DER), a DH PEM string inside a binary, and P-256/384/521 and DSA signature files with forced even r values. Unlabeled bare PKCS#1 keys (1024-bit e=65537, 1024-bit e=3, 512-bit) must still be flagged. On master the fixtures produce 38 findings and the test fails; it passes here.tests/unit/unit_tests.cpp: the sameSEQ { 65537, 65537 }body is a key underRSA PUBLIC KEYand not underDH PARAMETERS. Unlabeled, it is not a key.test_keysfail.-DMT_SANITIZE=ON. 7.5k mutated DER blobs ran through the ASan build with no report.DH/X9.42 DH/DSA/SSL SESSION PARAMETERS, or DER dhparams). The remaining RSA findings all come from certificates,PUBLIC KEY/PRIVATE KEYPEM, SSH keys, or DER SPKI and certs, except one OpenSSL test file that is the documented generator-5 case.Closes #46
🤖 Generated with Claude Code