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 NSEC3RecordWithOwner
- type NSECRecordWithOwner
- type Querier
- type ValidationResult
- type ValidationStep
- type Validator
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 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 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) 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.