Repository navigation
fix(keys): parse traditional DSA private keys as DSA, not RSA - #45
Merged
Merged
Conversation
A traditional DSAPrivateKey and a PKCS#1 RSAPrivateKey both begin
SEQUENCE { INTEGER version, INTEGER ... }, so parse_priv_der took the
leading INTEGER as proof of RSA and reported every DSA key as RSA. A
1024-bit DSA key surfaced as rsa-weak-modulus / RSA-1024, and a 2048-bit
DSA key was silently cleared as a healthy RSA key, hiding that it is DSA.
Disambiguate by the PEM key-type label ("DSA PRIVATE KEY" vs "RSA
PRIVATE KEY"), falling back to the DER field count when unlabeled
(RSAPrivateKey has >=9 INTEGERs, DSAPrivateKey has 6). Handle PKCS#8 DSA
by OID. A traditional DSA key now parses as algo=DSA with the prime p's
bit length as the key size, and keys.cpp flags a DSA prime below the
2048-bit floor as dsa-weak-parameters (CWE-326) instead of an RSA type.
Adds a traditional-DSA fixture to test_keys asserting dsa-weak-parameters
and no rsa-* type.
Closes #44
This was referenced Nov 20, 2026
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
Traditional DSA private keys were misparsed as RSA.
parse_priv_dersaw the leadingINTEGER versionand assumed a PKCS#1 RSAPrivateKey, so aBEGIN DSA PRIVATE KEYwas reported withtype=rsa-weak-modulus,label=RSA-1024. The weakness verdict is coincidentally right for a 1024-bit key (weak either way), but the algorithm label is wrong, and a 2048-bit DSA key would be cleared as a healthy RSA key, hiding that it is DSA.Why it happened
DSAPrivateKey ::= SEQ { version, p, q, g, y, x }andRSAPrivateKey ::= SEQ { version, n, e, d, p, q, dp, dq, qinv }both startSEQ { INTEGER, INTEGER, ... }, so the leading INTEGER does not distinguish them. Only the RSA shape (second element INTEGER) and PKCS#8 (second element SEQUENCE, OID-gated) were handled; a traditional DSA key collided with the RSA branch. (Traditional EC is safe: its second element is an OCTET STRING.)Fix
parse_priv_dertakes the PEM key-type label and routes a traditional DSA key toalgo=DSA(key size from the primep), with a structural field-count fallback (RSAPrivateKey >=9 INTEGERs, DSAPrivateKey 6) when unlabeled. PKCS#8 DSA handled by OID.keys.cppgains adsa-weak-parameterscheck (p < 2048 medium, < 1024 high, CWE-326) so a weak DSA key is still flagged, under a DSA-specific type.Test
tests/test_keys.pygains a traditional-DSA fixture assertingdsa-weak-parametersand norsa-*type. Full suite green (ctest 15/15).Verified on a synthetic traditional 1024-bit DSA key: before,
rsa-weak-modulus / RSA-1024; after,dsa-weak-parameters / DSA-1024plus secretsPrivate key (DSA). A 1024-bit RSA key still reportsrsa-weak-modulus.Closes #44