dns.dnssec

index · dns

Overview

DNSSEC validation primitives: key tag computation, DS digest verification, RRSIG signature verification, and chain-of-trust validation helpers. Supports algorithms 8 (RSA/SHA-256), 10 (RSA/SHA-512), 13 (ECDSA P-256), 14 (ECDSA P-384), and 15 (ED25519).

Denial of existence is checked for NSEC (RFC 4035) and for NSEC3 (RFC 5155): the iterated SHA-1 hash, the closest encloser proof and the opt-out flag. An answer expanded from a wildcard has its own proof, that no closer name exists.

Functions

NameSignature
compute_key_tagcompute_key_tag(rdata_wire) -> tag
encode_dnskey_rdataencode_dnskey_rdata(dnskey) -> wire_bytes
encode_name_canonicalencode_name_canonical(name) -> wire_bytes
encode_rdata_canonicalencode_rdata_canonical(rr) -> wire_bytes
build_canonical_rrsetbuild_canonical_rrset(owner, rrtype, rrclass, original_ttl, rr_list) -> wire_bytes
build_sig_databuild_sig_data(rrsig_rdata, canonical_rrset_wire) -> sig_data
parse_rsa_public_keyparse_rsa_public_key(pubkey_bytes) -> n, e, err
verify_signatureverify_signature(algorithm, sig_data, signature, dnskey_rdata) -> ok, err
rrsig_wildcardrrsig_wildcard(rrsig_rr, owner) -> encloser
verify_rrsigverify_rrsig(rrsig_rr, rrset, dnskey_rr, precomputed_tag) -> ok, err
verify_dsverify_ds(ds_rr, dnskey_rr) -> ok, err
validate_rrsetvalidate_rrset(rrset, rrsig_list, dnskey_list) -> ok, err, unsupported, wildcard
validate_dnskey_rrsetvalidate_dnskey_rrset(dnskey_records, dnskey_rrsigs, ds_records) -> ok, err, unsupported
validate_nsec_nodatavalidate_nsec_nodata(nsec_records, qname, qtype) -> ok, err
validate_nsec_no_dsvalidate_nsec_no_ds(nsec_records, child) -> ok, err
validate_nsec_nxdomainvalidate_nsec_nxdomain(nsec_records, qname) -> ok, err
validate_nsec_wildcardvalidate_nsec_wildcard(nsec_records, qname, encloser) -> ok, err
base32hex_encodebase32hex_encode(bytes) -> encoded
base32hex_decodebase32hex_decode(encoded) -> bytes, err
nsec3_hashnsec3_hash(name, salt, iterations) -> hash
validate_nsec3_no_dsvalidate_nsec3_no_ds(nsec3_records, zone, child) -> ok, err, insecure
validate_nsec3_nodatavalidate_nsec3_nodata(nsec3_records, zone, qname, qtype) -> ok, err, insecure
validate_nsec3_nxdomainvalidate_nsec3_nxdomain(nsec3_records, zone, qname) -> ok, err, insecure
validate_nsec3_wildcardvalidate_nsec3_wildcard(nsec3_records, zone, qname, encloser) -> ok, err, insecure

compute_key_tag(rdata_wire) -> tag

Compute DNSKEY key tag from wire-format RDATA

encode_dnskey_rdata(dnskey) -> wire_bytes

Encode DNSKEY rdata fields to wire-format bytes

encode_name_canonical(name) -> wire_bytes

Encode a domain name in lowercase uncompressed wire form

encode_rdata_canonical(rr) -> wire_bytes

Re-encode RDATA in canonical form (lowercased names, no compression)

build_canonical_rrset(owner, rrtype, rrclass, original_ttl, rr_list) -> wire_bytes

Build canonical wire form of an RRset for signature verification

build_sig_data(rrsig_rdata, canonical_rrset_wire) -> sig_data

Build the data that is signed by an RRSIG (RRSIG fields + canonical RRset)

parse_rsa_public_key(pubkey_bytes) -> n, e, err

