Skip to content

Refuse to sign with RSA keys of sizes the RFCs rule out - #194

Merged
NelsonVides merged 2 commits into
mainfrom
sign-rsa-key-sizes
Nov 16, 2026
Merged

NelsonVides merged 2 commits into
mainfrom
sign-rsa-key-sizes

Conversation

@NelsonVides

Copy link
Copy Markdown
Contributor

RFC 3110 §3 and RFC 5702 §2 have an RSA modulus 512 to 4096 bits long, or 1024 to 4096 for RSA/SHA-512, and RFC 3110 §2 an exponent of at most 4096 bits. In 6.0.0, a DNSKEY with any other key is refused when loaded, verify_rrsig/4 verifies nothing with it, and dnskey_public_key/2 lays out none for it, but signing still signed with it, making RRSIGs no DNSKEY verifying them could be published for.

Signing with an RSA key now lays out its public half as dnskey_public_key/2 does, as signing with a DSA key already did, and raises what that raises:

Key main now
4104-bit modulus, any RSA algorithm signs raises {badarg, {rsa_modulus_bits, 4104}}
1016-bit modulus, RSA/SHA-512 signs raises {badarg, {rsa_modulus_bits, 1016}}
other than [E, N, D] or those and the CRT's five crypto's {badarg, {"pkey.c", 506}, "Couldn't get RSA private key"} or {error, {"pkey.c", 884}, "Can't EVP_PKEY_sign"} raises {badarg, key_shape}
512 to 4096 bits, 1024 to 4096 for RSA/SHA-512, of 3 or 8 numbers signs signs

erldns signs with the 8 numbers its zone decoder takes from a PEM key, which sign as before. sign_rrset/6's docs now list these errors, and none of them, nor its stacktrace, holds the key, as crypto's did not either.

Tests: sign_with_rsa_key_rfcs_rule_out_raises signs with keys of 512, 1016 and 1024 bits where the RFCs allow them, the same with the CRT's numbers as without, and refuses 4104 bits for every RSA algorithm and 1016 for RSA/SHA-512, exactly where dnskey_public_key/2 refuses them; and it refuses seven key shapes without the key in the error or the stacktrace. rsa_key_rfc3110_rules_out_verifies_nothing signed with a 768-bit key for RSA/SHA-512 to see that it verifies nothing; crypto signs that over signed data built by hand now. Taking out the size check or the shape check makes the new test fail.

Part of #169 (S3). DSA keys were already held to RFC 2536 when signing.

RFC 3110 and RFC 5702 have an RSA modulus 512 to 4096 bits long, or 1024
to 4096 for RSA/SHA-512, and an exponent of at most 4096 bits. A DNSKEY
with any other key is refused when loaded and verifies nothing, but
signing still signed with one, making RRSIGs no DNSKEY verifying them
could be published for.

Signing with an RSA key now lays out its public half as
dnskey_public_key/2 does, as signing with a DSA key already did, and
raises {badarg, {rsa_modulus_bits, Bits}} or
{badarg, {rsa_exponent_bits, Bits}}, and {badarg, key_shape} for a key
of other than [E, N, D] or those and the CRT's five, where crypto raised
its own errors. None holds the key.

The test that a 768-bit RSA/SHA-512 key verifies nothing has crypto sign
over signed data built by hand, as signing refuses that key.
@NelsonVides NelsonVides added the bug Code defect or incorrect behavior label Nov 16, 2026
@NelsonVides NelsonVides self-assigned this Nov 16, 2026
# Conflicts:
#	CHANGELOG.md
@NelsonVides
NelsonVides merged commit 68b1d52 into main Nov 16, 2026
6 checks passed
@NelsonVides
NelsonVides deleted the sign-rsa-key-sizes branch November 16, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Code defect or incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant