dnssec

package
v0.6.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: MIT Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

View Source
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

func ComputeNSEC3Hash(name string, algorithm uint8, iterations uint16, salt []byte) ([]byte, error)

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

func NSEC3HashToString(hash []byte) string

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

func VerifyDS(dnskey *dns.DNSKEYRecord, ds *dns.DSRecord, ownerName string) bool

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:

  1. Closest-encloser MATCH: an NSEC3 whose owner hash equals H(CE), where CE is the deepest ancestor of qname proven to exist.
  2. 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.
  3. 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:

  1. 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.

  2. 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.

  3. 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
)

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 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

func NewValidator(querier Querier, logger *slog.Logger) *Validator

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

func (v *Validator) AllowSHA1(allow bool)

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) SHA1Allowed added in v0.6.14

func (v *Validator) SHA1Allowed() bool

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) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL