Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2e100b4
M1: RFC 1035 wire codec with strict decoding and name compression
claude Oct 13, 2026
e857744
M2: DNSSEC signature verification and RFC known-answer tests
claude Oct 13, 2026
c86b0c5
M3: NSEC and NSEC3 denial-of-existence proofs
claude Oct 13, 2026
b02574d
M4: chain-of-trust validator with explicit verdicts
claude Oct 13, 2026
079eadf
M5: DoH stub client, dnssec-stub CLI, recorded-response tests
claude Oct 13, 2026
fe93016
M6: fuzzing of the decoder, NSEC3 parser, presentation parser and val…
claude Oct 13, 2026
3e02708
fix(validator): a spent fetch budget mid-chain is bogus, not indeterm…
claude Oct 13, 2026
8a9ccfd
M7: cross-check against Unbound and ldns on a fixed zone set
claude Oct 13, 2026
1da07d2
Integrate the library into the minted repository: docs, CI, container
claude Oct 13, 2026
7b87054
fix(validator): never infer insecurity from an unverified RRSIG signer
claude Oct 26, 2026
5a48a72
fix(deed): declare the cli capability with the dnssec-stub CLI
claude Oct 27, 2026
b255fb7
fix(deed): declare the library's paths in the variant contract
claude Oct 27, 2026
742e626
C ABI seam: zig_dnssec.h, libzig_dnssec, Idris2 model (#5)
hyperpolymath Oct 27, 2026
7e2c4ce
fix(dnssec): never infer insecurity from an unauthenticated signer name
hyperpolymath Oct 27, 2026
db58948
fix(wire): SVCB/HTTPS canonical form, relative-name length, skew-boun…
hyperpolymath Oct 27, 2026
9e3a860
fix(stub): keep a DoH URI template's query in the request target
hyperpolymath Oct 27, 2026
4673656
fix(ffi): refuse QTYPE=RRSIG at the C boundary with invalid_argument
hyperpolymath Oct 27, 2026
1a410bc
fix(container,ci): report the cross-check's status; force HTTPS and T…
hyperpolymath Oct 27, 2026
15468f2
test(replay): regressions for the validator's signer, Labels, TTL and…
hyperpolymath Oct 27, 2026
33a778b
fix(deed,scripts): make (provenance) reachable and honour the variant…
hyperpolymath Oct 27, 2026
43c0ca2
docs: record the milestone-1 review cycle and what its evidence does …
hyperpolymath Oct 27, 2026
0eaea35
docs(verification): the deed's template pin is unfetchable, so the dr…
hyperpolymath Oct 27, 2026
d9cd8ec
Update src/dnssec/validator.zig
hyperpolymath Oct 28, 2026
41864cb
Update src/README.adoc
hyperpolymath Oct 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/actions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ workflows:
'.github/workflows/workflow-linter.yml':
- 'actions/checkout@v7.0.1'
- 'oven-sh/setup-bun@v2.2.0'
'.github/workflows/zig-ci.yml':
- 'actions/checkout@v7.0.1'
dependencies:
'actions/attest-build-provenance@v4.2.2':
ref: 'v4.2.2'
Expand Down
106 changes: 106 additions & 0 deletions .github/workflows/zig-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This workflow is managed by gh actions-lock.
# SPDX-License-Identifier: MPL-2.0
#
# Builds and tests the zig-dnssec library with the Zig release pinned in
# mise.lock. The toolchain is fetched from ziglang.org and checked against
# its published SHA-256 (no third-party setup action).
name: Zig CI
on:
push:
branches: [main]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
env:
ZIG_VERSION: "0.17.0"
ZIG_SHA256: "1cbe9df9f27e6b78d14ccbca43b6703a404ef79ef1c463de901d7f088d4e2026"
steps:
- uses: actions/checkout@v7.0.1

- name: Install Zig (checksum-verified)
run: |
set -euo pipefail
curl -fsSL --proto '=https' --tlsv1.2 -o "$RUNNER_TEMP/zig.tar.xz" \
"https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-linux-${ZIG_VERSION}.tar.xz"
echo "${ZIG_SHA256} $RUNNER_TEMP/zig.tar.xz" | sha256sum -c -
tar -xJf "$RUNNER_TEMP/zig.tar.xz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/zig-x86_64-linux-${ZIG_VERSION}" >> "$GITHUB_PATH"

- name: Formatting
run: zig fmt --check build.zig src/root.zig src/wire src/dnssec src/stub src/cli src/interface/ffi tests

- name: Unit, RFC-vector, denial, replay, fuzz-corpus and C ABI tests
run: zig build test --summary all

- name: ReleaseSafe build
run: zig build -Doptimize=ReleaseSafe

- name: Short fuzz run (standalone mutation fuzzer, fixed seed)
run: |
zig build fuzz-tool -Doptimize=ReleaseSafe
./zig-out/bin/dnssec-fuzz all 20 0x2026

# The Idris2 side of the ABI seam: typecheck the proofs, then run the
# Idris2 -> C ABI -> Zig end-to-end test. Idris2 is built from a pinned
# release commit (it has no checksummed binary release).
abi-seam:
runs-on: ubuntu-24.04
timeout-minutes: 45
permissions:
contents: read
env:
ZIG_VERSION: "0.17.0"
ZIG_SHA256: "1cbe9df9f27e6b78d14ccbca43b6703a404ef79ef1c463de901d7f088d4e2026"
IDRIS2_TAG: "v0.7.0"
IDRIS2_COMMIT: "27780073c8631826d846499840b3857d9b9a4fd5"
steps:
- uses: actions/checkout@v7.0.1

- name: Install Zig (checksum-verified)
run: |
set -euo pipefail
curl --proto '=https' --tlsv1.2 -fsSL -o "$RUNNER_TEMP/zig.tar.xz" \
"https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-linux-${ZIG_VERSION}.tar.xz"
echo "${ZIG_SHA256} $RUNNER_TEMP/zig.tar.xz" | sha256sum -c -
tar -xJf "$RUNNER_TEMP/zig.tar.xz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/zig-x86_64-linux-${ZIG_VERSION}" >> "$GITHUB_PATH"

- name: Build Idris2 from the pinned release commit
run: |
set -euo pipefail
sudo apt-get update -q
sudo apt-get install -y -q chezscheme libgmp-dev
git clone -q --depth 1 --branch "$IDRIS2_TAG" https://github.com/idris-lang/Idris2.git "$RUNNER_TEMP/idris2-src"
test "$(git -C "$RUNNER_TEMP/idris2-src" rev-parse HEAD)" = "$IDRIS2_COMMIT"
make -C "$RUNNER_TEMP/idris2-src" bootstrap SCHEME=chezscheme PREFIX="$RUNNER_TEMP/idris2" -j"$(nproc)"
make -C "$RUNNER_TEMP/idris2-src" install PREFIX="$RUNNER_TEMP/idris2"
echo "$RUNNER_TEMP/idris2/bin" >> "$GITHUB_PATH"

# `idris2 --typecheck` can exit 0 with an Error: line (see
# scripts/check-proofs.sh), so both are checked.
- name: Typecheck the Idris2 ABI model
run: |
set -euo pipefail
out="$(idris2 --typecheck src/interface/abi.ipkg 2>&1)" || { echo "$out"; exit 1; }
echo "$out"
if echo "$out" | grep -q '^Error'; then exit 1; fi

- name: Idris2 -> C ABI -> Zig end-to-end test
run: |
set -euo pipefail
zig build ffi
idris2 --build src/interface/E2e/abi-e2e.ipkg
LD_LIBRARY_PATH=zig-out/lib src/interface/E2e/build/exec/abi-e2e \
tests/testdata/crosscheck.traces tests/testdata/crosscheck-root.anchor
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ verification/proofs/coq/.*.aux
# Agda compiled proof artifacts
verification/proofs/agda/*.agdai


# Zig
.zig-cache/
zig-out/

# zig-dnssec cross-check: local server state, and test signing keys that
# tests/crosscheck/make-zones.sh generates (only signed zones are a fixture)
/tests/crosscheck/work/
/tests/crosscheck/keys/
2 changes: 2 additions & 0 deletions .machine_readable/root-allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ tests/
?REQUIRES_INITIALISATION.md # written by the minting process, removed once `just repo-init` runs
?Project.toml # julia-library archetype: Pkg reads the package manifest from the package root only
?test/ # julia-library archetype: Pkg.test runs test/runtests.jl, a fixed path (the spine keeps tests/)
?build.zig # Zig package: `zig build` and `zig fetch` read the build script from the package root only
?build.zig.zon # Zig package manifest (name, version, fingerprint, paths); read from the package root only
110 changes: 110 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,116 @@ https://semver.org/spec/v2.0.0.html[Semantic Versioning].

==== Added

* DNS wire-format codec (RFC 1035): strict, bounds-checked decoding;
encoding with name compression; presentation-format parser.
* DNSSEC signature verification through Zig's standard library: RSASHA1,
RSASHA1-NSEC3-SHA1, RSASHA256, RSASHA512, ECDSAP256SHA256, ECDSAP384SHA384,
ED25519; DS digests SHA-1, SHA-256, SHA-384.
* NSEC and NSEC3 denial-of-existence proofs (RFC 4035, RFC 5155, RFC 6840).
* Chain-of-trust validator with `secure | insecure | bogus | indeterminate`
verdicts, static trust anchors (IANA root KSK-2017 and KSK-2024 built in),
resource budgets, and fail-closed default policies.
* Validating stub client over DNS-over-HTTPS (HTTP/1.1, TLS end to end,
optional CONNECT proxy) and the `dnssec-stub` command-line tool.
* Tests: RFC known-answer vectors, RFC appendix zones and responses, 263
recorded responses replayed offline, mutation attacks, fuzz targets with a
corpus; a cross-check against Unbound and ldns (`tests/crosscheck/`).
* `zig-ci` workflow; container image (`build/container/Containerfile`).
* C ABI (`zig build ffi`): `zig_dnssec.h` as the contract, a pure-Zig
`libzig_dnssec` checked against it at compile time, and an Idris2 model of
the interface (`src/interface/Abi/`) whose result type cannot carry an
answer for a bogus or indeterminate verdict; tests keep the three in step,
and an Idris2 end-to-end test (`just abi-e2e`) runs in CI.

==== Fixed

* Integer overflow in name decoding at the 255-octet boundary (found by
fuzzing).
* DNAME answers were rejected because the synthesised CNAME was examined
first (found by the Unbound cross-check).

Twelve findings from the external review of the milestone-1 pull request
(`hyperpolymath/zig-dnssec`#4, two automated reviews over `6d6a2b11` and
`4025364b`). Each has a regression test that was confirmed to fail against
the code it now guards; the two marked *security* accepted or produced
attacker-influenced data.

* *Security:* a forged RRSIG naming an insecure ancestor could bypass a
closer trust anchor. Insecurity was inferred from the RRSIG's signer name
alone, so an answer signed by a zone that is insecure from the root anchor
was handed back as usable `insecure` data even when an anchor existed below
that zone (RFC 4035 §5.2's closest-encloser rule). The signer is now
rejected when a configured anchor is at or below it, and the answer is
`bogus` (`bad_signer`).
* *Security:* the same defect on the denial path. `collectDenial` chose the
zone from the first unauthenticated RRSIG signer and returned `insecure`
before any signature over the NSEC/NSEC3/SOA records was checked. All
candidate signers are now gathered deepest-first and the denial RRset is
authenticated before it can establish anything.
* `computeZoneStatus` used only the first DS signature's signer; it now tries
every signer of the DS RRset that is a strict ancestor of the child.
* An extra RRSIG over a DS RRset naming a different ancestor could break an
otherwise valid chain (`no_matching_key` against the wrong keyset).
* A forged same-signer RRSIG with a smaller `Labels` field could change the
depth at which a wildcard expansion was proved, rejecting valid answers.
The `Labels` value now comes from the signature that actually verified, not
from the minimum over all signatures present.
* An `insecure` answer could be cached for the TTL the responder chose: the
received TTL of unsigned data is not signed, and the answer outlived the
denial proof that made it acceptable. The proof's own TTL now bounds it.
* `QTYPE=RRSIG` was reported as `bogus` for a correctly signed response;
nothing signs an RRSIG RRset, so it is now refused as `malformed_response`
at the validator and `ZIG_DNSSEC_ERR_INVALID_ARGUMENT` at the C ABI.
* For `QTYPE=CNAME` below a DNAME, the synthesised CNAME *is* the answer
(RFC 6672 §5.3.1); the validator redirected past it and then demanded a
NODATA proof nobody is obliged to send.
* `effectiveTtl` wrapped to a huge value for signatures accepted only within
the configured clock skew; it now measures to the widened window and fails
closed at 0.
* The SVCB/HTTPS RDATA layout was missing, so the TargetName was hashed in
the case it arrived in rather than canonical lowercase (RFC 4034 §6.2,
RFC 9460 §2.2).
* A relative name joined to its `$ORIGIN` overflowed the `u8` length before
the 255-octet check, panicking in safe modes and overrunning the name
buffer otherwise.
* The DoH transport dropped the query component of a configured URI template,
silently requesting a different endpoint (RFC 8484 §3.1).
* `build/container/Containerfile`: the `crosscheck` target's `CMD` chained
`servers.sh stop` with `;`, so its exit status masked the cross-check's.

==== Changed

* `scripts/validate-template.sh` now honours the repo deed's
`(paths :removed …)` list, and builds the root `build.zig` when the
variant contract has removed `src/interface/ffi/build.zig`. Previously it
required paths this variant deliberately deleted and, under `set -e`,
aborted on the first one without reporting the rest.
* `zig-dnssec_chora.deed`: the `(variant (paths …))` clause closed with one
parenthesis too many, which ended `(repo-deed …)` early and left
`(provenance)` a sibling of it rather than a clause of it. No reader could
reach the provenance facts — `scripts/deed-field.sh --has … provenance`
reported the clause absent, so
`scripts/check-template-conformance.sh` failed T1 and never evaluated
T2–T4. This came from the mint, not from this milestone: `main` carries the
same defect, and `build/just/repo-init.just` emits the correct `)))`.
* Toolchain pins: the Zig download in `zig-ci.yml` and in the container's
`toolchain` stage now forces HTTPS and a minimum of TLS 1.2
(`curl --proto '=https' --tlsv1.2`), so a pinned SHA-256 cannot be
satisfied by a downgraded transfer.
* Toolchain pin: Zig 0.16.0 → 0.17.0 (`mise.lock`).
* `src/interface/`: the template's example ABI/FFI seam is replaced by the
zig-dnssec C ABI; its separate `ffi/build.zig` is gone (the root
`build.zig` builds and tests the seam).

=== Inherited from rsr-template-repo at mint (2026-10-13)

The entries below describe the template this repository was minted from, not
zig-dnssec itself.

==== Template [Unreleased]

==== Added

* `www/` site-operations bundle (issue #53): canonical `.well-known/`
metadata, publishable content, policy sources, error bodies,
security-header templates, Caddy/nginx/Apache integration examples, an
Expand Down
39 changes: 29 additions & 10 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ clean-all: clean
# TEST & QUALITY
# ═══════════════════════════════════════════════════════════════════════════════

# Run every detected language's tests: `zig build test` covers src/interface/ffi
# (unit tests in src/main.zig, test/integration_test.zig). It compiles only after
# `just repo-init` has filled the template tokens, so an un-initialised template
# fails here loudly instead of reporting a pass over nothing.
# Run every detected language's tests: `zig build test` (library, C ABI and the
# Idris2/header consistency checks in src/interface/ffi/test/) and
# `idris2 --typecheck src/interface/abi.ipkg` (the seam's proofs).
test: provision::test

# Run tests with verbose output
Expand All @@ -145,9 +144,15 @@ test-smoke:
@echo "FAIL: 'just test-smoke' is not wired yet — no smoke check ran. Edit the 'test-smoke' recipe." >&2; exit 1

# Run end-to-end tests (full pipeline: build → run → verify)
e2e:
e2e: abi-e2e
bash tests/e2e.sh

# Idris2 -> C ABI -> Zig validator, over the recorded fixtures. Needs zig and idris2.
abi-e2e:
zig build ffi
idris2 --build src/interface/E2e/abi-e2e.ipkg
LD_LIBRARY_PATH=zig-out/lib src/interface/E2e/build/exec/abi-e2e tests/testdata/crosscheck.traces tests/testdata/crosscheck-root.anchor

# Run aspect tests (cross-cutting concern validation)
aspect:
# Aspect tests validate architectural invariants:
Expand All @@ -163,20 +168,34 @@ bench: provision::bench

# Run readiness tests (Component Readiness Grade: D/C/B)
readiness:
# TODO: Replace with your readiness test command. Examples:
# cargo test --test readiness -- --nocapture
@echo "FAIL: 'just readiness' is not wired yet — no readiness test ran. Edit the 'readiness' recipe." >&2; exit 1
# Deliberately unwired, and deliberately failing. This variant's Component
# Readiness Grade is X (Untested) in docs/status/READINESS.adoc, so there is
# no readiness evidence for a test run to attest to. CRG v2.0 Principle 4 is
# "grade as-is today, not aspirationally": pointing this recipe at the unit
# or replay suite would report a grade the evidence does not support, and
# `just test-all` would then claim "safe to merge" on the strength of it.
# Wire this when the D-grade gates (RSR-compliant + per-capability tests +
# a documented scope with a citing test matrix) are actually met.
@echo "FAIL: 'just readiness' is not wired — CRG is X (Untested)." >&2; \
echo " See docs/status/READINESS.adoc for the gates this variant has not met." >&2; \
exit 1

# Print the current CRG grade (reads from READINESS.md '**Current Grade:** X' line)
crg-grade:
@grade=$$(grep -oP '(?<=\*\*Current Grade:\*\* )[A-FX]' READINESS.md 2>/dev/null | head -1); \
@# This variant keeps its readiness assessment at docs/status/READINESS.adoc,
@# not the template's READINESS.md; reading only the latter silently reported
@# the fallback grade for the wrong reason. AsciiDoc bold is `*Current Grade:*`,
@# Markdown bold is `**Current Grade:**`, so both spellings are matched.
@f="docs/status/READINESS.adoc"; [ -f "$$f" ] || f="READINESS.md"; \
grade=$$(grep -oP '\*+Current Grade:\*+\s*\K[A-FX]' "$$f" 2>/dev/null | head -1); \
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
[ -z "$$grade" ] && grade="X"; \
echo "$$grade"

# Print a shields.io CRG badge for embedding in README files
# Looks for '**Current Grade:** X' in READINESS.md; falls back to X
crg-badge:
@grade=$$(grep -oP '(?<=\*\*Current Grade:\*\* )[A-FX]' READINESS.md 2>/dev/null | head -1); \
@f="docs/status/READINESS.adoc"; [ -f "$$f" ] || f="READINESS.md"; \
grade=$$(grep -oP '\*+Current Grade:\*+\s*\K[A-FX]' "$$f" 2>/dev/null | head -1); \
[ -z "$$grade" ] && grade="X"; \
case "$$grade" in \
A) color="brightgreen" ;; \
Expand Down
Loading
Loading