Parse RSA public key from DNSKEY public_key field

verify_signature(algorithm, sig_data, signature, dnskey_rdata) -> ok, err

Verify a cryptographic signature using the appropriate algorithm

rrsig_wildcard(rrsig_rr, owner) -> encloser

Find the wildcard an RRSIG shows its RRset was expanded from

An RRSIG counts the labels of the name it signs, without the root and without a leading * (RFC 4034 §3.1.3). An owner with more labels was expanded from a wildcard (RFC 4035 §5.3.2). Returns that wildcard's parent, the closest encloser of owner: w.example. for a.z.w.example. under an RRSIG that counts two labels.

Returns nil when the counts agree. The wildcard's own name is no expansion, so *.w.example. under the same RRSIG gives nil too.

verify_rrsig(rrsig_rr, rrset, dnskey_rr, precomputed_tag) -> ok, err

Verify an RRSIG against an RRset using a DNSKEY

verify_ds(ds_rr, dnskey_rr) -> ok, err

Verify a DS record against a DNSKEY record

validate_rrset(rrset, rrsig_list, dnskey_list) -> ok, err, unsupported, wildcard

Validate an RRset using available RRSIGs and DNSKEYs

unsupported is true when the RRset failed and every RRSIG that found its key has an algorithm outside SUPPORTED_ALGORITHMS.

wildcard is set when the RRSIG that verified shows the RRset was expanded from a wildcard: the wildcard's parent, as rrsig_wildcard returns it. Such an answer holds only once the zone proves that no closer name exists, with validate_nsec_wildcard or validate_nsec3_wildcard.

validate_dnskey_rrset(dnskey_records, dnskey_rrsigs, ds_records) -> ok, err, unsupported

Validate a DNSKEY RRset using DS records (DS → KSK → RRSIG chain)

unsupported is true when the set failed and no supported algorithm could have checked it: no DS record is usable, or every RRSIG that found its key names an algorithm outside SUPPORTED_ALGORITHMS.

A DS record is usable when its algorithm is in SUPPORTED_ALGORITHMS and its digest type is 1, 2 or 4. An unusable one is skipped. When none is usable, err names the algorithm or the digest type that rules the first record out.

A set whose RRSIG shows a wildcard expansion fails. A DNSKEY set sits at its zone's apex, and no wildcard expands to it.

validate_nsec_nodata(nsec_records, qname, qtype) -> ok, err

Validate NSEC proves NODATA for qname/qtype

The proofs of RFC 4035 §3.1.3.1 and §3.1.3.4. An NSEC at qname must have the queried type and CNAME clear. With NS set and SOA clear, it comes from the parent side of a delegation. It then holds no type of the child zone, and proves a DS absence alone.

With SOA set, it comes from the child side of a zone cut: the apex of the zone at qname. A DS lives on the parent side, so that record proves no DS absence. The root has no parent, and its record does.

With no such record, an NSEC must cover qname, so the name has no records of its own. That NSEC shows the closest encloser of qname: the longest ancestor the name shares with its owner or its next name. When the next name lies under qname, the name is an empty non-terminal. It exists, holds no type, and the proof stands.

Otherwise a wildcard answers for qname. An NSEC must sit at the wildcard right under the closest encloser, with the queried type and CNAME clear.

The covering NSEC proves nothing when qname lies below its owner, and that owner is a delegation or holds a DNAME (RFC 6840 §4.1).

validate_nsec_no_ds(nsec_records, child) -> ok, err

Validate NSEC proves a delegation to child has no DS

validate_nsec_nxdomain(nsec_records, qname) -> ok, err

Validate NSEC proves NXDOMAIN for qname

The proof of RFC 4035 §3.1.3.2. An NSEC must cover qname, so the name has no records of its own. That NSEC shows the closest encloser of qname, as it does for validate_nsec_nodata. When its next name lies under qname, the name is an empty non-terminal. It exists, and the proof fails.

