Skip to content

Check the version of DSA and EC private keys - #826

Merged
sjaeckel merged 1 commit into
libtom:developfrom
dlazobnaKocka:check-dsa-ecc-key-version
Nov 18, 2026
Merged

sjaeckel merged 1 commit into
libtom:developfrom
dlazobnaKocka:check-dsa-ecc-key-version

Conversation

@dlazobnaKocka

@dlazobnaKocka dlazobnaKocka commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Same problem as #803 (fixed in #814), this time for DSA and EC.

dsa_import() and ecc_import_openssl() decode the version of a DSAPrivateKey or ECPrivateKey but never check it, so a key with any version is accepted. The key itself is still validated, so this is about strict parsing, not a crash.

DSAPrivateKey now has to be version 0 and ECPrivateKey version 1, otherwise the import returns CRYPT_INVALID_PACKET. For EC both the curve OID form and the explicit curve form are checked.

The tests flip the version byte in the existing DSA and EC test keys. They fail on develop and pass with the fix.

Checklist

  • tests are added or updated
  • if this fixes something: added a Fixes: tag to the commit message

dsa_import() and ecc_import_openssl() decoded the version of a
DSAPrivateKey or ECPrivateKey but never checked it, so a key with
any version was accepted. This is the same problem as
libtom#803 for RSA.

DSAPrivateKey has to be version 0 and ECPrivateKey version 1.
Return CRYPT_INVALID_PACKET otherwise.

Fixes: ed6897d ("DSA private keys are being exported to a compatible with OpenSSL and GnuTLS format.")
Fixes: 05d397d ("ECC improved import/export")
@karel-m

karel-m commented Nov 17, 2026

Copy link
Copy Markdown
Member

Looks good to me

@sjaeckel
sjaeckel merged commit 4840702 into libtom:develop Nov 18, 2026
202 checks passed
@dlazobnaKocka
dlazobnaKocka deleted the check-dsa-ecc-key-version branch November 18, 2026 13:10
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.

3 participants