Skip to content

fix(keys): parse traditional DSA private keys as DSA, not RSA - #45

Merged
nmatt0 merged 1 commit into
masterfrom
fix/dsa-privkey-misparse
Nov 12, 2026
Merged

nmatt0 merged 1 commit into
masterfrom
fix/dsa-privkey-misparse

Conversation

@nmatt0

@nmatt0 nmatt0 commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What

Traditional DSA private keys were misparsed as RSA. parse_priv_der saw the leading INTEGER version and assumed a PKCS#1 RSAPrivateKey, so a BEGIN DSA PRIVATE KEY was reported with type=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 } and RSAPrivateKey ::= SEQ { version, n, e, d, p, q, dp, dq, qinv } both start SEQ { 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_der takes the PEM key-type label and routes a traditional DSA key to algo=DSA (key size from the prime p), with a structural field-count fallback (RSAPrivateKey >=9 INTEGERs, DSAPrivateKey 6) when unlabeled. PKCS#8 DSA handled by OID.
  • keys.cpp gains a dsa-weak-parameters check (p < 2048 medium, < 1024 high, CWE-326) so a weak DSA key is still flagged, under a DSA-specific type.
  • RSA path unchanged.

Test

tests/test_keys.py gains a traditional-DSA fixture asserting dsa-weak-parameters and no rsa-* 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-1024 plus secrets Private key (DSA). A 1024-bit RSA key still reports rsa-weak-modulus.

Closes #44

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
@nmatt0
nmatt0 merged commit 8dcf577 into master Nov 12, 2026
4 checks passed
@nmatt0
nmatt0 deleted the fix/dsa-privkey-misparse branch November 12, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

keyweak: traditional DSA private keys are misparsed and reported as RSA

1 participant