Documentation
¶
Index ¶
- Constants
- Variables
- func ComputeNSEC3Hash(name string, algorithm uint8, iterations uint16, salt []byte) ([]byte, error)
- func HasType(nsec3 *dns.NSEC3Record, rrtype uint16) bool
- func NSEC3HashToString(hash []byte) string
- func VerifyClosestEncloser(qname string, nsec3Records []*dns.NSEC3Record) (string, error)
- func VerifyDS(dnskey *dns.DNSKEYRecord, ds *dns.DSRecord, ownerName string) bool
- func VerifyNSEC3Denial(qname string, nsec3Records []*dns.NSEC3Record) (bool, error)
- func VerifyNSEC3Denial5155(qname string, qtype uint16, rcode uint8, records []NSEC3RecordWithOwner) (bool, error)
- func VerifyNSEC3DenialDSAbsent(childZone string, records []NSEC3RecordWithOwner) (bool, error)
- func VerifyNSEC3DenialFull(qname string, nsec3Records []NSEC3RecordWithOwner) (bool, error)
- func VerifyNSECDenial(qname string, qtype uint16, rcode uint8, records []NSECRecordWithOwner) (bool, error)
- func VerifyRRSIG(rrset []dns.ResourceRecord, rrsig *dns.RRSIGRecord, dnskey *dns.DNSKEYRecord) error
- type FailureReason
- type NSEC3RecordWithOwner
- type NSECRecordWithOwner
- type NTAStore
- func (s *NTAStore) Add(zone string, expiry time.Time, reason string)
- func (s *NTAStore) Cleanup() int
- func (s *NTAStore) List() []NegativeTrustAnchor
- func (s *NTAStore) Match(qname string) (NegativeTrustAnchor, bool)
- func (s *NTAStore) Remove(zone string) bool
- func (s *NTAStore) SetClock(fn func() time.Time)
- type NegativeTrustAnchor
- type Querier
- type ValidationResult
- type ValidationStep
- type Validator
- func (v *Validator) AllowSHA1(allow bool)
- func (v *Validator) NTAMatches() int64
- func (v *Validator) NTAStore() *NTAStore
- func (v *Validator) SHA1Allowed() bool
- func (v *Validator) SetNTAStore(store *NTAStore)
- func (v *Validator) ValidateResponse(response *dns.Message, qname string, qtype uint16) ValidationResult
- func (v *Validator) ValidateResponseDetailed(response *dns.Message, qname string, qtype uint16) (ValidationResult, []ValidationStep)
- func (v *Validator) ValidateResponseWithReason(response *dns.Message, qname string, qtype uint16) (ValidationResult, FailureReason)
Constants ¶
const MaxNSEC3Iterations = 100
MaxNSEC3Iterations is the hard ceiling on the NSEC3 iteration count this resolver will honour, per RFC 9276 §3.2 (August 2022): "validating resolvers SHOULD return an insecure response when processing NSEC3 records with iterations larger than 100." High iteration counts give no real cryptographic benefit but let an attacker amplify CPU cost per query (NSEC3 hash-walk DoS) and slow down legitimate validation. Aligns with BIND 9.18+ and Unbound 1.16+ defaults.
Variables ¶
var RootDSRecords = []dns.DSRecord{ { KeyTag: 20326, Algorithm: dns.AlgRSASHA256, DigestType: dns.DigestSHA256, Digest: hexDecode("E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D"), }, { KeyTag: 38696, Algorithm: dns.AlgRSASHA256, DigestType: dns.DigestSHA256, Digest: hexDecode("683D2D0ACB8C9B712A1948B27F741219298D0A450D612C483AF444A4C0FB2B16"), }, }
RootDSRecords contains the trust anchors for the DNS root zone. These are the well-known IANA root KSK trust anchors used to anchor the DNSSEC chain of trust.
Key tag 20326: Root KSK (2017), RSA/SHA-256 Key tag 38696: Root KSK (2024), RSA/SHA-256 — added per audit H-7 to avoid a forced validation outage at the next root KSK rollover (the resolver intentionally bypasses fallback on DNSSEC failure, so missing the new anchor would take the entire resolver dark). See: https://data.iana.org/root-anchors/root-anchors.xml
Functions ¶
func ComputeNSEC3Hash ¶
ComputeNSEC3Hash computes the NSEC3 hash for a domain name. Algorithm 1 is SHA-1 (the only defined algorithm per RFC 5155). The result is the raw hash bytes (not base32-encoded).
func HasType ¶
func HasType(nsec3 *dns.NSEC3Record, rrtype uint16) bool
HasType checks whether the NSEC3 type bitmap includes the given RR type.
func NSEC3HashToString ¶
NSEC3HashToString encodes raw NSEC3 hash bytes to the base32hex string representation used in NSEC3 owner names.
func VerifyClosestEncloser ¶
func VerifyClosestEncloser(qname string, nsec3Records []*dns.NSEC3Record) (string, error)
VerifyClosestEncloser finds the closest encloser for the queried name by looking for an NSEC3 record whose hash matches a parent of qname. Returns the closest encloser name if found.
func VerifyDS ¶
VerifyDS checks if a DNSKEY matches a DS record by computing the DS digest over the canonical owner name + DNSKEY RDATA and comparing it to the DS digest. The ownerName is the domain name that owns the DNSKEY (e.g., "example.com.").
func VerifyNSEC3Denial ¶
func VerifyNSEC3Denial(qname string, nsec3Records []*dns.NSEC3Record) (bool, error)
VerifyNSEC3Denial verifies that a queried name falls within an NSEC3 hash gap, proving the name does not exist (NXDOMAIN) or the type does not exist (NODATA). Returns true if the denial proof is valid.
func VerifyNSEC3Denial5155 ¶ added in v0.6.12
func VerifyNSEC3Denial5155(qname string, qtype uint16, rcode uint8, records []NSEC3RecordWithOwner) (bool, error)
VerifyNSEC3Denial5155 verifies a NXDOMAIN or NODATA denial proof per RFC 5155 §8.4–8.7 and RFC 6840 §4.8. Unlike the loose VerifyNSEC3DenialFull (which only checks that some NSEC3 covers H(qname) and is correct only for the next-closer-coverage step in isolation), this function requires the full three-record proof for NXDOMAIN:
- Closest-encloser MATCH: an NSEC3 whose owner hash equals H(CE), where CE is the deepest ancestor of qname proven to exist.
- Next-closer COVER: an NSEC3 whose interval contains H(next_closer), where next_closer is CE's immediate child label on the path to qname.
- Wildcard-at-CE COVER: an NSEC3 whose interval contains H(*.CE), proving that the synthetic wildcard does not exist either.
For NODATA the function accepts either:
- Direct NODATA: an NSEC3 matching H(qname) whose type bitmap omits qtype (and CNAME).
- Wildcard NODATA: CE-match + NC-cover + wildcard-MATCH whose bitmap omits qtype.
Opt-out semantics (RFC 5155 §6): if the next-closer-covering NSEC3 has the opt-out flag set, the next closer name could be an unsigned delegation, and the NXDOMAIN proof is therefore inconclusive (return false). A caller receiving false here treats the response as Bogus (signed denial without a verifiable proof) rather than Secure NXDOMAIN.
Without this strict layering, a forged single covering NSEC3 over H(qname) can fake NXDOMAIN for any name whose true closest-encloser differs from what the attacker claims — exactly the proof-substitution attack RFC 5155 is designed to prevent.
func VerifyNSEC3DenialDSAbsent ¶ added in v0.6.12
func VerifyNSEC3DenialDSAbsent(childZone string, records []NSEC3RecordWithOwner) (bool, error)
VerifyNSEC3DenialDSAbsent verifies an NSEC3 proof that the queried zone has no DS record at its parent — required for authenticating "insecure delegation" responses (RFC 5155 §10.4). Three forms are accepted:
- NSEC3 at H(childZone) with DS absent from the bitmap (and NS present, so we're at a real delegation point rather than a synthesized empty name).
- Opt-out next-closer-cover: the NC-covering NSEC3 has the opt-out flag set, asserting that the child is an unsigned delegation that the parent zone has not enumerated.
The function returns true only when one of these proofs holds. A caller that gets `true` from this function may safely treat the delegation as Insecure; `false` means the denial of DS is unproven and the response must NOT downgrade a previously-Secure chain to Insecure.
func VerifyNSEC3DenialFull ¶
func VerifyNSEC3DenialFull(qname string, nsec3Records []NSEC3RecordWithOwner) (bool, error)
VerifyNSEC3DenialFull verifies NSEC3 denial with full owner hash information. This is the proper implementation that checks hash ranges correctly.
func VerifyNSECDenial ¶ added in v0.6.4
func VerifyNSECDenial(qname string, qtype uint16, rcode uint8, records []NSECRecordWithOwner) (bool, error)
VerifyNSECDenial verifies an NSEC denial proof for a NODATA or NXDOMAIN response. Returns true if the records authenticate the negative answer.
Three forms are accepted:
NODATA (RFC 4035 §5.4) — an NSEC at owner == qname whose type bitmap does not include qtype or CNAME. A delegation-style NSEC (NS bit set without SOA) is rejected: it belongs to the parent zone and proves nothing about types served at the child.
NXDOMAIN — covering NSEC for qname plus covering NSEC for the wildcard `*.closest_encloser` derived from the qname-covering NSEC. This is the standard two-NSEC name-error proof.
Compact denial of existence (draft-ietf-dnsop-compact-denial-of-existence, widely deployed by Cloudflare as "black lies"). For an NXDOMAIN response the auth server returns an NSEC at owner == qname whose bitmap excludes CNAME and DNAME, asserting the name has no useful records. Treated as a valid NXDOMAIN proof: the RCODE is signer-authenticated via the SOA RRSIG and the NSEC bitmap denies every type the client could have wanted.
func VerifyRRSIG ¶
func VerifyRRSIG(rrset []dns.ResourceRecord, rrsig *dns.RRSIGRecord, dnskey *dns.DNSKEYRecord) error
VerifyRRSIG verifies an RRSIG signature over an RRset using a DNSKEY. It builds the signed data (RRSIG RDATA without signature + canonical RRset) and verifies the cryptographic signature according to the algorithm.
Types ¶
type FailureReason ¶ added in v0.6.15
type FailureReason int
FailureReason classifies why DNSSEC validation produced a non-Secure verdict. Designed to be mapped by callers to RFC 8914 Extended DNS Error (EDE) info codes so that clients and operators can distinguish, for example, "the auth's signature expired" (operational issue on the auth side) from "we saw a cryptographically forged signature" (security event). Without this distinction every Bogus collapses into the generic EDE 6 and the cause is lost.
Suggested EDE mapping (RFC 8914 §4):
ReasonSignatureExpired → EDE 7 (Signature Expired) ReasonSignatureNotYetValid → EDE 8 (Signature Not Yet Valid) ReasonDNSKEYMissing → EDE 9 (DNSKEY Missing) ReasonNoMatchingDNSKEY → EDE 9 (DNSKEY Missing — no key by tag/alg) ReasonRRSIGsMissing → EDE 10 (RRSIGs Missing) ReasonUnsupportedDNSKEYAlgo → EDE 1 (Unsupported DNSKEY Algorithm) ReasonUnsupportedDSDigest → EDE 2 (Unsupported DS Digest Type) ReasonOther → EDE 6 (DNSSEC Bogus, generic)
const ( // ReasonNone means no specific failure reason was recorded (verdict // is Secure, or the validator didn't tag a specific cause). ReasonNone FailureReason = iota // ReasonSignatureExpired — an RRSIG's expiration is in the past. ReasonSignatureExpired // ReasonSignatureNotYetValid — an RRSIG's inception is in the future. ReasonSignatureNotYetValid // ReasonDNSKEYMissing — no DNSKEY rrset could be fetched for the signer. ReasonDNSKEYMissing // ReasonNoMatchingDNSKEY — DNSKEYs were fetched but none matched the // RRSIG's key-tag/algorithm. ReasonNoMatchingDNSKEY // ReasonRRSIGsMissing — the response is in a signed zone but lacks RRSIG. ReasonRRSIGsMissing // ReasonUnsupportedDNSKEYAlgo — every RRSIG used an algorithm this // resolver cannot verify. ReasonUnsupportedDNSKEYAlgo // ReasonUnsupportedDSDigest — every DS digest type was unsupported. ReasonUnsupportedDSDigest // ReasonOther — cryptographic verify failed, bailiwick failed, or some // other Bogus cause the validator has not classified further. ReasonOther // ReasonNTAOverride — a Negative Trust Anchor (RFC 7646) is active for // the queried zone subtree, suppressing the validation verdict to // Insecure regardless of what the chain would have produced. The // operator installed the NTA explicitly; this is the audit trail. ReasonNTAOverride )
func FailureReasonFromString ¶ added in v0.6.15
func FailureReasonFromString(s string) FailureReason
FailureReasonFromString is the inverse of FailureReason.String. Returns ReasonNone for the empty string and ReasonOther for unrecognised tokens (we'd rather fall through to the generic EDE 6 than drop the signal).
func (FailureReason) String ¶ added in v0.6.15
func (r FailureReason) String() string
String returns a stable token for the reason — used in logs, metrics, and ResolveResult.DNSSECReason so the value crosses package boundaries without leaking the int representation.
type NSEC3RecordWithOwner ¶
type NSEC3RecordWithOwner struct {
dns.NSEC3Record
OwnerHash []byte // raw hash bytes from the NSEC3 RR owner name
}
NSEC3RecordWithOwner extends NSEC3Record with the owner hash for proper range checking in denial proofs.
type NSECRecordWithOwner ¶ added in v0.6.4
type NSECRecordWithOwner struct {
dns.NSECRecord
OwnerName string
}
NSECRecordWithOwner pairs a parsed NSEC RDATA with the owner name from the resource record. The owner is required for both canonical range coverage checks and NODATA proofs (which compare owner against qname).
type NTAStore ¶ added in v0.6.42
type NTAStore struct {
// contains filtered or unexported fields
}
NTAStore is a thread-safe collection of negative trust anchors. Construct via NewNTAStore. The zero value is NOT ready for use — callers must use the constructor so the internal map is allocated.
func LoadNTAStoreFromStrings ¶ added in v0.6.42
LoadNTAStoreFromStrings builds a store from operator config lines of the form "<zone>|<RFC3339-expiry>|<reason>". Empty lines are skipped. Lines that fail to parse (bad format, unparseable timestamp, expiry already past) are returned in the second result so the caller can log them but the store remains usable with the entries that did parse. Returns a non-nil store even on total parse failure.
func NewNTAStore ¶ added in v0.6.42
func NewNTAStore() *NTAStore
NewNTAStore returns an empty store backed by the wall clock.
func (*NTAStore) Add ¶ added in v0.6.42
Add installs an NTA for the given zone. If an NTA already exists for the same zone it is replaced (typical "extend or shorten the window" operator action). Expiry MUST be in the future at the moment of the call; an Expiry already in the past is silently ignored — the caller should detect this and surface an error if it matters.
func (*NTAStore) Cleanup ¶ added in v0.6.42
Cleanup removes expired NTAs from the store. Returns the number of entries removed. Safe to call on a schedule (e.g. once per minute) from a background goroutine.
func (*NTAStore) List ¶ added in v0.6.42
func (s *NTAStore) List() []NegativeTrustAnchor
List returns a snapshot of all currently-stored NTAs (active OR expired — for operator-facing UI it is useful to surface expired entries until Cleanup runs). Order is not specified.
func (*NTAStore) Match ¶ added in v0.6.42
func (s *NTAStore) Match(qname string) (NegativeTrustAnchor, bool)
Match reports whether the given qname is covered by any active (unexpired) NTA. The walk is suffix-based: the NTA at `example.test` matches `example.test`, `foo.example.test`, and so on, but NOT `other.test`. Cousins outside the NTA subtree always fall through to normal validation.
Expired entries are treated as absent; they are not eagerly evicted here (that would require a write lock on the hot path). Use Cleanup() periodically to reclaim memory.
type NegativeTrustAnchor ¶ added in v0.6.42
type NegativeTrustAnchor struct {
// Zone is the apex name of the zone for which validation is
// suppressed. Always stored normalized (lowercase, trailing dot).
Zone string
// Expiry is the wall-clock time after which this NTA is treated
// as removed. RFC 7646 §6 requires a bounded lifetime.
Expiry time.Time
// Reason is an operator-supplied free-text note. Surfaced via the
// observability API so the operator can later answer "why did I
// add this NTA". Not used by the matcher.
Reason string
}
NegativeTrustAnchor (NTA, RFC 7646) is an operator-installed override that suppresses DNSSEC validation for a specific zone subtree for a bounded time window.
Motivation: a major TLD or a frequently-used domain misconfigures its signatures (expired RRSIG, broken DS rollover, KSK lost). Every validating resolver in front of that zone goes SERVFAIL. The operator — who knows the zone is broken but the operator of the broken zone has not yet fixed it — wants to keep their users working without disabling DNSSEC globally. RFC 7646 §1 defines an NTA as exactly that: a per-zone, time-bounded local override that downgrades validation to Insecure for matching qnames.
Safety design:
- NTAs are bounded by expiry. RFC 7646 §6 stresses that NTAs MUST NOT be open-ended; an entry past its expiry is treated as removed. The store enforces this on every Match call.
- The expiry is operator-set (no implicit duration), so the operational team takes the explicit decision of how long to tolerate the broken zone.
- Match uses strict suffix semantics: an NTA at `example.test` covers `example.test` itself and any descendant (`foo.example.test`, `bar.foo.example.test`), but NOT sibling zones like `other.test`. This matches the bailiwick rule used everywhere else in the validator.
Match is read-side hot path (every DNSSEC-validated query passes through it), so the store uses RWMutex with the read path under RLock only.
type Querier ¶
type Querier interface {
// QueryDNSSEC sends a DNS query with the DO (DNSSEC OK) bit set
// and returns the response.
QueryDNSSEC(name string, qtype uint16, qclass uint16) (*dns.Message, error)
}
Querier is the interface the validator uses to fetch DNSKEY and DS records needed for DNSSEC chain-of-trust validation.
type ValidationResult ¶
type ValidationResult int
ValidationResult represents the outcome of DNSSEC validation.
const ( // Secure means all signatures validated and the chain of trust is intact. Secure ValidationResult = iota // Insecure means the zone does not have DNSSEC (no RRSIG/DS records). Insecure // Bogus means signature validation failed - the response cannot be trusted. Bogus // Indeterminate means validation could not be completed (e.g., missing keys). Indeterminate )
func (ValidationResult) String ¶
func (v ValidationResult) String() string
String returns a human-readable name for the validation result.
type ValidationStep ¶ added in v0.6.7
type ValidationStep struct {
Stage string // "skip-weak", "skip-unsupported", "no-rrset", "expired", "not-yet", "out-of-bailiwick", "no-dnskey", "no-matching-key", "verify-failed", "verify-ok", "trust-chain"
Signer string
Owner string
KeyTag uint16
Algorithm uint8
TypeCovered uint16
Labels uint8
Outcome string // "ok", "bogus", "insecure", "indeterminate", "skipped"
Detail string
}
ValidationStep captures one RRSIG-attempt outcome inside a validation pass. It is produced by ValidateResponseDetailed and exposed to diagnostic tools (the DNS lookup trace UI) so an operator can see exactly which signature the validator considered, what it covered, and why it was accepted or rejected. Plain ValidateResponse callers do not pay for this — they get the same single verdict as before.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator performs DNSSEC signature verification and trust chain validation.
func NewValidator ¶
NewValidator creates a new DNSSEC Validator that uses the given Querier to fetch DNSKEY/DS records and the root trust anchors for chain validation.
func (*Validator) AllowSHA1 ¶ added in v0.6.2
AllowSHA1 toggles acceptance of RSASHA1 RRSIGs and SHA1 DS digests. When false (the default), responses that depend on SHA1 are treated as insecure (as if the zone published no signatures we can validate).
func (*Validator) NTAMatches ¶ added in v0.6.42
NTAMatches reports the cumulative count of validations short- circuited by an NTA match. Surfaced via /api/stats so operators can see whether an NTA is actually doing anything.
func (*Validator) NTAStore ¶ added in v0.6.42
NTAStore returns the configured store, or nil if none is wired. Operator-facing UI reads from here.
func (*Validator) SHA1Allowed ¶ added in v0.6.14
SHA1Allowed reports the current allowSHA1 setting. Used by callers that advertise their accepted primitives via RFC 6975 DAU/DHU options — the advertised list must match what the validator will actually accept.
func (*Validator) SetNTAStore ¶ added in v0.6.42
SetNTAStore wires a Negative Trust Anchor (RFC 7646) registry into the validator. Pass nil to disable NTA enforcement. Once set, every ValidateResponse call consults the store first; matching qnames are short-circuited to Insecure with ReasonNTAOverride before any chain work runs.
func (*Validator) ValidateResponse ¶
func (v *Validator) ValidateResponse(response *dns.Message, qname string, qtype uint16) ValidationResult
ValidateResponse validates DNSSEC signatures in a DNS response. It checks RRSIG records in the answer section and validates the trust chain from the signer back to the root trust anchors. For NXDOMAIN/NODATA responses, it also validates NSEC3 proofs.
func (*Validator) ValidateResponseDetailed ¶ added in v0.6.7
func (v *Validator) ValidateResponseDetailed(response *dns.Message, qname string, qtype uint16) (ValidationResult, []ValidationStep)
ValidateResponseDetailed returns the same verdict as ValidateResponse plus a per-RRSIG step log for diagnostic UIs. Each step records the algorithm, key tag, signer, type covered, labels, and outcome so a human can see why the validator settled on Secure / Insecure / Bogus / Indeterminate.
Plain ValidateResponse callers do not pay for this — they get the same single verdict and no allocated step slice.
func (*Validator) ValidateResponseWithReason ¶ added in v0.6.15
func (v *Validator) ValidateResponseWithReason(response *dns.Message, qname string, qtype uint16) (ValidationResult, FailureReason)
ValidateResponseWithReason returns the same verdict as ValidateResponse plus a FailureReason that classifies why a Bogus / Indeterminate verdict was reached. Callers can map the reason to an RFC 8914 EDE info code so that "RRSIG expired" and "no DNSKEY by key tag" don't collapse into the generic EDE 6. For Secure verdicts the reason is ReasonNone.
Like ValidateResponse, this path does not allocate per-RRSIG steps.