]> git.ipfire.org Git - thirdparty/bind9.git/commit
Reject RSA DNSKEYs with degenerate modulus at parse time
authorOndřej Surý <ondrej@isc.org>
Thu, 30 Apr 2026 09:55:14 +0000 (11:55 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 30 Apr 2026 13:50:32 +0000 (15:50 +0200)
commit045d5d04559a41b71e22a6e06b132c2851354e9c
treea2c4125791f3f95ce1177797708f526ae1a7d770
parent62ced63e2232c26d4efa93a7bbd8cc0e21627e3d
Reject RSA DNSKEYs with degenerate modulus at parse time

The wire-format RSA DNSKEY parser used the residual rdata length after
the exponent as the modulus length, with no positive lower bound.  A
crafted DNSKEY whose declared exponent length consumed the whole buffer
produced n = 0; the BN_bin2bn(_, 0, _) returned a non-NULL BIGNUM, the
NULL-check passed, and dnssec-importkey -f wrote out a "valid" key with
no key material.  RSASHA1 also bypassed the algorithm-specific lower
bound in opensslrsa_createctx (which only checks an upper bound for the
SHA1 algorithms), so the degenerate key reached the verify path with
whatever behaviour the linked OpenSSL exhibits for n = 0.

Add OPENSSLRSA_MIN_MODULUS_BITS = 512 (the lowest legitimate modulus
across the RSA DNSSEC algorithms per RFC 5702) and reject smaller
moduli at parse time in opensslrsa_fromdns, opensslrsa_parse, and
opensslrsa_fromlabel — the same three load paths where the existing
exponent upper-bound check lives.

Assisted-by: Claude:claude-opus-4-7
lib/dns/opensslrsa_link.c
tests/dns/rsa_test.c