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/ck_pi5_manifest_check.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 / ck_pi5_manifest_check.sh` 84 lines ยท 7720 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 # ck_pi5_manifest_check.sh -- PI5-8 Q6 gate: the receipts manifest tool and its TEST-key signature round trip. 18 # 1. synthetic run folders -> manifest; second run gives identical bytes; order of arguments does not matter; 19 # 2. a missing run folder, an absent verdict line and an unknown run tag each make the tool fail with no output; 20 # 3. the owner signs a fixed statement binding the manifest length and sha256 (PIV Ed25519 takes a small message only); 21 # sign with the public RFC 8032 TEST 1 key (TEST ONLY) and verify with the in-tree Ed25519; a flipped manifest byte, 22 # a flipped signature byte, a different public key and a signature over the raw manifest must all fail to verify; 23 # 4. an openssl Ed25519 SOFTWARE key (TEST, stands in for the YubiKey) signs the statement and the tool verifies it. 24 # No owner or release key is generated or used. Set PI5_RUNS= to also build the manifest of real runs. 25 set -euo pipefail 26 root="$(cd "$(dirname "$0")/.." && pwd)" 27 tmp="$(mktemp -d)"; trap 'rm -rf "${tmp}"' EXIT 28 fail=0 29 ok() { echo "PASS $*"; } 30 bad() { echo "FAIL $*"; fail=1; } 31 cc -std=gnu11 -O1 -Wall -Wextra -Werror -I"${root}/native/sig" -I"${root}/native/argus" -o "${tmp}/sig" \ 32 "${root}/native/kernel/tools/ck_manifest_sig.c" "${root}/native/sig/`ed25519`.c" "${root}/native/sig/sha512.c" "${root}/native/sig/ct.c" "${root}/native/argus/sha256.c" 33 mk() { # tag efi commit log-lines... 34 local t="$1" e="$2" c="$3"; shift 3 35 mkdir -p "${tmp}/runs/${t}" 36 echo "[00:00:00Z] run ${t}: efi=/x/BOOTAA64.EFI sha256=${e}" > "${tmp}/runs/${t}/run.log" 37 { echo "aienos_commit: ${c}"; printf '%s\r\n' "$@"; } > "${tmp}/runs/${t}/kernel.log" 38 } 39 e1=$(printf 'a%.0s' $(seq 64)); e2=$(printf 'b%.0s' $(seq 64)); c1=$(printf '1%.0s' $(seq 40)) 40 printf 'pi5-x1\tT first\t^good: \npi5-x1\tT first\t^also=[0-9]+$\npi5-x2\tT second\t^other ok$\n' > "${tmp}/t.tsv" 41 mk pi5-x1 "${e1}" "${c1}" "good: yes" "noise" "also=42" 42 mk pi5-x2 "${e2}" "${c1}" "other ok" 43 M="${root}/scripts/pi5_receipts_manifest.sh" 44 "${M}" -t "${tmp}/t.tsv" "${tmp}/runs/pi5-x2" "${tmp}/runs/pi5-x1" > "${tmp}/m1" 45 "${M}" -t "${tmp}/t.tsv" "${tmp}/runs/pi5-x1" "${tmp}/runs/pi5-x2" > "${tmp}/m2" 46 if cmp -s "${tmp}/m1" "${tmp}/m2" && [ -s "${tmp}/m1" ]; then ok "manifest is deterministic and independent of argument order"; else bad "manifest not deterministic"; fi 47 grep -q "^efi_sha256 ${e1}$" "${tmp}/m1" && grep -q "^aienos_commit ${c1}$" "${tmp}/m1" && grep -q "^ | good: yes$" "${tmp}/m1" && grep -q "^runs 2$" "${tmp}/m1" \ 48 && ok "manifest carries efi sha256, commit, verdict lines (CR stripped)" || bad "manifest content" 49 if ! grep -q $'\r' "${tmp}/m1"; then ok "manifest has no carriage returns"; else bad "CR in manifest"; fi 50 if "${M}" -t "${tmp}/t.tsv" "${tmp}/runs/pi5-x1" "${tmp}/runs/pi5-nope" > "${tmp}/o" 2>"${tmp}/e"; then bad "missing run folder accepted"; elif [ ! -s "${tmp}/o" ] && grep -q MISSING "${tmp}/e"; then ok "missing run folder refused, no manifest"; else bad "missing run folder handling"; fi 51 printf 'pi5-x1\tT first\t^never matches$\n' > "${tmp}/t2.tsv" 52 if "${M}" -t "${tmp}/t2.tsv" "${tmp}/runs/pi5-x1" > "${tmp}/o" 2>"${tmp}/e"; then bad "absent verdict line accepted"; elif [ ! -s "${tmp}/o" ]; then ok "absent verdict line refused, no manifest"; else bad "absent verdict output"; fi 53 if "${M}" -t "${tmp}/t.tsv" "${tmp}/runs/pi5-x1" "${tmp}/runs/pi5-x2" "${tmp}/runs/pi5-x1" > "${tmp}/o3" 2>/dev/null && cmp -s "${tmp}/o3" "${tmp}/m1"; then ok "duplicate folder argument is folded"; else bad "duplicate folder"; fi 54 mkdir -p "${tmp}/runs/pi5-x3"; cp "${tmp}/runs/pi5-x1/"* "${tmp}/runs/pi5-x3/" 55 if "${M}" -t "${tmp}/t.tsv" "${tmp}/runs/pi5-x3" > "${tmp}/o" 2>/dev/null; then bad "run tag without table rows accepted"; else ok "run tag without table rows refused"; fi 56 # TEST-key signature round trip over the statement that binds the manifest 57 TPK=`d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a` 58 # the statement is exactly four LF lines and agrees with an independent sha256sum 59 "${tmp}/sig" statement "${tmp}/m1" "${tmp}/m1.st" 60 want="$(printf 'AIENOS-OWNER-STATEMENT-V1\npurpose pi5-8-receipts-manifest\nmanifest_bytes %s\nmanifest_sha256 %s\n' "$(wc -c < "${tmp}/m1")" "$(sha256sum < "${tmp}/m1" | cut -d' ' -f1)"; echo x)" 61 got="$(cat "${tmp}/m1.st"; echo x)" 62 if [ "${want}" = "${got}" ] && [ "$(wc -l < "${tmp}/m1.st")" = 4 ]; then ok "statement bytes match the spec and sha256sum"; else bad "statement bytes"; fi 63 "${tmp}/sig" sign-test "${tmp}/m1" "${tmp}/m1.sig" | tee "${tmp}/s.out" 64 grep -q "TEST ONLY" "${tmp}/s.out" && ok "sign-test says TEST ONLY" || bad "sign-test label" 65 "${tmp}/sig" verify "${tmp}/m1" "${tmp}/m1.sig" "${TPK}" | tee "${tmp}/v.out" && grep -q "^MANIFEST_SIG: PASS" "${tmp}/v.out" && ok "signature verifies with the in-tree Ed25519" || bad "verify" 66 cp "${tmp}/m1" "${tmp}/m1.bad"; printf 'X' | dd of="${tmp}/m1.bad" bs=1 seek=40 conv=notrunc 2>/dev/null 67 if "${tmp}/sig" verify "${tmp}/m1.bad" "${tmp}/m1.sig" "${TPK}" >/dev/null; then bad "tampered manifest verified"; else ok "tampered manifest fails to verify"; fi 68 cp "${tmp}/m1.sig" "${tmp}/s.bad"; printf 'Z' | dd of="${tmp}/s.bad" bs=1 seek=10 conv=notrunc 2>/dev/null 69 if "${tmp}/sig" verify "${tmp}/m1" "${tmp}/s.bad" "${TPK}" >/dev/null; then bad "tampered signature verified"; else ok "tampered signature fails to verify"; fi 70 if "${tmp}/sig" verify "${tmp}/m1" "${tmp}/m1.sig" `3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c` >/dev/null; then bad "wrong key verified"; else ok "wrong public key fails to verify"; fi 71 # a signature over the raw manifest (the old, pre-statement scheme) must not verify 72 openssl genpkey -algorithm ED25519 -out "${tmp}/sw.pem" 2>/dev/null 73 SWPK="$(openssl pkey -in "${tmp}/sw.pem" -pubout -outform DER | tail -c 32 | od -An -v -tx1 | tr -d ' \n')" 74 openssl pkeyutl -sign -rawin -inkey "${tmp}/sw.pem" -in "${tmp}/m1" -out "${tmp}/raw.sig" 75 if "${tmp}/sig" verify "${tmp}/m1" "${tmp}/raw.sig" "${SWPK}" >/dev/null; then bad "raw-manifest signature verified"; else ok "signature over the raw manifest is refused"; fi 76 # TEST software key standing in for the YubiKey: sign the statement bytes, verify through the tool 77 openssl pkeyutl -sign -rawin -inkey "${tmp}/sw.pem" -in "${tmp}/m1.st" -out "${tmp}/sw.sig" 78 "${tmp}/sig" verify "${tmp}/m1" "${tmp}/sw.sig" "${SWPK}" | tee "${tmp}/sv.out" 79 grep -q "^MANIFEST_SIG: PASS" "${tmp}/sv.out" && ok "openssl software key (TEST) signature over the statement verifies" || bad "software key verify" 80 if "${tmp}/sig" verify "${tmp}/m1.bad" "${tmp}/sw.sig" "${SWPK}" >/dev/null; then bad "software signature verified a tampered manifest"; else ok "software signature fails on a tampered manifest"; fi 81 if [ -n "${PI5_RUNS:-}" ]; then 82 "${M}" --all "${PI5_RUNS}" > "${tmp}/real" && echo "real manifest: $(grep -c '^run ' "${tmp}/real") runs, $(wc -c < "${tmp}/real") bytes, sha256 $(sha256sum < "${tmp}/real" | cut -d' ' -f1)" || bad "real runs manifest" 83 fi 84 [ "${fail}" = 0 ] && echo "PASS ck_pi5_manifest_check" || { echo "FAIL ck_pi5_manifest_check"; exit 1; }