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/blob/main/scripts/qemu_artifact_test.sh # 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 branch `main` Branches Tags History `aienux / scripts / qemu_artifact_test.sh` 564 lines · 28608 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 # SEED-0B QEMU qualification (P2-5 loader, P2-6 SEED-0B artifact and 18 # Admission Receipt v0, P2-7 negative matrix) in QEMU AArch64 (UEFI, EL2). 19 # 20 # Firmware reads signed .AIEN files from \EFI\AIENOS\ARTIFACTS on the ESP and 21 # hands their bytes to the kernel, which stages, verifies, admits, loads and 22 # runs each one as an isolated EL0 task, then reclaims it. Two boots: 23 # 24 # 1. seed0b-qualification build (TEST ONLY qualification trust anchor): 25 # P26SEED first SEED-0B capability artifact: READ granted and used, 26 # WRITE through the READ handle denied, forged/never-issued/ 27 # zero handles denied, read past the grant denied, exits 0 28 # P25EXEC admitted, runs from the exact authenticated bytes, exits 0 29 # P25WX admitted, killed by a W^X permission fault on its code page 30 # P25SPIN admitted, killed when its admitted time budget runs out 31 # P25TAMP one payload byte flipped after signing: rejected BadSignature 32 # H01..H29 negative matrix (aienos-artifact-tool negative-corpus): each 33 # refused at its expected stage with its stable reason, or 34 # admitted and contained with its expected outcome 35 # 2. ordinary build (empty production trust set): every candidate refused; 36 # production trust fails closed. 37 # 38 # Every candidate must be reclaimed (all frames returned, no live 39 # capabilities) and emits an unsigned Admission Receipt v0; the host checks 40 # each binds the artifact it supplied and its observed outcome, matches the 41 # kernel digest, signs it with the TEST ONLY SEED-0B receipt key and 42 # verifies it. Canonical markers (ARTIFACT_*, SEED0B_*, ADMISSION_RECEIPT, 43 # HOSTILE_MATRIX, SEED_0B_QEMU) summarise the claims; each passes only if 44 # every check tagged with it passed. AIENOS_SEED0B_EVIDENCE= writes 45 # the evidence record. No physical hardware is touched. 46 # 47 # Captured-log mode (P2-9, Machine 1): AIENOS_SEED0B_SERIAL= 48 # with AIENOS_SEED0B_INPUTS= 49 # skips both QEMU boots, proves the staged inputs are byte-identical to a 50 # fresh deterministic pack and to their MANIFEST.sha256, that the inputs, the 51 # log and this clean checkout share one commit, that the log shows Machine 1's 52 # CPU identity, and applies the qualification-boot checks to the captured log 53 # with the SEED-0B-MACHINE1 tier (marker SEED_0B_MACHINE1). 54 # 55 # Needs qemu-system-aarch64 and AAVMF (Ubuntu: qemu-system-arm qemu-efi-aarch64). 56 set -euo pipefail 57 58 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 59 cd "${repo_root}" 60 61 code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" 62 vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" 63 captured="${AIENOS_SEED0B_SERIAL:-}" 64 if [[ -n "${captured}" ]]; then 65 [[ -r "${captured}" ]] || { echo "captured console log not readable: ${captured}"; exit 2; } 66 [[ -d "${AIENOS_SEED0B_INPUTS:-}" ]] || { echo "AIENOS_SEED0B_INPUTS must name the prepared inputs directory"; exit 2; } 67 tier_label=SEED-0B-MACHINE1 68 final_marker=SEED_0B_MACHINE1 69 else 70 command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; exit 2; } 71 [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; exit 2; } 72 tier_label=SEED-0B-QEMU 73 final_marker=SEED_0B_QEMU 74 fi 75 76 fixtures="crates/aienos-artifact-tool/fixtures/p2_5" 77 seed_fixtures="crates/aienos-artifact-tool/fixtures/p2_6" 78 work="$(mktemp -d)" 79 trap 'rm -rf "${work}"' EXIT 80 failed=0 81 82 # ---- claim categories ------------------------------------------------------- 83 CATEGORIES=(ARTIFACT_PARSE ARTIFACT_IDENTITY ARTIFACT_SIGNATURE ARTIFACT_ADMISSION 84 ARTIFACT_LOADED_BYTES ARTIFACT_WX SEED0B_AUTHORIZED_READ SEED0B_WRITE_DENIED 85 SEED0B_FORGED_DENIED SEED0B_RESOURCE_BOUND SEED0B_CLEANUP ADMISSION_RECEIPT HOSTILE_MATRIX) 86 declare -A seen=() bad=() 87 cats="" # categories the next checks count toward 88 rtag="" # which boot the next receipt files belong to 89 pass() { 90 echo "PASS $1" 91 local c 92 for c in ${cats}; do seen[$c]=1; done 93 } 94 fail() { 95 echo "FAIL $1" 96 failed=1 97 local c 98 for c in ${cats}; do bad[$c]=1; done 99 } 100 101 # ---- inputs ----------------------------------------------------------------- 102 # The committed probe bytes are the qualification inputs. When an assembler 103 # is available, prove they are exactly what probe.S assembles to. 104 as_bin=as 105 [[ "$(uname -m)" == "aarch64" ]] || as_bin=aarch64-linux-gnu-as 106 if command -v "${as_bin}" >/dev/null; then 107 "${fixtures}/assemble.sh" "${work}/asm" 108 "${seed_fixtures}/assemble.sh" "${work}/asm" 109 for pair in "${fixtures}:p25exec" "${fixtures}:p25wx" "${fixtures}:p25spin" "${seed_fixtures}:p26seed"; do 110 dir=${pair%%:*} probe=${pair##*:} 111 if cmp -s "${work}/asm/${probe}/code.bin" "${dir}/${probe}/code.bin"; then 112 pass "${probe} code.bin is exactly what probe.S assembles to" 113 else 114 fail "${probe} code.bin differs from probe.S" 115 fi 116 done 117 else 118 echo "NOTE no AArch64 assembler; using committed probe bytes unchecked" 119 fi 120 121 # Test-only signing: debug build by design (release refuses the feature). 122 cargo build --quiet -p aienos-artifact-tool --features seed0b-test-signing 123 tool="${CARGO_TARGET_DIR:-target}/debug/aienos-artifact-tool" 124 esp_art="${work}/esp/EFI/AIENOS/ARTIFACTS" 125 mkdir -p "${work}/esp/EFI/BOOT" "${esp_art}" 126 "${fixtures}/pack.sh" "${tool}" "${esp_art}" 127 "${seed_fixtures}/pack.sh" "${tool}" "${esp_art}" 128 "${tool}" negative-corpus "${esp_art}" >/dev/null 129 mv "${esp_art}/ids.txt" "${work}/ids.txt" 130 mv "${esp_art}/expected.txt" "${work}/expected.txt" 131 touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" 132 for f in "${esp_art}"/H*.AIEN; do 133 n=$(basename "${f}") 134 awk -v n="${n}" '$1 == n { found = 1 } END { exit !found }' "${work}/ids.txt" || echo "${n} $("${tool}" id "${f}" 2>/dev/null || echo none)" >>"${work}/ids.txt" 135 done 136 candidate_count=$(find "${esp_art}" -maxdepth 1 -name '*.AIEN' | wc -l) 137 if [[ -n "${captured}" ]]; then 138 cats="ARTIFACT_IDENTITY" 139 staged="${AIENOS_SEED0B_INPUTS}/ARTIFACTS" 140 if [[ ! -d "${staged}" ]]; then 141 echo "FAIL ${staged} is not a directory (AIENOS_SEED0B_INPUTS must be the prepared inputs root)" 142 echo "SEED_0B_MACHINE1: FAIL" 143 exit 1 144 fi 145 staged_count=$(find "${staged}" -maxdepth 1 -name '*.AIEN' | wc -l) 146 [[ "${staged_count}" == "${candidate_count}" ]] || fail "staged ${staged_count} candidates, expected ${candidate_count}" 147 for f in "${esp_art}"/*.AIEN; do 148 n=$(basename "${f}") 149 if cmp -s "${f}" "${staged}/${n}"; then 150 pass "staged ${n} is byte-identical to the deterministic pack" 151 else 152 fail "staged ${n} differs from the deterministic pack" 153 fi 154 done 155 156 # Bind log -> inputs -> this checkout, and log -> Machine 1. A captured log 157 # is operator-attested (TRUST-1 adds measured boot); these checks stop the 158 # honest mix-ups: a log from another commit, other inputs, or QEMU. 159 manifest="${AIENOS_SEED0B_INPUTS}/MANIFEST.sha256" 160 inputs_commit="" 161 if [[ ! -r "${manifest}" ]]; then 162 fail "prepared inputs carry MANIFEST.sha256" 163 else 164 if (cd "${AIENOS_SEED0B_INPUTS}" && grep -v '^#' MANIFEST.sha256 | sha256sum --check --strict --quiet); then 165 pass "staged inputs match MANIFEST.sha256" 166 else 167 fail "staged inputs do not match MANIFEST.sha256" 168 fi 169 listed=$(grep -vc '^#' "${manifest}" || true) 170 present=$(cd "${AIENOS_SEED0B_INPUTS}" && find . -type f ! -name MANIFEST.sha256 | wc -l) 171 if [[ "${listed}" == "${present}" ]]; then 172 pass "MANIFEST.sha256 lists every staged file (${present})" 173 else 174 fail "MANIFEST.sha256 lists ${listed} files but ${present} are staged" 175 fi 176 inputs_commit=$(sed -n 's/^# commit \([0-9a-f]\{40\}\)$/\1/p' "${manifest}") 177 fi 178 head_commit=$(git rev-parse HEAD) 179 if [[ -n "${inputs_commit}" && "${inputs_commit}" == "${head_commit}" ]]; then 180 pass "inputs were prepared from this checkout's commit ${head_commit}" 181 else 182 fail "inputs commit '${inputs_commit}' is not this checkout's HEAD ${head_commit}" 183 fi 184 if [[ -z "$(git status --porcelain)" ]]; then 185 pass "checkout is clean" 186 else 187 fail "checkout has uncommitted changes" 188 fi 189 log_commit=$(tr -d '\r' <"${captured}" | sed -n 's/^aienos_commit: //p' | sort -u) 190 if [[ -n "${inputs_commit}" && "${log_commit}" == "${inputs_commit}" ]]; then 191 pass "captured log was produced by the prepared image's commit" 192 else 193 fail "captured log commit '${log_commit}' is not the inputs commit '${inputs_commit}'" 194 fi 195 # Machine 1 CPU identity (evidence/m2_first_boot_2026-09-24.md): 20 cores, 196 # boot core Cortex-A725 (part 0xd87) or Cortex-X925 (0xd85). 197 if tr -d '\r' <"${captured}" | grep -q '^cpu_cores: 20$' && \ 198 tr -d '\r' <"${captured}" | grep -qE '^boot_cpu_midr: 0x[0-9a-f]+ \(part 0xd8[57]\)$'; then 199 pass "captured log shows Machine 1 CPU identity (20 cores, A725/X925 boot core)" 200 else 201 fail "captured log does not show Machine 1 CPU identity; a QEMU log cannot qualify Machine 1" 202 fi 203 cats="" 204 fi 205 id_prefix() { # name -> first 16 hex digits of its ArtifactId 206 awk -v n="$1" '$1 == n { print substr($2, 1, 16) }' "${work}/ids.txt" 207 } 208 209 commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" 210 build_image() { # features, output 211 AIENOS_COMMIT="${commit}" AIENOS_RESTART_SECS=1 cargo build --quiet --release \ 212 -p aienos-boot --target aarch64-unknown-uefi --features "$1" --bin aienos-handoff 213 cp "${CARGO_TARGET_DIR:-target}"/aarch64-unknown-uefi/release/aienos-handoff.efi "$2" 214 } 215 if [[ -z "${captured}" ]]; then 216 build_image seed0b-qualification "${work}/qualification.efi" 217 build_image handoff "${work}/production.efi" 218 fi 219 220 boot() { # image, serial text output 221 cp "$1" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" 222 cp "${vars_fd}" "${work}/vars.fd" 223 local log="${work}/serial.log" started status 224 started=$(date +%s) 225 set +e 226 # Issue #61: single-threaded TCG; MTTCG hung in 1/40 soak boots. 227 timeout "${AIENOS_QEMU_TIMEOUT:-300}" qemu-system-aarch64 \ 228 -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ 229 -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ 230 -drive if=pflash,format=raw,file="${work}/vars.fd" \ 231 -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ 232 -device virtio-blk-pci,drive=esp \ 233 -device ramfb -display none -nic none \ 234 -serial file:"${log}" -no-reboot 235 status=$? 236 set -e 237 tr -d '\r' <"${log}" >"$2" 238 echo "qemu exit ${status} after $(( $(date +%s) - started )) s (commit ${commit:0:12})" 239 [[ "${status}" != 124 ]] || { cats=""; fail "QEMU timed out (no reset)"; } 240 } 241 242 has() { grep -qE -- "$2" "$1"; } 243 check() { # serial, description, extended regex 244 if has "$1" "$3"; then pass "$2"; else fail "$2"; fi 245 } 246 common_checks() { # serial 247 cats="" 248 check "$1" "left firmware and entered the kernel" "kernel: alive" 249 check "$1" "M3 cooperative threads unchanged" "threads: ok" 250 check "$1" "M3 EL0 isolation proof unchanged" "el0: ok write=granted forged=denied fault=contained exit=0" 251 check "$1" "M3 typed IPC proof unchanged" "ipc: ok message=delivered cap=delegated rights=attenuated forged=denied revoked=denied" 252 check "$1" "firmware read all ${candidate_count} artifact candidates" "^artifact_candidates: ${candidate_count}$" 253 if grep -q "^report-truncated:" "$1"; then 254 fail "kernel report lines were truncated: $(grep "^report-truncated:" "$1" | tr '\n' ' ')" 255 else 256 pass "no kernel report line was truncated" 257 fi 258 check "$1" "final report reached the console" "report_kind: final" 259 if has "$1" "report_kind: (panic|fault)"; then fail "panic or fault reported"; fi 260 if has "$1" "^receipt: [^ ]+ seq=[0-9]+ invalid$"; then fail "a candidate produced no valid receipt"; fi 261 cats="SEED0B_CLEANUP" 262 local before after 263 before=$(grep -oE "artifact_frames_free_before: [0-9]+" "$1" | awk '{print $2}' | tail -1) 264 after=$(grep -oE "artifact_frames_free_after: [0-9]+" "$1" | awk '{print $2}' | tail -1) 265 if [[ -n "${before}" && "${before}" == "${after}" ]]; then 266 pass "every frame returned after all candidates (${before} free before and after)" 267 else 268 fail "frame accounting across candidates (before=${before:-?} after=${after:-?})" 269 fi 270 cats="" 271 } 272 273 # receipt_check SERIAL NAME PATTERN: the kernel's unsigned receipt for NAME 274 # must decode, bind the supplied artifact, match PATTERN, carry the digest 275 # the host recomputes, and sign/verify with the TEST ONLY receipt key. 276 receipt_check() { 277 local serial="$1" name="$2" want="$3" line record kdigest out 278 line=$(grep -E "^receipt: ${name//./\\.} seq=[0-9]+ digest=[0-9a-f]{64} record=[0-9a-f]{1024}$" "${serial}" | tail -1 || true) 279 if [[ -z "${line}" ]]; then 280 fail "${name} receipt emitted" 281 return 282 fi 283 record=${line##*record=} 284 kdigest=$(sed -E 's/.* digest=([0-9a-f]{64}) .*/\1/' <<<"${line}") 285 local file="${work}/${rtag}-${name}.receipt" 286 "${tool}" receipt from-hex "${record}" "${file}" >/dev/null 287 if ! out=$("${tool}" receipt check "${file}" "${esp_art}/${name}" 2>&1); then 288 fail "${name} receipt binds the supplied artifact (${out})" 289 return 290 fi 291 if [[ "${out}" != *"digest=${kdigest} "* ]]; then 292 fail "${name} receipt digest recomputed by the host" 293 return 294 fi 295 if ! grep -qE -- "${want}" <<<"${out}"; then 296 fail "${name} receipt records the observed outcome (${out})" 297 return 298 fi 299 "${tool}" receipt sign-test "${file}" "${file}.signed" >/dev/null 300 if "${tool}" receipt verify "${file}.signed" | grep -q "RECEIPT_VERIFY: PASS digest=${kdigest} "; then 301 pass "${name} receipt: bound, host digest match, observed outcome, TEST ONLY signature verifies" 302 else 303 fail "${name} signed receipt verifies" 304 fi 305 } 306 307 stage_code() { case "$1" in received) echo 1;; staged) echo 2;; verified) echo 3;; authorized) echo 4;; 308 reserved) echo 5;; mapped) echo 6;; hashed) echo 7;; sealed) echo 8;; caps) echo 9;; *) echo x;; esac; } 309 status_of() { case "$1" in exited:*) echo Exited;; timeout) echo Timeout;; fault:*) echo Fault;; 310 bad-syscall:*) echo BadSyscall;; resource-overrun) echo ResourceOverrun;; *) echo NotRun;; esac; } 311 # Categories a negative-matrix case supports beyond HOSTILE_MATRIX. 312 case_cats() { 313 case "$1" in 314 H0[1-9]-*|H10-*|H17-*|H18-*|H19-*|H20-*) echo "ARTIFACT_PARSE";; 315 H1[1-6]-*) echo "ARTIFACT_SIGNATURE";; 316 H21-*) echo "ARTIFACT_LOADED_BYTES ARTIFACT_IDENTITY";; 317 H22-*|H23-*|H24-*) echo "ARTIFACT_WX";; 318 H25-*|H26-*) echo "SEED0B_RESOURCE_BOUND";; 319 H27-*|H28-*|H29-*) echo "ARTIFACT_ADMISSION";; 320 esac 321 } 322 323 # ---- boot 1: qualification build ------------------------------------------- 324 qual="${work}/qualification.txt" 325 rtag=qual 326 if [[ -n "${captured}" ]]; then 327 tr -d '\r' <"${captured}" >"${qual}" 328 else 329 boot "${work}/qualification.efi" "${qual}" 330 fi 331 common_checks "${qual}" 332 check "${qual}" "qualification build is labelled TEST ONLY" \ 333 "artifact_trust: seed0b-test qualification build — TEST ONLY" 334 check "${qual}" "receipts carry the ${tier_label} tier" "^artifact_receipt_tier: ${tier_label}$" 335 336 admitted_line() { # name, exec regex, caps -> regex for an admitted, reclaimed candidate 337 echo "^artifact: ${1//./\\.} admitted id=$(id_prefix "$1") tier=seed0b-test exec=$2 bytes=identified=verified=admitted=mapped=executed wx=enforced caps=$3 revoked=yes reclaimed=yes frames=[0-9]+ " 338 } 339 340 cats="SEED0B_AUTHORIZED_READ SEED0B_WRITE_DENIED SEED0B_FORGED_DENIED ARTIFACT_IDENTITY ARTIFACT_ADMISSION ARTIFACT_LOADED_BYTES ARTIFACT_WX SEED0B_CLEANUP" 341 check "${qual}" "P26SEED (first SEED-0B capability artifact) read through its grant, WRITE and forged authority denied, exit 0, reclaimed" \ 342 "$(admitted_line P26SEED.AIEN exited:0x0 1)syscalls=9 reads=3 denials=5$" 343 cats="ARTIFACT_ADMISSION" 344 check "${qual}" "P26SEED granted exactly its READ request (granted ⊆ requested)" \ 345 "^grant: P26SEED\.AIEN\[0\] kind=object id=1 rights=0x1 bounds=0\+32 max_ops=4 max_bytes=32$" 346 if [[ $(grep -c "^grant: P26SEED\.AIEN\[" "${qual}") == 1 ]]; then pass "P26SEED holds exactly one capability"; else fail "P26SEED holds exactly one capability"; fi 347 cats="ADMISSION_RECEIPT SEED0B_AUTHORIZED_READ SEED0B_WRITE_DENIED SEED0B_FORGED_DENIED" 348 receipt_check "${qual}" P26SEED.AIEN "decision=Admitted tier=${tier_label} stage=0 reason=0x0 status=Exited exit=0 syscalls=9 reads_ok=3 denials=5 flags=0xff$" 349 350 cats="ARTIFACT_IDENTITY ARTIFACT_LOADED_BYTES SEED0B_CLEANUP" 351 check "${qual}" "P25EXEC admitted and executed its exact authenticated bytes, exit 0, caps revoked, reclaimed" \ 352 "$(admitted_line P25EXEC.AIEN exited:0x0 1)syscalls=3 reads=1 denials=1$" 353 cats="ARTIFACT_WX SEED0B_CLEANUP" 354 check "${qual}" "P25WX admitted then killed by W^X fault on its code page, reclaimed" \ 355 "$(admitted_line P25WX.AIEN fault:code-write 0)syscalls=0 reads=0 denials=0$" 356 cats="SEED0B_RESOURCE_BOUND SEED0B_CLEANUP" 357 check "${qual}" "P25SPIN admitted then killed at its time budget, reclaimed" \ 358 "$(admitted_line P25SPIN.AIEN timeout 0)syscalls=0 reads=0 denials=0$" 359 cats="ARTIFACT_SIGNATURE SEED0B_CLEANUP" 360 check "${qual}" "P25TAMP (payload byte flipped after signing) rejected BadSignature, reclaimed" \ 361 "^artifact: P25TAMP\.AIEN rejected stage=verified reason=BadSignature reclaimed=yes$" 362 cats="ADMISSION_RECEIPT" 363 receipt_check "${qual}" P25EXEC.AIEN "decision=Admitted .* status=Exited exit=0 syscalls=3 reads_ok=1 denials=1 flags=0xfd$" 364 receipt_check "${qual}" P25WX.AIEN "decision=Admitted .* status=Fault exit=0 syscalls=0 reads_ok=0 denials=0 flags=0xe4$" 365 receipt_check "${qual}" P25SPIN.AIEN "decision=Admitted .* status=Timeout exit=0 syscalls=0 reads_ok=0 denials=0 flags=0xe4$" 366 receipt_check "${qual}" P25TAMP.AIEN "decision=Rejected .* stage=3 reason=0x12 status=NotRun exit=0 syscalls=0 reads_ok=0 denials=0 flags=0x04$" 367 368 matrix_total=0 matrix_admitted=0 369 while read -r name decision a b c _; do 370 [[ -n "${name}" ]] || continue 371 matrix_total=$((matrix_total + 1)) 372 cats="HOSTILE_MATRIX SEED0B_CLEANUP $(case_cats "${name}")" 373 if [[ "${decision}" == rejected ]]; then 374 check "${qual}" "${name} refused at ${a} (${b}), never ran, reclaimed" \ 375 "^artifact: ${name//./\\.} rejected stage=${a} reason=${b} reclaimed=yes$" 376 cats="HOSTILE_MATRIX ADMISSION_RECEIPT" 377 receipt_check "${qual}" "${name}" "decision=Rejected .* stage=$(stage_code "${a}") reason=${c} status=NotRun exit=0 syscalls=0 reads_ok=0 denials=0 flags=0x04$" 378 else 379 matrix_admitted=$((matrix_admitted + 1)) 380 check "${qual}" "${name} admitted and contained (${a}), reclaimed" "$(admitted_line "${name}" "${a}" "${b}")" 381 cats="HOSTILE_MATRIX ADMISSION_RECEIPT" 382 receipt_check "${qual}" "${name}" "decision=Admitted .* status=$(status_of "${a}") " 383 fi 384 done < <(sed 's/ #.*//' "${work}/expected.txt") 385 cats="ARTIFACT_ADMISSION HOSTILE_MATRIX" 386 check "${qual}" "H29 requested READ|WRITE and was granted READ only" \ 387 "^grant: H29-READ-WRITE-REQUEST\.AIEN\[0\] kind=object id=1 rights=0x1 " 388 if has "${qual}" "^grant: H28-"; then fail "H28 (WRITE-only request) received a capability"; else pass "H28 requested only WRITE and received no capability"; fi 389 cats="" 390 check "${qual}" "final report summarises every admission decision" \ 391 "artifacts: candidates=${candidate_count} admitted=$((4 + matrix_admitted)) rejected=$((1 + matrix_total - matrix_admitted))" 392 393 # ---- boot 2: ordinary build, empty production trust ------------------------- 394 prod="${work}/production.txt" 395 rtag=prod 396 if [[ -z "${captured}" ]]; then 397 boot "${work}/production.efi" "${prod}" 398 common_checks "${prod}" 399 cats="ARTIFACT_SIGNATURE" 400 if has "${prod}" "seed0b-test qualification build"; then 401 fail "ordinary build must not carry the qualification label" 402 fi 403 if has "${prod}" "^artifact: [^ ]+ admitted"; then 404 fail "ordinary build admitted an artifact" 405 else 406 pass "ordinary build admitted nothing" 407 fi 408 prod_expect() { # name -> "stage reason code" in the ordinary build 409 local line 410 line=$(sed 's/ #.*//' "${work}/expected.txt" | awk -v n="$1" '$1 == n') 411 if [[ -n "${line}" ]] && read -r _ d s r c <<<"${line}" && [[ "${d}" == rejected && "${s}" == verified \ 412 && "${r}" != BadSignature && "${r}" != UntrustedSigner ]]; then 413 echo "${s} ${r} ${c}" # structural refusal precedes any trust decision 414 else 415 echo "verified UntrustedSigner 0x11" 416 fi 417 } 418 for f in "${esp_art}"/*.AIEN; do 419 name=$(basename "${f}") 420 read -r s r c <<<"$(prod_expect "${name}")" 421 cats="ARTIFACT_SIGNATURE SEED0B_CLEANUP" 422 check "${prod}" "ordinary build refuses ${name} (${r}), reclaimed" \ 423 "^artifact: ${name//./\\.} rejected stage=${s} reason=${r} reclaimed=yes$" 424 cats="ADMISSION_RECEIPT" 425 receipt_check "${prod}" "${name}" "decision=Rejected .* stage=$(stage_code "${s}") reason=${c} status=NotRun .* flags=0x04$" 426 done 427 cats="" 428 check "${prod}" "final report summarises zero admitted" \ 429 "artifacts: candidates=${candidate_count} admitted=0 rejected=${candidate_count}" 430 fi 431 432 if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then 433 cp "${qual}" "${AIENOS_LOG_DIR}/qemu_artifact_qualification_serial.log" 434 [[ -n "${captured}" ]] || cp "${prod}" "${AIENOS_LOG_DIR}/qemu_artifact_production_serial.log" 435 fi 436 437 # ---- canonical markers ----------------------------------------------------- 438 markers="" 439 all_ok=1 440 for c in "${CATEGORIES[@]}"; do 441 if [[ -n "${seen[$c]:-}" && -z "${bad[$c]:-}" ]]; then 442 markers+="${c}: PASS"$'\n' 443 else 444 markers+="${c}: FAIL"$'\n' 445 all_ok=0 446 fi 447 done 448 [[ "${failed}" == 0 ]] || all_ok=0 449 if [[ "${all_ok}" == 1 ]]; then markers+="${final_marker}: PASS"; else markers+="${final_marker}: FAIL"; fi 450 echo "${markers}" 451 452 # ---- evidence record --------------------------------------------------------- 453 # Key fields of a candidate's report line (decision, outcome, W^X, caps, 454 # cleanup and counters), without the ArtifactId prefix. 455 observed() { 456 grep -E "^artifact: ${1//./\\.} " "${qual}" | sed -E \ 457 -e 's/^artifact: [^ ]+ //' -e 's/ id=[0-9a-f]+ tier=[a-z0-9-]+//' \ 458 -e 's/bytes=identified=verified=admitted=mapped=executed/bytes=match/' 459 } 460 if [[ -n "${AIENOS_SEED0B_EVIDENCE:-}" ]]; then 461 seed="${esp_art}/P26SEED.AIEN" 462 seed_receipt="${work}/qual-P26SEED.AIEN.receipt" 463 { 464 if [[ -n "${captured}" ]]; then 465 echo "# SEED-0B Machine 1 qualification evidence (captured console log)" 466 echo 467 echo "> TEST-ONLY SEED-0B qualification on Machine 1, checked from a captured console" 468 echo "> log. The artifact and receipt keys are RFC 8032 test vectors (TEST 1 artifact" 469 echo "> signer, TEST 2 receipt signer). This is not a production identity ceremony." 470 else 471 echo "# SEED-0B QEMU qualification evidence" 472 echo 473 echo "> TEST-ONLY SEED-0B qualification in QEMU. The artifact and receipt keys are" 474 echo "> RFC 8032 test vectors (TEST 1 artifact signer, TEST 2 receipt signer)." 475 echo "> This is not a production identity ceremony and not Machine 1 qualification." 476 fi 477 echo 478 echo "Generated by \`scripts/qemu_artifact_test.sh\` on $(date -u +%Y-%m-%dT%H:%M:%SZ)." 479 echo 480 echo "## Build and platform" 481 echo 482 echo '```text' 483 echo "git_commit: ${commit}" 484 echo "worktree_clean: $([[ -z "$(git status --porcelain 2>/dev/null)" ]] && echo yes || echo no)" 485 echo "rustc: $(rustc -V)" 486 echo "cargo: $(cargo -V)" 487 if [[ -z "${captured}" ]]; then 488 echo "qemu: $(qemu-system-aarch64 --version | head -1)" 489 echo "qemu_machine: virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 4 -m 2048" 490 echo "aavmf_code: ${code_fd} sha256=$(sha256sum "${code_fd}" | cut -d' ' -f1)" 491 echo "images: aienos-handoff.efi --features seed0b-qualification (boot 1), --features handoff (boot 2)" 492 else 493 echo "platform: Machine 1 (captured console log)" 494 echo "image: aienos-handoff.efi --features seed0b-qualification,hardware-staging (see inputs MANIFEST.sha256)" 495 fi 496 echo "host: $(uname -srm)" 497 echo '```' 498 echo 499 echo "## Canonical markers" 500 echo 501 echo '```text' 502 echo "${markers}" 503 echo '```' 504 echo 505 echo "## SEED-0B artifact: P26SEED.AIEN" 506 echo 507 echo '```text' 508 echo "file_sha256: $(sha256sum "${seed}" | cut -d' ' -f1)" 509 "${tool}" verify "${seed}" | sed 's/^/verify: /' 510 "${tool}" inspect "${seed}" | grep -E "^(capability\[|resource_envelope:)" | sed 's/^/requested: /' 511 grep -E "^grant: P26SEED\.AIEN" "${qual}" | sed 's/^/granted: /' 512 grep -E "^artifact_(policy_digest|verifier_identity|receipt_tier|frames_free_(before|after)):" "${qual}" 513 grep -E "^artifact: P26SEED\.AIEN " "${qual}" 514 echo '```' 515 echo 516 echo "Expected allowed operation: \`OBJECT_READ\` through the granted handle at offsets 0 and 24 (and 0 again after the denied write)." 517 echo "Expected denied operations: \`OBJECT_WRITE\` through the READ-only handle; \`OBJECT_READ\` with a forged-generation handle, a never-issued slot, the zero handle, and at offset 32 outside the grant." 518 echo "Observed: exit 0 (every expectation met), 9 syscalls, 3 successful reads, 5 denials; capability revoked; every frame reclaimed." 519 echo 520 echo "## Admission receipt (P26SEED.AIEN)" 521 echo 522 echo '```text' 523 grep -E "^receipt: P26SEED\.AIEN " "${qual}" | sed -E 's/ record=([0-9a-f]{64}).*/ record=\1…/' 524 "${tool}" receipt inspect "${seed_receipt}" 525 "${tool}" receipt verify "${seed_receipt}.signed" 526 echo '```' 527 echo 528 echo "## Matrix (qualification boot)" 529 echo 530 echo "\`bytes=match\` abbreviates identified = verified = admitted = mapped = executed bytes." 531 echo 532 echo "| Candidate | Expected | Observed |" 533 echo "|---|---|---|" 534 for n in P26SEED.AIEN P25EXEC.AIEN P25WX.AIEN P25SPIN.AIEN P25TAMP.AIEN; do 535 echo "| ${n} | see above | \`$(observed "${n}")\` |" 536 done 537 while IFS= read -r l; do 538 n=${l%% *} 539 what=${l#*# } 540 exp=$(sed 's/ #.*//' <<<"${l}" | cut -d' ' -f2-) 541 obs=$(observed "${n}") 542 echo "| ${n} (${what//|/\\|}) | ${exp} | \`${obs//|/\\|}\` |" 543 done <"${work}/expected.txt" 544 echo 545 if [[ -z "${captured}" ]]; then 546 echo "Ordinary build: all ${candidate_count} candidates refused (structural reasons unchanged, all others UntrustedSigner), each reclaimed with a verified receipt." 547 else 548 echo "Captured log: ${captured} (sha256 $(sha256sum "${captured}" | cut -d' ' -f1)); staged inputs byte-identical to the deterministic pack." 549 fi 550 echo 551 echo "Covered by host tests rather than QEMU (not inducible from outside the kernel): mapped-byte mismatch after copy, frame/shadow/scheduler reservation failure, writable code alias (W^X audit), executed-byte change." 552 } >"${AIENOS_SEED0B_EVIDENCE}" 553 echo "evidence written: ${AIENOS_SEED0B_EVIDENCE}" 554 fi 555 556 if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then 557 echo "---- serial console: qualification build ----" 558 cat "${qual}" 559 if [[ -z "${captured}" ]]; then 560 echo "---- serial console: ordinary build ----" 561 cat "${prod}" 562 fi 563 fi 564 [[ "${failed}" == 0 && "${all_ok}" == 1 ]] && echo "QEMU_ARTIFACT: PASS" || { echo "QEMU_ARTIFACT: FAIL"; exit 1; }