Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/patches/ff6aa42c35f46e44 # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/aienux#243 (code only) closed derived `ff6aa42c35f46e44` #243 Imported from GitHub aien-dev/aienux#243 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `4cfc9d303e331cd4215bd1d879d744e762576b4a` · Head `226c695e48672e4bfb05e58154bc0568d303f05d` ### Apply it ``` git checkout -b patch-ff6aa42c35f46e44 4cfc9d303e331cd4215bd1d879d744e762576b4a curl -fsSL https://interplane.io/drakestapleton/aienux/patches/ff6aa42c35f46e44.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aienux 243 226c695e48672e4bfb05e58154bc0568d303f05d ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aienux","number":243,"url":"https://github.com/aien-dev/aienux/pull/243","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:02Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.github/workflows/native-suites.yml b/.github/workflows/native-suites.yml index f5aa1872..9965b3df 100644 --- a/.github/workflows/native-suites.yml +++ b/.github/workflows/native-suites.yml @@ -2,9 +2,9 @@ # only compiled these into the kernel image; nothing ran their own tests. # # Coverage map (what runs where): -# native/capability test ci.yml +# native/capability test ci.yml (ci.yml is disabled_manually on GitHub, so this does NOT run in CI today) # native/capability mutants this file -# native/store test mutants ci.yml +# native/store test mutants ci.yml (ci.yml is disabled_manually on GitHub, so this does NOT run in CI today) # native/kernel test sanitize + gates ck-kernel.yml (owned by another lane) # native/net test sanitize mutants this file # native/sig test sanitize mutants this file diff --git a/docs/TRUST-1-M5-GATE-MATRIX.md b/docs/TRUST-1-M5-GATE-MATRIX.md index 526afae7..015942bf 100644 --- a/docs/TRUST-1-M5-GATE-MATRIX.md +++ b/docs/TRUST-1-M5-GATE-MATRIX.md @@ -19,7 +19,7 @@ Overall: **TRUST-1 NOT QUALIFIED. M5 NOT QUALIFIED.** | 1 Recovery media | 16 Q17 assertions with SB ON + test-file round trip | `build_standalone_recovery_initrd.sh`, `verify_recovery_tools.sh`, `collect_recovery_boot_evidence.sh`, `test_recovery_unlock_chroot.sh` | QEMU zero-disk boot receipt; stick boot-and-return on hardware (#53, #59, partial) | image build + host proofs | Machine 1 + USB stick | yes | BLOCKED_OPERATOR | Operator Steps 3, 4, 6: test file, rebuild stick (approval), attended SB-ON boot with unlock round trip | | 2 TPM measurement campaign | one-variable boot experiments, every candidate PCR explained | `tpm_measurement_campaign.sh capture/compare/receipt`, `test_trust1_measurement_tools.sh` | tooling self-test (verify_all step 10); one baseline capture | tooling only | Machine 1 | yes (reboots) | BLOCKED_OPERATOR | Operator Steps 1, 2, 7 (baseline restarts), then the Q15 one-variable experiments, each needing a reboot | | 3 Owner Root ceremony | offline hierarchy, generation-1 manifest, two verified backups, rotation demo | `trust1_key_ceremony.sh`, `test_trust1_key_ceremony.sh` | throwaway-key self-test (verify_all step 12) | tooling only | offline machine, two media | yes | BLOCKED_OPERATOR | Operator Step 8 (offline ceremony, two backups in separate places); precondition Gates 0-1 PASS | -| 4 Emulator security suite | Q9 list: signed/unsigned/tampered, manifest accept/alter, A/B select + fallback, swTPM policy, 100-boot soak, receipts | `qemu_secureboot_signing_test.sh` (snakeoil TEST key), `qemu_security_suite.sh`, `qemu_native_rollback_test.sh` | signed/unsigned/tampered PASS in QEMU; soak 3-5 boots in verify_all | yes (QEMU) | no | no | MISSING_IMPLEMENTATION | (outside the Q9 list, recorded for revocation coverage) firmware-level revocation (adding a revoked Boot Signer or image hash to dbx) is not tested in QEMU: no in-house authenticated-variable writer and no efitools; loader has no signed boot manifest and no A/B slot selection (crates/aienos-boot has none; loader is Rust and awaits the C/asm loader); signing with the real Boot Signer needs Gate 3; 100-boot soak NOT_RUN; build/emulator receipts not produced | +| 4 Emulator security suite | Q9 list: signed/unsigned/tampered, manifest accept/alter, A/B select + fallback, swTPM policy, 100-boot soak, receipts | `qemu_secureboot_signing_test.sh` (snakeoil TEST key), `qemu_security_suite.sh`, `qemu_native_rollback_test.sh` | signed/unsigned/tampered PASS in QEMU; soak 3-5 boots in verify_all | yes (QEMU) | no | no | MISSING_IMPLEMENTATION | (outside the Q9 list, recorded for revocation coverage) firmware-level revocation (adding a revoked Boot Signer or image hash to dbx) is not tested in QEMU: no in-house authenticated-variable writer and no efitools; loader has no signed boot manifest and no A/B slot selection (crates/aienos-boot has none; loader is Rust and awaits the C/asm loader); signing with the real Boot Signer needs Gate 3; 100-boot soak recorded 100/100 in QEMU on 2026-10-02 (see the update below; the repo holds no receipt file for it, only a queue log); build/emulator receipts not produced | | 5 TPM policy simulation | release-set policy N / N+1 / retire, cases current, next, rollback, invalid, rotation, recovery, in swTPM | `trust1_gate5_policy_sim.sh selftest` (swTPM; PolicyAuthorize by a throwaway Owner Root over Release Signer delegations, signed release sets of PolicyPCR + PolicyNV, monotonic NV counters for release and signer floors, PolicyOR recovery branch via PolicySigned by a throwaway Operator Approval key over a fresh TPM nonce) | selftest on swTPM: 31 checks, `TRUST1_GATE5_POLICY_SIM: PASS`; every refusal comes from the TPM; includes mutated-policy negative controls. Simulation only, never Machine 1 | yes (swTPM) | no | yes (preconditions) | BLOCKED_OPERATOR | the simulation itself passes, but formal Gate 5 PASS needs preconditions Gates 2-4 PASS: the PCR selection (PCR 7 and 11 are placeholders) comes from the Gate 2 campaign, the real Owner Root / Release Signer / Operator Approval keys from the Gate 3 ceremony, and Gate 4 is MISSING_IMPLEMENTATION; no simulation receipt file is written yet | | 6 Storage migration prep | add owner-policy unlock path beside old, three paths proven | none | none | no | Machine 1 | yes | BLOCKED_OPERATOR | preconditions Gates 0-5; needs its own written steps and approval | | 7 Hardware validation | one attended owner-signed boot with SB ON, Linux stays default | `trust1_gate7_preflight.sh` (read-only) | preflight script only | preflight only | Machine 1 | yes | BLOCKED_OPERATOR | preconditions Gates 0-6 and operator approval receipt | @@ -55,9 +55,9 @@ The C sealed Store (`native/store/store_sealed.c`, lane 11) wires `native/m5` in | Protocol for 512-byte tearing | proven twice: Rust engine root-tear closure (#136 Tier 2a: every non-zero superblock byte in sector 0) and the C host reference `native/store/torn_slot.c` (#175, every block subset enumerated); neither is the production path | n/a | | Production Store on 512-byte geometry | C disk layer now exists: `native/disk` (block layer + freestanding C NVMe driver, #190, QEMU virtual NVMe only) and `native/store` (byte-identical C twin of the ADR 0015 engine, 89/89 golden-vector rows, plus the sealed Store with the torn_slot anchor); host receipt `evidence/trust1_m5_qualification_6fd36c3012ad792862e6098492ae78d7b091c5fada8af73c7c60e6a8f544a650.json`. QEMU kernel-path evidence: the sealed C Store runs in the C kernel boot path on a 512 B QEMU namespace (`evidence/trust1_m5_qualification_3358bc2585f0982e1dfbcd0f5ed2fe077847332591782edff8974f0da9caeded.json`, row `ck_store_kernel_qemu`; QEMU-only unsafe DMA bypass, no crash campaign). The same C kernel Store path now runs SMMU-confined in QEMU (`iommu=smmuv3`, NVMe stream mapped to its DMA window only, out-of-window DMA faulted; `evidence/ck_gates_23482745517ec1967d2667b24d2a1cd9eafb27cdd91bdb91be7712a3a2968812.json`, gates `SMMU`, `M4_NVME`, `M4_STORE`; QEMU only, physical NOT_RUN). Missing: the binding on a real device (`m5_store_kernel_binding`) and any run on the Machine 1 SSD | MISSING_IMPLEMENTATION | -## Newest receipt (2026-10-01, lane 33): NOT_QUALIFIED and STALE +## Superseded receipt (2026-10-01, lane 33): NOT_QUALIFIED and STALE (the newest is in the 2026-10-02 update below) -The newest TRUST-1/M5 receipt is +This was the newest TRUST-1/M5 receipt on 2026-10-01 (superseded by 3f9d07f5, see the 2026-10-02 update below), namely `evidence/trust1_m5_qualification_3358bc2585f0982e1dfbcd0f5ed2fe077847332591782edff8974f0da9caeded.json`: 37 rows, pass 20, fail 0, not_run 1, blocked 11, missing 5, verdict **NOT_QUALIFIED**. It is **stale**: it ran at 5a3a05c, before #197 (SMMU), #199 @@ -84,4 +84,4 @@ Newest receipt, run at 44de11f with QEMU suites on: `evidence/trust1_m5_qualification_3f9d07f50196b4ad741b03c353ed3c45c268a72f04c32f00a0ddfab5294a3eee.json`, `TRUST1_M5_QUALIFICATION: NOT_QUALIFIED (pass=19 fail=1 not_run=1 blocked=11 missing=5)`. It supersedes 3358bc25. The one FAIL is `t1_gate7_preflight`, which reads live operator state: the Spark now has SecureBoot=0 (Drake's decision 2026-10-01), so the pre-flight correctly refuses. It is not a code regression. `store_rust_crosscheck` is NOT_RUN (Rust store tool not built). -Gate 4 soak: `GATE4_SOAK_RUNS=100 bash scripts/qemu_security_suite.sh` passed 100/100 boots plus the tampered-binary rejection (swTPM, QEMU, forge job C5-SOAK, log `~/workspace/test-queue-logs/C5-SOAK-005901.log`). Gate 4 stays MISSING_IMPLEMENTATION for the loader A/B and manifest items. +Gate 4 soak: `GATE4_SOAK_RUNS=100 bash scripts/qemu_security_suite.sh` passed 100/100 boots plus the tampered-binary rejection (swTPM, QEMU, forge job C5-SOAK, log `~/workspace/test-queue-logs/C5-SOAK-005901.log`). The tampered-binary step in that run used the older check (the guest merely never printed `kernel: alive`); the suite now also requires the firmware banner, so a rerun of that step under the stricter check is NOT_RUN. Gate 4 stays MISSING_IMPLEMENTATION for the loader A/B and manifest items. diff --git a/evidence/gate1_zero_disk_recovery_receipt_addendum_v1.json b/evidence/gate1_zero_disk_recovery_receipt_addendum_v1.json new file mode 100644 index 00000000..4a88989a --- /dev/null +++ b/evidence/gate1_zero_disk_recovery_receipt_addendum_v1.json @@ -0,0 +1,22 @@ +{ + "schema_version": "1.0.0", + "receipt_type": "gate1_zero_disk_recovery_addendum", + "procedure_id": "TRUST-1-GATE1-ADDENDUM-2026-10-02", + "timestamp_utc": "2026-10-02T00:00:00Z", + "amends_receipt": { + "path": "evidence/gate1_zero_disk_recovery_receipt.json", + "sha256": "e1d6ac54f56570a89450c129922de6001b8bb510b4d9db6ed11d93608937885d", + "previous_claim": "invariants block lists zero_internal_storage_dependency, internal_nvme_unmounted, atlas_recov_protected and qemu_zero_disk_verified as true, and status PASS_EMULATOR_VERIFIED", + "corrected_claim": "Those four true values were written as literals by the receipt writer of that time. The receipt carries no QEMU serial-log hash, no check output and no image-to-boot binding, so none of the four is backed by evidence recorded in the receipt. Read each as NOT_RUN. The current writer scripts/capture_gate1_receipt.sh computes qemu_zero_disk_boot and qemu_boot_bound_to_image_hash from a real run and records internal_nvme_unmounted and atlas_recov_protected as NOT_RUN." + }, + "field_status": { + "zero_internal_storage_dependency": "NOT_RUN", + "internal_nvme_unmounted": "NOT_RUN", + "atlas_recov_protected": "NOT_RUN", + "qemu_zero_disk_verified": "NOT_RUN" + }, + "unchanged_facts": "artifact sha256 values and the utilities list in the original receipt are file facts and are not amended", + "physical_hardware_status": "NOT_RUN", + "tier_words": { "host": "PASS", "qemu": "NOT_RUN", "hardware": "NOT_RUN" }, + "result": "ORIGINAL_INVARIANTS_NOT_BACKED" +} diff --git a/scripts/check_receipt_labels.sh b/scripts/check_receipt_labels.sh new file mode 100755 index 00000000..ef582199 --- /dev/null +++ b/scripts/check_receipt_labels.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# check_receipt_labels.sh: lint for evidence receipts that carry hardcoded +# invariant labels (a literal `true` inside an "invariants" block). +# +# A receipt with such a block is only acceptable if an addendum in the same +# folder amends it: the addendum names the receipt's path and carries the +# receipt's current sha256. Without that, the literal true reads as a PASS that +# nothing checked. +# +# Usage: scripts/check_receipt_labels.sh [EVIDENCE_DIR] (default: ../evidence) +# scripts/check_receipt_labels.sh --self-test +# Exit: 0 = every such receipt is amended, 1 = at least one is not. +set -uo pipefail + +lint_dir() { # DIR -> prints PASS/FAIL lines, returns 1 on any FAIL + local dir="$1" rc=0 f base h found + shopt -s nullglob + for f in "${dir}"/*.json; do + base="$(basename "${f}")" + case "${base}" in *addendum*) continue ;; esac + # a literal true inside an "invariants" object (up to the closing brace) + if sed -n '/"invariants"[[:space:]]*:[[:space:]]*{/,/}/p' "${f}" | grep -Eq ':[[:space:]]*true[[:space:]]*,?[[:space:]]*$'; then + h="$(sha256sum "${f}" | cut -d' ' -f1)" + found=0 + for a in "${dir}"/*addendum*.json; do + if grep -Eq "\"path\"[[:space:]]*:[[:space:]]*\"evidence/${base}\"" "${a}" && grep -Eq "\"sha256\"[[:space:]]*:[[:space:]]*\"${h}\"" "${a}"; then found=1; break; fi + done + if [[ ${found} == 1 ]]; then echo "PASS ${base}: hardcoded invariants are amended by an addendum bound to sha256 ${h:0:8}" + else echo "FAIL ${base}: literal true invariants with no addendum bound to its current sha256 ${h:0:8}"; rc=1; fi + fi + done + return ${rc} +} + +if [[ "${1:-}" == --self-test ]]; then + st=0; t="$(mktemp -d)"; trap 'rm -rf "${t}"' EXIT + expect() { # name want dir + local rc=0; lint_dir "$3" >"${t}/out.txt" 2>&1 || rc=$? + if [[ "${rc}" == "$2" ]]; then echo "PASS ${1} -> exit ${rc}"; else echo "FAIL ${1}: wanted ${2}, got ${rc}"; cat "${t}/out.txt"; st=1; fi + } + mk() { mkdir -p "${t}/$1"; printf '{\n "invariants": {\n "a_check": true,\n "policy": "x"\n }\n}\n' >"${t}/$1/r.json"; } + mk bare; expect "mutant: literal true, no addendum -> FAIL" 1 "${t}/bare" + mk good; h="$(sha256sum "${t}/good/r.json" | cut -d' ' -f1)" + printf '{"amends_receipt":{"path":"evidence/r.json","sha256":"%s"}}\n' "${h}" >"${t}/good/r_addendum.json" + expect "amended by an addendum bound to the hash -> PASS" 0 "${t}/good" + mk stale; printf '{"amends_receipt":{"path":"evidence/r.json","sha256":"%064d"}}\n' 0 >"${t}/stale/r_addendum.json" + expect "mutant: addendum bound to a different hash -> FAIL" 1 "${t}/stale" + mkdir -p "${t}/nr"; printf '{\n "invariants": {\n "a_check": "NOT_RUN"\n }\n}\n' >"${t}/nr/r.json" + expect "NOT_RUN labels need no addendum -> PASS" 0 "${t}/nr" + mkdir -p "${t}/other"; printf '{\n "ok": true\n}\n' >"${t}/other/r.json" + expect "receipt with no invariants block -> PASS" 0 "${t}/other" + if [[ ${st} == 0 ]]; then echo "CHECK_RECEIPT_LABELS_SELF_TEST: PASS"; exit 0; fi + echo "CHECK_RECEIPT_LABELS_SELF_TEST: FAIL"; exit 1 +fi + +dir="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/evidence}" +if lint_dir "${dir}"; then echo "RECEIPT_LABELS: PASS"; exit 0; fi +echo "RECEIPT_LABELS: FAIL"; exit 1 diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh index 86007fa2..da984017 100755 --- a/scripts/ck_gates.sh +++ b/scripts/ck_gates.sh @@ -268,7 +268,7 @@ write_receipt() { echo " \"finished_utc\": $(json_str "$(date -u +%FT%TZ)")," echo " \"commit\": $(json_str "${head_sha}")," echo " \"commit_subject\": $(json_str "${head_subject}")," - echo " \"tree_clean_before\": true," + echo " \"tree_clean_before\": ${tree_clean_before}," echo " \"tree_clean_after\": ${tree_clean_after}," echo " \"quiet_flag\": $(json_str "${QUIET_FLAG}")," echo " \"quiet_flag_present_at_start\": ${quiet_at_start}," @@ -469,7 +469,7 @@ self_test() { scenario R "$(fake bootR 0 'AIENOS_CK_M1: PASS')" "$(fake storeR 0 'AIENOS_CK_M4_NVME: PASS')" count_rows out_dir="${tmp}/out"; mkdir -p "${out_dir}" - started_utc=x; head_sha=x; head_subject='quote " backslash \ tab end'; tree_clean_after=true; quiet_at_start=false + started_utc=x; head_sha=x; head_subject='quote " backslash \ tab end'; tree_clean_before=true; tree_clean_after=true; quiet_at_start=false h_host=h; h_arch=a; h_kernel=k; h_cpu=c; q_path=q; q_version=v; fw_code_sha=x; fw_vars_sha=y; dma_mode="$(nvme_dma_mode)" write_receipt if [[ -f "${receipt_path}" && "$(sha_of <"${receipt_path}")" == "${receipt_sha}" && "${receipt_path}" == *"/ck_gates_${receipt_sha}.json" ]]; then @@ -477,6 +477,14 @@ self_test() { else bad "receipt name does not match its content hash" fi + # tree_clean_before comes from the pre-run tree state, never a literal. + grep -q '"tree_clean_before": true,' "${receipt_path}" && ok "receipt records tree_clean_before true when the tree was clean" || bad "tree_clean_before not true in a clean-tree receipt" + tree_clean_before=false; out_dir="${tmp}/out_dirty"; mkdir -p "${out_dir}" + write_receipt + grep -q '"tree_clean_before": false,' "${receipt_path}" && ok "mutant: dirty tree before the run -> receipt says tree_clean_before false" || bad "mutant survived: tree_clean_before stayed true" + tree_clean_before=true; out_dir="${tmp}/out" + # Restore the clean-tree receipt as the one the checks below look at. + write_receipt if command -v jq >/dev/null; then jq -e '.physical == "NOT_RUN" and (.gates | length) == 16 and .verdict == "NOT_ALL_GATES_PASS" and ([.gates[] | select(.id == "M1")][0].verdict == "PASS") @@ -484,7 +492,7 @@ self_test() { and (.children | length) == 9 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ && ok "receipt is valid JSON (jq) with expected fields" || bad "receipt JSON invalid or fields wrong" else - echo "SKIP jq not installed; JSON validity not machine-checked" + echo "NOT_RUN jq not installed; JSON validity not machine-checked"; jq_skipped=1 fi local before_sha; before_sha="$(sha_of <"${receipt_path}")" echo junk >"${work_dir}/other.tmp" @@ -528,7 +536,7 @@ self_test() { [[ ${rc} == 2 ]] && ok "unknown argument -> exit 2" || bad "unknown argument gave exit ${rc}" rm -rf --one-file-system "${tmp}" - if [[ ${st_fail} == 0 ]]; then echo "AIENOS_CK_GATES_SELF_TEST: PASS"; exit 0; fi + if [[ ${st_fail} == 0 ]]; then echo "AIENOS_CK_GATES_SELF_TEST: PASS${jq_skipped:+ (jq NOT_RUN: JSON validity of the receipt not machine-checked)}"; exit 0; fi echo "AIENOS_CK_GATES_SELF_TEST: FAIL"; exit 1 } @@ -548,6 +556,8 @@ main() { refuse_if_dirty "${repo_root}" local before; before="$(tree_state "${repo_root}")" + tree_clean_before=true + [[ -z "${before}" ]] || tree_clean_before=false head_sha="$(git -C "${repo_root}" rev-parse HEAD)" head_subject="$(git -C "${repo_root}" log -1 --format=%s HEAD)" started_utc="$(date -u +%FT%TZ)" diff --git a/scripts/lib_verify_summary.sh b/scripts/lib_verify_summary.sh new file mode 100644 index 00000000..a2400b67 --- /dev/null +++ b/scripts/lib_verify_summary.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +# lib_verify_summary.sh: the skipped-step bookkeeping and the closing verdict +# of scripts/verify_all.sh, kept here so the verdict can be tested without +# cargo or QEMU. Source it; or run `bash scripts/lib_verify_summary.sh +# --self-test` for negative controls. +# +# Rule: the last line of verify_all.sh says what actually ran. A skipped step +# makes the verdict NOT_RUN for that step (never "PASS"), and AIENOS_STRICT=1 +# turns any skipped step into a failure. QEMU steps are emulator evidence only; +# hardware is never checked by verify_all.sh. + +SKIPPED_STEPS=() + +skipped() { + echo "SKIPPED: $*" + SKIPPED_STEPS+=("$*") + if [[ "${AIENOS_STRICT:-0}" == "1" ]]; then + echo "STRICT FAIL: a step was skipped under AIENOS_STRICT=1 ($*)" >&2 + exit 1 + fi +} + +# run_or_skip DESCRIPTION COMMAND...: a script that exits 3 reports NOT_RUN (it +# skipped a check class); that is a skipped step here, never a pass. Any other +# nonzero exit stops the harness, as before. +run_or_skip() { + local desc="$1" rc=0; shift + "$@" || rc=$? + if [[ "${rc}" == 3 ]]; then skipped "${desc}: the script reported NOT_RUN (exit 3)" + elif [[ "${rc}" != 0 ]]; then exit "${rc}"; fi + return 0 +} + +final_verdict() { + echo "" + echo "============================================================" + if [[ ${#SKIPPED_STEPS[@]} -eq 0 ]]; then + echo "VERIFY_ALL: PASS (every step ran; QEMU steps are emulator evidence only, hardware NOT_RUN)" + else + printf 'NOT_RUN skipped step: %s\n' "${SKIPPED_STEPS[@]}" + echo "VERIFY_ALL: NOT_RUN (${#SKIPPED_STEPS[@]} step(s) skipped; every step that ran passed; not a full pass)" + fi + echo "============================================================" +} + +if [[ "${BASH_SOURCE[0]}" == "$0" && "${1:-}" == --self-test ]]; then + lib="${BASH_SOURCE[0]}"; st=0 + ok() { echo "PASS $*"; } + bad() { echo "FAIL $*"; st=1; } + # Each case runs in its own shell so exit paths are observable. + case_out() { AIENOS_STRICT="${STRICT:-0}" bash -c 'source "$1"; shift; eval "$@"' _ "${lib}" "$1" 2>&1; } + + out="$(case_out 'final_verdict')" + grep -qF 'VERIFY_ALL: PASS' <<<"${out}" && ok "no skipped step -> VERIFY_ALL: PASS" || bad "clean run did not print PASS" + + out="$(case_out 'skipped "demo step" >/dev/null; final_verdict')" + if grep -qF 'VERIFY_ALL: NOT_RUN (1 step(s) skipped' <<<"${out}" && ! grep -qF 'VERIFY_ALL: PASS' <<<"${out}"; then + ok "one skipped step -> VERIFY_ALL: NOT_RUN, never PASS (the old banner said PASSED regardless)" + else bad "skipped step verdict wrong: ${out}"; fi + grep -qF 'skipped step: demo step' <<<"${out}" && ok "the skipped step is named in the verdict" || bad "skipped step not named" + + rc=0; STRICT=1 case_out 'skipped "demo step"' >/dev/null || rc=$? + [[ "${rc}" == 1 ]] && ok "AIENOS_STRICT=1: a skipped step exits 1" || bad "strict skip exited ${rc}" + + rc=0; out="$(case_out 'run_or_skip demo bash -c "exit 3"; final_verdict')" || rc=$? + if [[ "${rc}" == 0 ]] && grep -qF 'VERIFY_ALL: NOT_RUN' <<<"${out}"; then ok "a child exiting 3 (NOT_RUN) is a skipped step"; else bad "exit-3 child: rc=${rc}"; fi + + rc=0; case_out 'run_or_skip demo bash -c "exit 1"; echo reached' >/dev/null || rc=$? + [[ "${rc}" == 1 ]] && ok "a child exiting 1 stops the harness" || bad "exit-1 child: rc=${rc}" + + rc=0; out="$(case_out 'run_or_skip demo true; final_verdict')" || rc=$? + [[ "${rc}" == 0 ]] && grep -qF 'VERIFY_ALL: PASS' <<<"${out}" && ok "a child exiting 0 is not a skip" || bad "exit-0 child: rc=${rc}" + + if [[ ${st} == 0 ]]; then echo "VERIFY_ALL_SUMMARY_SELF_TEST: PASS"; exit 0; fi + echo "VERIFY_ALL_SUMMARY_SELF_TEST: FAIL"; exit 1 +fi diff --git a/scripts/qemu_native_rollback_test.sh b/scripts/qemu_native_rollback_test.sh index f21d6a75..9fd056f4 100755 --- a/scripts/qemu_native_rollback_test.sh +++ b/scripts/qemu_native_rollback_test.sh @@ -20,6 +20,48 @@ set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${REPO_ROOT}" +# Per-invariant judges for the Default OS boot logs. The guest (rollback_mock.rs +# run_default) prints a PASS line for each invariant it checked itself and a FAIL +# line otherwise. A host label may only say PASS when the log carries that +# invariant's own evidence and no FAIL line for it. +log_consumed_ok() { # LOG: BootNext was consumed + [[ -f "$1" ]] || return 1 + grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "$1" 2>/dev/null && \ + grep -q "PASS NATIVE_ROLLBACK_BOOTNEXT_CONSUMED" "$1" && \ + ! grep -q "FAIL NATIVE_ROLLBACK_BOOTNEXT_STILL_PRESENT" "$1" +} +log_unchanged_ok() { # LOG: BootOrder still starts with the Default entry 0001 + [[ -f "$1" ]] || return 1 + grep -q "DEFAULT_OS: BOOT_ORDER\[0\]=0001" "$1" 2>/dev/null && \ + grep -q "PASS NATIVE_ROLLBACK_DEFAULT_UNCHANGED" "$1" && \ + ! grep -q "FAIL NATIVE_ROLLBACK_DEFAULT_ORDER_ALTERED" "$1" +} + +if [[ "${1:-}" == --self-test ]]; then + st=0; t="$(mktemp -d)"; trap 'rm -rf "${t}"' EXIT + good() { printf 'DEFAULT_OS: BOOT_CURRENT=0001\nDEFAULT_OS: BOOT_ORDER[0]=0001\nDEFAULT_OS: BOOT_NEXT=CONSUMED_PASS\nPASS NATIVE_ROLLBACK_BOOTNEXT_CONSUMED\nPASS NATIVE_ROLLBACK_DEFAULT_UNCHANGED\n'; } + expect() { # name want(0|1) function log + local rc=0; "$3" "$4" || rc=$? + if [[ "${rc}" == "$2" ]]; then echo "PASS $1 -> exit ${rc}"; else echo "FAIL $1: wanted ${2}, got ${rc}"; st=1; fi + } + good >"${t}/good.log" + expect "good Default boot: BootNext consumed" 0 log_consumed_ok "${t}/good.log" + expect "good Default boot: BootOrder unchanged" 0 log_unchanged_ok "${t}/good.log" + # Mutant: the firmware boot order was altered. The old host check ignored this and still printed DEFAULT_UNCHANGED: PASS. + good | sed -e 's/BOOT_ORDER\[0\]=0001/BOOT_ORDER[0]=0002/' -e 's/^PASS NATIVE_ROLLBACK_DEFAULT_UNCHANGED$/FAIL NATIVE_ROLLBACK_DEFAULT_ORDER_ALTERED/' >"${t}/order.log" + expect "mutant: BootOrder altered -> DEFAULT_UNCHANGED not PASS" 1 log_unchanged_ok "${t}/order.log" + expect "mutant: BootOrder altered leaves the BootNext label alone" 0 log_consumed_ok "${t}/order.log" + # Mutant: BootNext still present. + good | sed -e 's/CONSUMED_PASS/STILL_PRESENT/' -e 's/^PASS NATIVE_ROLLBACK_BOOTNEXT_CONSUMED$/FAIL NATIVE_ROLLBACK_BOOTNEXT_STILL_PRESENT/' >"${t}/next.log" + expect "mutant: BootNext still present -> CONSUMED not PASS" 1 log_consumed_ok "${t}/next.log" + # Mutant: the guest never printed the invariant lines (only the old unchanged markers). + printf 'DEFAULT_OS: BOOT_CURRENT=0001\nDEFAULT_OS: BOOT_NEXT=CONSUMED_PASS\nPASS NATIVE_ROLLBACK_REPEAT_BOOT\n' >"${t}/old.log" + expect "mutant: log with only the old markers -> DEFAULT_UNCHANGED not PASS" 1 log_unchanged_ok "${t}/old.log" + expect "mutant: missing log file -> not PASS" 1 log_unchanged_ok "${t}/absent.log" + if [[ ${st} == 0 ]]; then echo "NATIVE_ROLLBACK_SELF_TEST: PASS"; exit 0; fi + echo "NATIVE_ROLLBACK_SELF_TEST: FAIL"; exit 1 +fi + CODE_FD="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" VARS_FD="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" @@ -285,19 +327,21 @@ run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot3_default # Boot 4: Second consecutive boot of Default OS (proves system stays on Default, no loops) run_qemu_boot "${SUB6_DIR}/esp" "${SUB6_DIR}/vars.fd" "${SUB6_DIR}/boot4_default2.log" 20 || true -if grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB6_DIR}/boot3_default1.log" && \ - grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${SUB6_DIR}/boot4_default2.log" && \ - grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${SUB6_DIR}/boot4_default2.log" && \ - grep -q "DEFAULT_OS: BOOT_NEXT=CONSUMED_PASS" "${SUB6_DIR}/boot4_default2.log" && \ - grep -q "PASS NATIVE_ROLLBACK_REPEAT_BOOT" "${SUB6_DIR}/boot4_default2.log"; then +b3="${SUB6_DIR}/boot3_default1.log"; b4="${SUB6_DIR}/boot4_default2.log" +if grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${b3}" && \ + grep -q 'BdsDxe: starting Boot0001 "Default Linux OS"' "${b4}" && \ + grep -q "DEFAULT_OS: BOOT_CURRENT=0001" "${b4}" && \ + grep -q "PASS NATIVE_ROLLBACK_REPEAT_BOOT" "${b4}"; then pass "Subsequent reboot stayed on Default OS via AAVMF BootOrder without re-executing candidate" - echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: PASS" - echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: PASS" else fail "Repeated boot failed to stay on Default OS" - echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: FAIL" - echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: FAIL" fi +# Each invariant label is judged from its own evidence in BOTH Default boots. +sub6_consumed=FAIL; sub6_unchanged=FAIL +if log_consumed_ok "${b3}" && log_consumed_ok "${b4}"; then sub6_consumed=PASS; else fail "BootNext was not proven consumed in both Default boots"; fi +if log_unchanged_ok "${b3}" && log_unchanged_ok "${b4}"; then sub6_unchanged=PASS; else fail "Default BootOrder was not proven unchanged in both Default boots"; fi +echo "NATIVE_ROLLBACK_BOOTNEXT_CONSUMED: ${sub6_consumed}" +echo "NATIVE_ROLLBACK_DEFAULT_UNCHANGED: ${sub6_unchanged}" echo "" echo "============================================================" diff --git a/scripts/qemu_security_suite.sh b/scripts/qemu_security_suite.sh index 3d3da0f2..ffaa9f39 100755 --- a/scripts/qemu_security_suite.sh +++ b/scripts/qemu_security_suite.sh @@ -12,6 +12,42 @@ set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${repo_root}" +# judge_corrupt_rejection LOG: Subtest 3 verdict from the console log of the +# corrupted-image boot. PASS needs positive evidence that the firmware ran and +# the console was captured (the AAVMF banner), and no "kernel: alive". A missing +# or empty log, or a log without the banner, is FAIL: QEMU that never started +# must not read as "the firmware rejected the image". +judge_corrupt_rejection() { + local log="$1" + if [[ ! -f "${log}" ]]; then + echo "FAIL Corrupted-image boot left no console log: nothing shows the firmware ran"; return 1 + fi + if ! grep -q "UEFI firmware (version" "${log}"; then + echo "FAIL Corrupted-image console log has no firmware banner: QEMU or the firmware did not run, so no rejection was observed"; return 1 + fi + if grep -q "kernel: alive" "${log}"; then + echo "FAIL Corrupted binary unexpectedly reached kernel alive"; return 1 + fi + echo "PASS Corrupted binary cleanly rejected by firmware without reaching kernel alive (firmware banner present)" +} + +# --self-test: negative controls for judge_corrupt_rejection. No QEMU, no build. +if [[ "${1:-}" == --self-test ]]; then + st=0; t="$(mktemp -d)"; trap 'rm -rf "${t}"' EXIT + expect_rc() { # name want_rc log + local rc=0; judge_corrupt_rejection "$3" >/dev/null || rc=$? + if [[ "${rc}" == "$2" ]]; then echo "PASS $1 -> exit ${rc}"; else echo "FAIL $1: wanted ${2}, got ${rc}"; st=1; fi + } + printf 'UEFI firmware (version 2024.02 built at 12:48:22 on Jun 2 2026)\nBdsDxe: loading Boot0001 "UEFI Misc Device"\nBdsDxe: failed to load Boot0001\n' >"${t}/rejected.txt" + expect_rc "firmware ran, image rejected (no kernel: alive)" 0 "${t}/rejected.txt" + expect_rc "mutant: no log file at all (QEMU never started)" 1 "${t}/absent.txt" + : >"${t}/empty.txt"; expect_rc "mutant: empty console log" 1 "${t}/empty.txt" + printf 'qemu-system-aarch64: invalid option\n' >"${t}/nobanner.txt"; expect_rc "mutant: log without the firmware banner" 1 "${t}/nobanner.txt" + { cat "${t}/rejected.txt"; echo "kernel: alive"; } >"${t}/booted.txt"; expect_rc "mutant: corrupted image reached kernel: alive" 1 "${t}/booted.txt" + if [[ ${st} == 0 ]]; then echo "QEMU_SECURITY_SUITE_SELF_TEST: PASS"; exit 0; fi + echo "QEMU_SECURITY_SUITE_SELF_TEST: FAIL"; exit 1 +fi + code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" ITERATIONS="${GATE4_SOAK_RUNS:-5}" @@ -132,12 +168,7 @@ set -e if [[ -f "${corrupt_log}" ]]; then tr -d "\r" <"${corrupt_log}" >"${corrupt_work}/serial_corrupt.txt" [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${corrupt_work}/serial_corrupt.txt" "${AIENOS_LOG_DIR}/gate4_corrupt_serial.log" - if grep -q "kernel: alive" "${corrupt_work}/serial_corrupt.txt"; then - echo "FAIL Corrupted binary unexpectedly reached kernel alive" - exit 1 - else - echo "PASS Corrupted binary cleanly rejected by firmware without reaching kernel alive" - fi fi +judge_corrupt_rejection "${corrupt_work}/serial_corrupt.txt" || exit 1 echo "TRUST-1 Gate 4 Security Suite: ALL TESTS PASS" diff --git a/scripts/test_trust1_key_ceremony.sh b/scripts/test_trust1_key_ceremony.sh index c384d582..ee8db698 100755 --- a/scripts/test_trust1_key_ceremony.sh +++ b/scripts/test_trust1_key_ceremony.sh @@ -5,7 +5,9 @@ # backups each decrypt from their own copy; the record holds no private # material; a changed manifest, a swapped public key, and a wrong # passphrase are each refused; the Boot Signer cert can sign and verify an -# EFI image (when sbsign/sbverify and a built loader are present). +# EFI image (when sbsign/sbverify and a built loader are present; AIENOS_KEY_CEREMONY_EFI +# names another PE image). If that last check cannot run the verdict is NOT_RUN (exit 3), +# never ALL PASS. set -euo pipefail @@ -88,7 +90,8 @@ bash "${tool}" verify "${work}/gen1snap" 3 >/dev/null 2>&1 && fail "rollback to bash "${tool}" verify "${out}/public" 3 >/dev/null || fail "current generation 3 refused" pass "a validly signed older generation is refused when generation 3 is the minimum" -efi="${repo_root}/target/aarch64-unknown-uefi/release/aienos-handoff.efi" +efi="${AIENOS_KEY_CEREMONY_EFI:-${repo_root}/target/aarch64-unknown-uefi/release/aienos-handoff.efi}" +skipped_checks=() if command -v sbsign >/dev/null && command -v sbverify >/dev/null && [[ -f "${efi}" ]]; then "${OPENSSL}" pkey -in "${out}/private/boot_signer.key.pem" -passin file:"${work}/pass" \ -out "${work}/bs.key" 2>/dev/null @@ -98,7 +101,15 @@ if command -v sbsign >/dev/null && command -v sbverify >/dev/null && [[ -f "${ef || fail "Boot Signer signature does not verify" pass "Boot Signer cert signs and verifies the EFI loader (sbsign/sbverify)" else - echo "SKIP Boot Signer EFI signing (sbsign, sbverify or built loader missing)" + echo "SKIP Boot Signer EFI signing (sbsign, sbverify or built loader missing)"; skipped_checks+=("Boot Signer EFI signing") fi +# A skipped check is not a passed check. The ALL PASS line is printed only when +# every check ran; otherwise NOT_RUN and exit 3 (the qualify table maps 3 to +# NOT_RUN). +if [[ ${#skipped_checks[@]} -gt 0 ]]; then + printf 'NOT_RUN skipped check: %s\n' "${skipped_checks[@]}" + echo "TRUST-1 key ceremony self-test (throwaway keys): NOT_RUN (${#skipped_checks[@]} check(s) skipped; every other check passed)" + exit 3 +fi echo "TRUST-1 key ceremony self-test (throwaway keys): ALL PASS" diff --git a/scripts/trust1_gate7_preflight.sh b/scripts/trust1_gate7_preflight.sh index eef4a7fa..f5bcf867 100755 --- a/scripts/trust1_gate7_preflight.sh +++ b/scripts/trust1_gate7_preflight.sh @@ -171,7 +171,12 @@ else rc=$? fi grep -E '^(FAIL|SKIP)|^image not found' "${log}" | sed 's/^/ /' -check "every recovery tool is inside ${image_note}" "$([[ ${rc} -eq 0 ]] && echo 1 || echo 0)" +if [[ ${rc} -eq 3 ]]; then + # verify_recovery_tools.sh exits 3 when a check class was skipped (NOT_RUN). + fail "every recovery tool is inside ${image_note}: NOT CHECKED in full (verify_recovery_tools.sh skipped a check class and reported NOT_RUN)" +else + check "every recovery tool is inside ${image_note}" "$([[ ${rc} -eq 0 ]] && echo 1 || echo 0)" +fi echo "" echo "-- Not checked here (need Drake's reboots or later gates) --" diff --git a/scripts/trust1_m5_qualify.sh b/scripts/trust1_m5_qualify.sh index ab7dc32d..41a8ef34 100755 --- a/scripts/trust1_m5_qualify.sh +++ b/scripts/trust1_m5_qualify.sh @@ -48,9 +48,9 @@ set -uo pipefail # =========================================================================== GATE_TABLE=' t1_measurement_tools|software|run_measurement_tools|2|^TRUST-1 measurement tools self-test: ALL PASS$|TRUST-1 Gate 0/2 read-only tools self-test on a software TPM -t1_key_ceremony|software|run_key_ceremony|-|^TRUST-1 key ceremony self-test \(throwaway keys\): ALL PASS$|TRUST-1 Gate 3 key ceremony self-test with throwaway keys +t1_key_ceremony|software|run_key_ceremony|3|^TRUST-1 key ceremony self-test \(throwaway keys\): ALL PASS$|TRUST-1 Gate 3 key ceremony self-test with throwaway keys t1_gate7_preflight|software|run_gate7_preflight|-|^GATE7_PREFLIGHT: PASS|TRUST-1 Gate 7 read-only pre-flight (depends on operator state) -t1_recovery_tools|software|run_recovery_tools|-|^RECOVERY_TOOLS: PASS|recovery initrd ships mount, EFI repair and boot-entry restore tools +t1_recovery_tools|software|run_recovery_tools|3|^RECOVERY_TOOLS: PASS|recovery initrd ships mount, EFI repair and boot-entry restore tools store_torn_slot_c|software|run_store_c|-|^TORN_SLOT_HOST_EMULATION: PASS|Store C reference torn-write test (host block-device emulation) store_native_c|software|run_store_c|-|^AIENOS_STORE_NATIVE: PASS$|C twin of the System Store v1 engine + sealed Store (host file-backed; golden vectors byte-identical to Rust) store_rust_crosscheck|software|run_store_rust_xcheck|2|^STORE_RUST_CROSSCHECK: PASS$|Rust aienos-store-tool opens C-written stores and reads back the same generation and objects (C to Rust direction; NOT_RUN when the Rust tool is not built) @@ -617,9 +617,20 @@ self_test() { jq -e '.verdict == "NOT_QUALIFIED" and .counts.blocked == 1 and .gates[1].verdict == "NOT_RUN" and .gates[1].blocker == "BLOCKED_OPERATOR" and .gates[0].blocker == "-" and .tree_clean_before == true and .machine.pcr_sha256["1"] == "cd"' "${receipt_path}" >/dev/null \ && ok "receipt is valid JSON (jq) with expected fields" || bad "receipt is not valid JSON or fields wrong" else - echo "SKIP jq not installed; JSON validity not machine-checked" + echo "SKIP jq not installed; JSON validity not machine-checked"; jq_skipped=1 fi + # The two scripts that return 3 for "a check was skipped" must map to NOT_RUN + # through their table rows, never PASS and never an accidental FAIL. + for g in t1_key_ceremony t1_recovery_tools; do + row="$(grep "^${g}|" "${BASH_SOURCE[0]}" | head -1)" + IFS='|' read -r _ _ _ nrc marker _ <<<"${row}" + v="$(classify_log software 3 "${nrc}" "${marker}" /dev/null)" + [[ "${v%%|*}" == NOT_RUN ]] && ok "${g}: exit 3 (a skipped check) -> NOT_RUN" || bad "${g}: exit 3 classified ${v%%|*}" + v="$(classify_log software 0 "${nrc}" "${marker}" /dev/null)" + [[ "${v%%|*}" == FAIL ]] && ok "${g}: exit 0 without its marker line -> FAIL" || bad "${g}: exit 0 without marker classified ${v%%|*}" + done + # Quiet-flag header must match the rows (TR-02 inspector fix item 3). # Mutation: the flag is up while a QEMU gate is evaluated and down when # the receipt is written. The old header sampled only at write time and @@ -684,7 +695,8 @@ self_test() { fi rm -rf --one-file-system "${tmp}" - if [[ ${st_fail} == 0 ]]; then echo "TRUST1_M5_QUALIFY_SELF_TEST: PASS"; exit 0; fi + if [[ ${st_fail} == 0 && ${jq_skipped:-0} == 0 ]]; then echo "TRUST1_M5_QUALIFY_SELF_TEST: PASS"; exit 0; fi + if [[ ${st_fail} == 0 ]]; then echo "TRUST1_M5_QUALIFY_SELF_TEST: PASS (jq missing: receipt JSON validity NOT_RUN)"; exit 0; fi echo "TRUST1_M5_QUALIFY_SELF_TEST: FAIL"; exit 1 } diff --git a/scripts/verify_all.sh b/scripts/verify_all.sh index 61bc8720..254d084a 100755 --- a/scripts/verify_all.sh +++ b/scripts/verify_all.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash # AIENOS End-to-End Build and Evidence Verification Harness # Enforces sequential integration gates on the host DGX Spark environment. +# Last line: VERIFY_ALL: PASS only when every step ran; VERIFY_ALL: NOT_RUN if any step +# was skipped (scripts/lib_verify_summary.sh; test: bash scripts/lib_verify_summary.sh --self-test). set -euo pipefail # @@ -17,13 +19,8 @@ if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then fi cd "${REPO_ROOT}" -skipped() { - echo "SKIPPED: $*" - if [[ "${AIENOS_STRICT:-0}" == "1" ]]; then - echo "STRICT FAIL: a step was skipped under AIENOS_STRICT=1 ($*)" >&2 - exit 1 - fi -} +# shellcheck source=scripts/lib_verify_summary.sh +source "${REPO_ROOT}/scripts/lib_verify_summary.sh" echo "============================================================" echo "AIENOS Integration Verification Harness" @@ -178,12 +175,8 @@ else fi echo "" -echo "============================================================" -echo "HOST VERIFICATIONS PASSED." -echo "Config A: observed capture verified. M0 native-boot rollback proven in QEMU." -echo "Kernel: aarch64-unknown-none library compiles. Native boot remains untested." -echo "UEFI: diagnostic and GB10-discovering handoff images build; hardware boot remains untested." -echo "============================================================" +# Steps 1 to 6e (host checks and QEMU emulator runs) are done. The closing verdict is +# written once, at the very end, from what actually ran (final_verdict). # Step 7: TRUST-1 Gate 4 Security Suite (swTPM, Soak, Fault Injection) echo "" @@ -208,7 +201,7 @@ fi echo "" echo "--- [Recovery Media Tooling Manifest] ---" if command -v gzip >/dev/null && command -v cpio >/dev/null; then - ./scripts/verify_recovery_tools.sh + run_or_skip "recovery tool manifest" ./scripts/verify_recovery_tools.sh else skipped "gzip or cpio not present on host." fi @@ -241,7 +234,15 @@ fi echo "" echo "--- [TRUST-1 Gate 3 Key Ceremony Tool Self-Test] ---" if command -v openssl >/dev/null && openssl version | grep -q '^OpenSSL 3\.'; then - ./scripts/test_trust1_key_ceremony.sh 2>/dev/null + run_or_skip "TRUST-1 key ceremony self-test" bash -c 'exec ./scripts/test_trust1_key_ceremony.sh 2>/dev/null' else skipped "OpenSSL 3 not present on host." fi + +# Step 13: evidence receipts with hardcoded invariant labels must be amended. +echo "" +echo "--- [Evidence Receipt Label Lint] ---" +run_or_skip "receipt label lint self-test" ./scripts/check_receipt_labels.sh --self-test +run_or_skip "receipt label lint" ./scripts/check_receipt_labels.sh + +final_verdict diff --git a/scripts/verify_recovery_tools.sh b/scripts/verify_recovery_tools.sh index eac8ae75..192588e0 100755 --- a/scripts/verify_recovery_tools.sh +++ b/scripts/verify_recovery_tools.sh @@ -4,6 +4,10 @@ # restore boot entries. Host-side, static check only: extracts the built # initrd and greps for files and init hooks. No real devices, no root, no # QEMU boot (qemu_verify_recovery_media.sh already covers the boot itself). +# Verdict: PASS only when every check ran and passed; FAIL on any failed check +# (exit 1); NOT_RUN (exit 3) when a check class was skipped (readelf missing, or +# the test-only no-gocryptfs allowance in use). A skip is never a PASS. +# bash scripts/verify_recovery_tools.sh --self-test negative controls, no build. # Zero Disk Secrets and Unslop compliant. set -euo pipefail @@ -11,6 +15,55 @@ set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${REPO_ROOT}" +# --self-test: negative controls on a synthetic image. No build, no QEMU, no +# root. Proves the verdict follows the checks: a missing tool is FAIL, a +# skipped check class (no gocryptfs allowed, no readelf) is NOT_RUN (exit 3), +# and only a complete, unskipped image is PASS. +if [[ "${1:-}" == --self-test ]]; then + self="${REPO_ROOT}/scripts/verify_recovery_tools.sh" + command -v readelf >/dev/null || { echo "NOT_RUN self-test needs readelf on this host"; echo "RECOVERY_TOOLS_SELF_TEST: NOT_RUN"; exit 3; } + t="$(mktemp -d)"; trap 'rm -rf "${t}"' EXIT + st=0 + mk_root() { # dir: a complete synthetic recovery root + local d="$1" f + mkdir -p "${d}/bin" "${d}/etc" "${d}/usr/local/sbin" "${d}/lib/aarch64-linux-gnu" + for f in busybox mount lsblk blkid cryptsetup fsck.vfat mkfs.vfat fsck.ext4 efibootmgr chroot findmnt \ + tpm2_pcrread sbverify age gocryptfs fusermount3; do + : >"${d}/bin/${f}"; chmod +x "${d}/bin/${f}" + done + : >"${d}/usr/local/sbin/collect_recovery_boot_evidence" + : >"${d}/lib/aarch64-linux-gnu/libtss2-tcti-device.so.0" + printf 'nvme.ko\ndm-crypt.ko\n' >"${d}/etc/aienos-modules.order" + printf '#!/bin/sh\n# aienos.test=1\n# efibootmgr\nexec /bin/sh\n' >"${d}/init"; chmod +x "${d}/init" + } + mk_img() { (cd "$1" && find . | cpio -o -H newc --quiet 2>/dev/null) | gzip -c >"$2"; } + # expect NAME RC MARKER IMAGE [PATH_OVERRIDE] [ALLOW_NO_GOCRYPTFS] + expect() { + local name="$1" want_rc="$2" want="$3" img="$4" path="${5:-${PATH}}" allow="${6:-0}" rc=0 out + out="$(PATH="${path}" AIENOS_RECOVERY_ALLOW_NO_GOCRYPTFS="${allow}" /bin/bash "${self}" "${img}" 2>&1)" || rc=$? + if [[ "${rc}" == "${want_rc}" ]] && grep -q "^RECOVERY_TOOLS: ${want}" <<<"${out}"; then + echo "PASS ${name} -> ${want} (exit ${rc})" + else + echo "FAIL ${name}: want ${want} exit ${want_rc}, got exit ${rc}: $(grep '^RECOVERY_TOOLS:' <<<"${out}" || echo 'no verdict line')"; st=1 + fi + } + mk_root "${t}/full"; mk_img "${t}/full" "${t}/full.img" + expect "complete image" 0 PASS "${t}/full.img" + mk_root "${t}/noage"; rm "${t}/noage/bin/age"; mk_img "${t}/noage" "${t}/noage.img" + expect "mutant: age deleted from the image" 1 FAIL "${t}/noage.img" + mk_root "${t}/nogo"; rm "${t}/nogo/bin/gocryptfs"; mk_img "${t}/nogo" "${t}/nogo.img" + expect "mutant: gocryptfs missing, not allowed" 1 FAIL "${t}/nogo.img" + expect "gocryptfs missing, test-only allowance -> check skipped" 3 NOT_RUN "${t}/nogo.img" "${PATH}" 1 + # A PATH with the tools the script needs but no readelf: the closure check cannot run. + mkdir -p "${t}/nopath" + for c in gzip cpio sed grep mktemp rm mkdir readlink head cat dirname basename sort wc tr; do + ln -s "$(command -v "${c}")" "${t}/nopath/${c}" + done + expect "readelf absent -> library closure checks skipped" 3 NOT_RUN "${t}/full.img" "${t}/nopath" + if [[ ${st} == 0 ]]; then echo "RECOVERY_TOOLS_SELF_TEST: PASS"; exit 0; fi + echo "RECOVERY_TOOLS_SELF_TEST: FAIL"; exit 1 +fi + WORK_DIR=$(mktemp -d) trap 'rm -rf "${WORK_DIR}"' EXIT @@ -45,6 +98,7 @@ echo "Extracting ${INITRD_IMG}..." gzip -dc "${INITRD_IMG}" | (cd "${ROOT_DIR}" && cpio -idm --quiet) FAILED=0 +SKIPS=() check() { if [[ "$2" == 1 ]]; then echo "PASS $1" @@ -91,7 +145,7 @@ check "tpm2 device transport library packaged (dlopen, not seen by ldd)" \ check "sbverify present" "$(have_file bin/sbverify)" check "age present" "$(have_file bin/age)" if [[ "${AIENOS_RECOVERY_ALLOW_NO_GOCRYPTFS:-0}" == 1 ]]; then - echo "SKIP gocryptfs present (TEST-ONLY image built on a host without gocryptfs)" + echo "SKIP gocryptfs present (TEST-ONLY image built on a host without gocryptfs)"; SKIPS+=("gocryptfs present (TEST-ONLY image without gocryptfs)") else check "gocryptfs present" "$(have_file bin/gocryptfs)" fi @@ -129,7 +183,7 @@ if command -v readelf >/dev/null; then tcti="$(compgen -G "${ROOT_DIR}/lib/*-linux-gnu/libtss2-tcti-device.so.0" | head -n 1 || true)" [[ -z "${tcti}" ]] || check "tpm2 device transport: its libraries are inside the image" "$(closure_ok "$(readlink -f "${tcti}")")" else - echo "SKIP library closure checks (readelf not installed)" + echo "SKIP library closure checks (readelf not installed)"; SKIPS+=("library closure checks (readelf not installed)") fi echo "" @@ -144,4 +198,10 @@ if [[ "${FAILED}" != 0 ]]; then echo "RECOVERY_TOOLS: FAIL" exit 1 fi +# A skipped check is not a passed check: say NOT_RUN and exit 3, never PASS. +if [[ ${#SKIPS[@]} -gt 0 ]]; then + printf 'NOT_RUN skipped check: %s\n' "${SKIPS[@]}" + echo "RECOVERY_TOOLS: NOT_RUN (${#SKIPS[@]} check(s) skipped; every other check passed)" + exit 3 +fi echo "RECOVERY_TOOLS: PASS (initrd ships mount, EFI repair, and boot-entry restore capability)" ```