interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / verify_all.sh

286 lines · 13910 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# AIENOS End-to-End Build and Evidence Verification Harness
18# Enforces sequential integration gates on the host DGX Spark environment.
19# Last line: VERIFY_ALL: PASS only when every step ran; VERIFY_ALL: NOT_RUN if any step
20# was skipped (scripts/lib_verify_summary.sh; test: bash scripts/lib_verify_summary.sh --self-test).
21
22set -euo pipefail
23#
24# AIENOS_STRICT=1 turns every SKIPPED step into a failure, so a green strict
25# run proves every step really ran. AIENOS_LOG_DIR=<dir> makes the QEMU
26# scripts copy their serial logs into <dir> (used by scripts/m3_receipt.sh).
27# Without either variable the behaviour is unchanged.
28
29REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
30if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then
31 mkdir -p "${AIENOS_LOG_DIR}"
32 AIENOS_LOG_DIR="$(cd "${AIENOS_LOG_DIR}" && pwd)"
33 export AIENOS_LOG_DIR
34fi
35cd "${REPO_ROOT}"
36
37# This harness and the QEMU scripts it calls read build output from target/ in this
38# checkout (for example target/aarch64-unknown-uefi/release/aienos-boot.efi). A caller's
39# CARGO_TARGET_DIR elsewhere (the Spark judge sets a shared one per repository) made the
40# UEFI image check fail with "No such file or directory", and a shared directory can hand
41# a test binary built from another checkout. Build into this checkout's own target/.
42export CARGO_TARGET_DIR="${REPO_ROOT}/target"
43# The Spark judge runs gates with PATH=/var/lib/aien-run/cargo/bin:/usr/local/bin:/usr/bin:/bin, without the sbin
44# directories. Unprivileged tools from there are still needed (the recovery initrd build runs
45# `modprobe --show-depends`), so append them; earlier PATH entries keep precedence.
46export PATH="${PATH}:/usr/sbin:/sbin"
47
48# shellcheck source=scripts/lib_verify_summary.sh
49source "${REPO_ROOT}/scripts/lib_verify_summary.sh"
50
51echo "============================================================"
52echo "AIENOS Integration Verification Harness"
53echo "Host: $(uname -n) | Arch: $(uname -m) | Kernel: $(uname -r)"
54echo "Date: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
55echo "Strict: ${AIENOS_STRICT:-0} | Serial log dir: ${AIENOS_LOG_DIR:-none}"
56echo "============================================================"
57
58# Step 1: Gate 1 Verification (Config A Reference Bundle)
59echo ""
60echo "--- [Gate 1 Verification: Config A Freeze] ---"
61if [[ ! -f "evidence/config_a_reference_bundle.json" ]]; then
62 echo "Running freeze_reality.sh..."
63 ./scripts/freeze_reality.sh
64fi
65./scripts/verify_evidence.sh "evidence/config_a_reference_bundle.json"
66echo "PASS Gate 1 Config A reference bundle verified"
67
68# Step 1b: Formatting
69echo ""
70echo "--- [Formatting: cargo fmt --check] ---"
71cargo fmt --all --check
72echo "PASS formatting: cargo fmt --all --check"
73
74# Step 2: Host component test suite
75echo ""
76echo "--- [Host Component Testing: Workspace Crates] ---"
77cargo test --workspace -- --format=pretty
78echo "PASS host tests: cargo test --workspace -- --format=pretty"
79echo "PASS ABI conformance: frozen wire format golden bytes and roundtrips verified"
80
81# Step 3: Linting & Zero-Warning Enforcement
82echo ""
83echo "--- [Clippy Verification: -D warnings] ---"
84cargo clippy --workspace --all-targets -- -D warnings
85echo "PASS clippy: zero warnings with -D warnings"
86
87# Step 3b: target-only code (bare-metal kernel, UEFI images) is invisible to
88# the host clippy run above, so lint each shipped target/feature set too.
89echo ""
90echo "--- [Clippy Verification: AArch64 targets, -D warnings] ---"
91cargo clippy -p aienos-kernel --target aarch64-unknown-none --no-default-features -- -D warnings
92cargo clippy -p aienos-kernel --target aarch64-unknown-none --no-default-features --features seed0b-test-anchor -- -D warnings
93for features in firmware handoff seed0b-qualification usb-keyboard nvme-read nvme-write store-qual continuity-qual recovery-qual; do
94 cargo clippy -p aienos-boot --target aarch64-unknown-uefi --features "${features}" --bins -- -D warnings
95done
96echo "PASS clippy: aarch64-unknown-none kernel and aarch64-unknown-uefi images, zero warnings"
97
98# Step 3c: TEST-ONLY SEED-0B qualification code paths are feature-gated and
99# so absent from the default runs above; test and lint them explicitly.
100echo ""
101echo "--- [SEED-0B qualification features: tests and clippy] ---"
102cargo test -p aienos-artifact --features seed0b-test-anchor
103cargo test -p aienos-artifact-tool --features seed0b-test-signing
104cargo clippy -p aienos-artifact-tool --all-targets --features seed0b-test-signing -- -D warnings
105if cargo build --release -p aienos-artifact-tool --features seed0b-test-signing >/dev/null 2>&1; then
106 echo "FAIL release build accepted the TEST-ONLY SEED-0B signing identity" >&2
107 exit 1
108fi
109echo "PASS SEED-0B qualification features tested and linted; release build refuses the test signing identity"
110
111# Step 4: Bare-metal library compilation check (not a boot test)
112echo ""
113echo "--- [Bare-Metal Target Compilation Check] ---"
114cargo check -p aienos-kernel --target aarch64-unknown-none --no-default-features
115cargo build -p aienos-kernel --target aarch64-unknown-none --no-default-features
116echo "PASS AArch64 build: aienos-kernel for aarch64-unknown-none"
117
118# Step 5: Build an AArch64 UEFI diagnostic image and inspect its PE header.
119# This verifies the firmware entry artifact format, not a hardware boot.
120echo ""
121echo "--- [AArch64 UEFI Image Builds] ---"
122cargo build --release -p aienos-boot --target aarch64-unknown-uefi --features firmware --bin aienos-boot
123cargo run --quiet --release -p aienos-evidence -- verify-efi "${CARGO_TARGET_DIR:-target}"/aarch64-unknown-uefi/release/aienos-boot.efi
124cargo build --release -p aienos-boot --target aarch64-unknown-uefi --features handoff --bin aienos-handoff
125cargo run --quiet --release -p aienos-evidence -- verify-efi "${CARGO_TARGET_DIR:-target}"/aarch64-unknown-uefi/release/aienos-handoff.efi
126echo "PASS AArch64 build: aienos-boot.efi and aienos-handoff.efi PE headers verified"
127
128# Step 6: QEMU AArch64 UEFI Boot Verification (Emulator Boot Test)
129echo ""
130echo "--- [QEMU AArch64 UEFI Boot Verification] ---"
131if command -v qemu-system-aarch64 >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then
132 ./scripts/qemu_boot_test.sh
133else
134 skipped "qemu-system-aarch64 or AAVMF firmware not present on host."
135fi
136
137# Step 6a: P2-5 Binary Artifact loader. Signed candidates are staged,
138# verified, admitted, run at EL0 from their exact authenticated bytes under
139# W^X, and reclaimed; the ordinary build rejects every one (QEMU only).
140echo ""
141echo "--- [P2-5 Binary Artifact Loader in QEMU] ---"
142if command -v qemu-system-aarch64 >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then
143 ./scripts/qemu_artifact_test.sh
144else
145 skipped "qemu-system-aarch64 or AAVMF firmware not present on host."
146fi
147
148# Step 6b: SEED-0A USB keyboard candidate, proven in QEMU only (ADR 0012).
149echo ""
150echo "--- [SEED-0A USB Keyboard in QEMU (input.keyboard.usb)] ---"
151if command -v qemu-system-aarch64 >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then
152 # Never an unsafe DMA bypass build here: clear any inherited override.
153 unset AIENOS_UNSAFE_DMA_BYPASS AIENOS_BUILD_FEATURES
154 # Default mode: keyboard DMA only through a QEMU SMMUv3 stream.
155 AIENOS_QEMU_SMMU=1 ./scripts/qemu_keyboard_test.sh
156else
157 skipped "qemu-system-aarch64 or AAVMF firmware not present on host."
158fi
159
160# Step 6c: SMMUv3 DMA confinement of the xHCI keyboard, QEMU only.
161echo ""
162echo "--- [SMMUv3 DMA Confinement in QEMU] ---"
163if command -v qemu-system-aarch64 >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then
164 ./scripts/qemu_smmu_test.sh
165 # No SMMU and no bypass: the keyboard must stay unavailable, DMA off.
166 AIENOS_QEMU_SMMU=0 ./scripts/qemu_keyboard_test.sh
167else
168 skipped "qemu-system-aarch64 or AAVMF firmware not present on host."
169fi
170
171# Step 6d: M0 Native-Boot Rollback Verification (QEMU only).
172echo ""
173echo "--- [M0 Native-Boot Rollback Verification in QEMU] ---"
174if command -v qemu-system-aarch64 >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then
175 ./scripts/qemu_native_rollback_test.sh
176else
177 skipped "qemu-system-aarch64 or AAVMF firmware not present on host."
178fi
179
180# Step 6e: P3 native NVMe driver and System Store v1 over NVMe (QEMU only).
181# Read and write/flush in both DMA modes (SMMU-confined, and fail-closed with
182# no SMMU), 4K root-write atomicity, the 4K Store crash/reboot campaign and the
183# 512-byte Store campaign, the M4 continuity campaign (ADR 0016) and the
184# Recovery Core campaign (ADR 0006, TEST-ONLY operator key). Never an
185# unsafe DMA bypass build here.
186echo ""
187echo "--- [P3 NVMe + System Store v1 in QEMU] ---"
188if command -v qemu-system-aarch64 >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then
189 unset AIENOS_UNSAFE_DMA_BYPASS AIENOS_BUILD_FEATURES
190 AIENOS_QEMU_SMMU=1 ./scripts/qemu_nvme_test.sh
191 AIENOS_QEMU_SMMU=0 ./scripts/qemu_nvme_test.sh
192 AIENOS_QEMU_SMMU=1 ./scripts/qemu_nvme_rw_test.sh
193 AIENOS_QEMU_SMMU=0 ./scripts/qemu_nvme_rw_test.sh
194 ./scripts/qemu_nvme_atomicity_test.sh
195 ./scripts/qemu_store_crash_test.sh
196 ./scripts/qemu_store_512b_crash_test.sh
197 ./scripts/qemu_continuity_test.sh
198 ./scripts/qemu_recovery_test.sh
199else
200 skipped "qemu-system-aarch64 or AAVMF firmware not present on host."
201fi
202
203echo ""
204# Steps 1 to 6e (host checks and QEMU emulator runs) are done. The closing verdict is
205# written once, at the very end, from what actually ran (final_verdict).
206
207# Step 7: TRUST-1 Gate 4 Security Suite (swTPM, Soak, Fault Injection)
208echo ""
209echo "--- [TRUST-1 Gate 4 Security Suite Verification] ---"
210if command -v qemu-system-aarch64 >/dev/null && command -v swtpm >/dev/null && [[ -r "${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" ]]; then
211 GATE4_SOAK_RUNS=3 ./scripts/qemu_security_suite.sh
212else
213 skipped "qemu-system-aarch64, swtpm, or AAVMF firmware not present on host."
214fi
215
216# Step 8: TRUST-1 Gate 1 Standalone Recovery Verification (Zero-Disk Boot)
217echo ""
218echo "--- [TRUST-1 Gate 1 Standalone Recovery Verification] ---"
219if command -v qemu-system-aarch64 >/dev/null; then
220 ./scripts/qemu_verify_recovery_media.sh
221else
222 skipped "qemu-system-aarch64 not present on host."
223fi
224
225# Step 9: Recovery Media Tooling Manifest (issue #17; host-side, no real
226# devices, no root -- extracts the built initrd and checks file presence).
227echo ""
228echo "--- [Recovery Media Tooling Manifest] ---"
229if command -v gzip >/dev/null && command -v cpio >/dev/null; then
230 run_or_skip "recovery tool manifest" ./scripts/verify_recovery_tools.sh
231else
232 skipped "gzip or cpio not present on host."
233fi
234
235# Offline recovery media trust boundary (scratch files and throwaway keys).
236# The host-only test does not qualify shim enrollment or physical media.
237echo ""
238echo "--- [Recovery Media Security Regression] ---"
239if command -v mkfs.ext4 >/dev/null && command -v mkfs.vfat >/dev/null &&
240 command -v grub-mkstandalone >/dev/null && command -v sbsign >/dev/null &&
241 command -v sbverify >/dev/null && command -v openssl >/dev/null; then
242 run_or_skip "recovery media security" ./scripts/test_recovery_media_security.sh
243else
244 skipped "mkfs, GRUB standalone builder, OpenSSL or sbsigntool not present on host."
245fi
246
247# Step 10: TRUST-1 Gate 0/2 measurement tools (software TPM, no hardware).
248echo ""
249echo "--- [TRUST-1 Measurement Tools Self-Test] ---"
250# FLAG(sovereignty): tpm2_pcrread gate (tpm2-tools, outside dep) on host; replace with in-house C tool check.
251if command -v swtpm >/dev/null && command -v tpm2_pcrread >/dev/null && command -v xxd >/dev/null; then
252 ./scripts/test_trust1_measurement_tools.sh
253else
254 skipped "swtpm, tpm2-tools, or xxd not present on host."
255fi
256
257# Step 11: TRUST-1 Gate 4 Secure Boot enforcement in QEMU. Firmware with
258# Secure Boot ON and the published Debian "snakeoil" TEST key in PK/KEK/db:
259# signed loader boots, unsigned / one-byte-tampered / wrong-key are refused
260# with Access Denied. No owner key, no hardware.
261echo ""
262echo "--- [TRUST-1 Gate 4 Secure Boot Signing in QEMU] ---"
263if command -v qemu-system-aarch64 >/dev/null && command -v sbsign >/dev/null && command -v sbverify >/dev/null \
264 && [[ -r /usr/share/AAVMF/AAVMF_CODE.snakeoil.fd && -r /usr/share/qemu-efi-aarch64/PkKek-1-snakeoil.key ]]; then
265 ./scripts/qemu_secureboot_signing_test.sh
266else
267 skipped "qemu-system-aarch64, sbsigntool, or snakeoil AAVMF firmware not present on host."
268fi
269
270# Step 12: TRUST-1 Gate 3 key ceremony tool self-test. THROWAWAY keys in a
271# private temp folder only (deleted on exit); never an owner key.
272echo ""
273echo "--- [TRUST-1 Gate 3 Key Ceremony Tool Self-Test] ---"
274if command -v openssl >/dev/null && openssl version | grep -q '^OpenSSL 3\.'; then
275 run_or_skip "TRUST-1 key ceremony self-test" bash -c 'exec ./scripts/test_trust1_key_ceremony.sh 2>/dev/null'
276else
277 skipped "OpenSSL 3 not present on host."
278fi
279
280# Step 13: evidence receipts with hardcoded invariant labels must be amended.
281echo ""
282echo "--- [Evidence Receipt Label Lint] ---"
283run_or_skip "receipt label lint self-test" ./scripts/check_receipt_labels.sh --self-test
284run_or_skip "receipt label lint" ./scripts/check_receipt_labels.sh
285
286final_verdict