An NSEC must also cover the wildcard right under the closest encloser, so no wildcard answers for qname. An NSEC at that wildcard, or a next name under it, shows that the wildcard exists. The name then takes the wildcard's answer or a NODATA, and the proof fails.

Neither NSEC proves anything for a name below its owner, when that owner is a delegation or holds a DNAME (RFC 6840 §4.1).

validate_nsec_wildcard(nsec_records, qname, encloser) -> ok, err

Validate NSEC proves no closer name hides behind a wildcard answer

The proof of RFC 4035 §5.3.4 for an answer expanded from the wildcard right under encloser. An NSEC must cover qname, so the name has no records of its own.

That NSEC must also name encloser as the closest encloser of qname. The closest encloser an NSEC shows is the longest ancestor qname shares with its owner or its next name. A longer one than encloser is a closer name, or an empty non-terminal, and the wildcard does not reach under it.

The NSEC proves nothing when qname lies below its owner, and that owner is a delegation or holds a DNAME (RFC 6840 §4.1).

base32hex_encode(bytes) -> encoded

Encode bytes in base32hex, lowercase and without padding

base32hex_decode(encoded) -> bytes, err

Decode unpadded base32hex of either case

nsec3_hash(name, salt, iterations) -> hash

Compute the NSEC3 hash of a domain name

Returns the 20 raw bytes of RFC 5155 §5: SHA-1 over the name in canonical wire form with the salt appended, then iterations more rounds over the previous digest and the salt. base32hex_encode turns the hash into the first label of the NSEC3 owner name.

validate_nsec3_no_ds(nsec3_records, zone, child) -> ok, err, insecure

Validate NSEC3 proves a delegation to child has no DS

The proof of RFC 5155 §8.9, from the NSEC3 records of the parent zone. Either a record matches the hash of child, with NS set and DS and SOA clear. Or a closest encloser proof holds for child, and the record that covers the next closer name has the opt-out flag set.

insecure is true when the records' iteration count is over NSEC3_MAX_ITERATIONS. No hash is computed then, and the caller reads the referral as insecure.

validate_nsec3_nodata(nsec3_records, zone, qname, qtype) -> ok, err, insecure

Validate NSEC3 proves NODATA for qname/qtype

The proofs of RFC 5155 §8.5 to §8.7, from the NSEC3 records of zone. A record that matches the hash of qname must have the queried type and CNAME clear. For a type other than DS it must not be the parent side of a delegation, with NS set and SOA clear. For DS it must not be the child side of a zone cut, with SOA set: a DS lives on the parent side. The root has no parent, and its record proves that it has no DS.

With no such record, a closest encloser proof must hold. For DS, the record that covers the next closer name must have the opt-out flag set. For any other type, a record must match the wildcard at the closest encloser, with the queried type and CNAME clear.

insecure is true when the response reads insecure: the proof runs through an opt-out span (RFC 5155 §9.2), or the iteration count is over NSEC3_MAX_ITERATIONS.

validate_nsec3_nxdomain(nsec3_records, zone, qname) -> ok, err, insecure

Validate NSEC3 proves NXDOMAIN for qname

The proof of RFC 5155 §8.4, from the NSEC3 records of zone: a closest encloser proof for qname, and a record that covers the wildcard at the closest encloser.

insecure is true when the response reads insecure: the record that covers the next closer name has the opt-out flag set (RFC 5155 §9.2), or the iteration count is over NSEC3_MAX_ITERATIONS.

validate_nsec3_wildcard(nsec3_records, zone, qname, encloser) -> ok, err, insecure

Validate NSEC3 proves no closer name hides behind a wildcard answer

The proof of RFC 5155 §8.8 for an answer expanded from the wildcard right under encloser, from the NSEC3 records of zone. A record must cover the next closer name, the ancestor of qname one label below encloser. The wildcard's RRSIG already shows that encloser exists, so no record has to match it.

insecure is true when the answer reads insecure: the record that covers the next closer name has the opt-out flag set, so an unsigned delegation may sit there, or the iteration count is over NSEC3_MAX_ITERATIONS.