diff --git a/.crumb b/.crumb index fe0a2520..5c12134e 100644 --- a/.crumb +++ b/.crumb @@ -27,8 +27,8 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "e9fd609c869a1f64d7d8c5e192b407adad34f50cfd25ec92ae84b1db2e34d53a", - "last_commit": "47216c3", + "digest": "d2b7dc151c8acb7896ad59cb1bf525b7a380502eda063a9dc24bc83d60d76d07", + "last_commit": "32256ba", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -39,21 +39,21 @@ "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "b5c64f0277790e020d9c0fde19cc064fafc5c64e1d37d4e92ed88f5a40e36da3", - "last_commit": "8ec0429", + "digest": "987eb5d8a450f5aaf1f821e428d30c06538cc5135d943892339157f9359e6938", + "last_commit": "32256ba", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:fedc4d4dda4ea94509bf93370b67d502d79280d1ccb31cfbd2401aeb392b3332", - "compiled_at": "2026-10-05T13:00:44Z", + "children_root": "sha256:6991afcf01ff2965aba6140ec23e294dcad019846fbb9670895ee4b172e86d60", + "compiled_at": "2026-10-05T19:26:03Z", "compiler": "crumb-compile/1", - "digest": "sha256:be62ad8ca85d3444b1d39e4b8039836839bb27b5dd08aaed18ee67a5b886c047", + "digest": "sha256:01d9117f8b03793a45b6ffc91c879be4997664e927541ea392413937238d02b8", "evidence_files": 147, "evidence_root": "sha256:3f1c80574189eaded43ead3929d21a74c01f77dee31e7b2e2bd3858e67155dc7", - "files": 2854, - "generated_at_commit": "47216c3161e3d69356a5ef0f08be5355a6286c2b", - "source_tree": "sha256:4db60f7840b6cc179702030acbf2e348dfc56cbe69d44d8fefccb569415012dc" + "files": 2857, + "generated_at_commit": "32256ba94a0bbabbe8f7ba201e7126b57fe4e4ea", + "source_tree": "sha256:c30d817e6a60a3ac5aa893fad88acd8e8f81ca7c39ebef83e3afa990f1d1d5fa" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 2e87ac53..c48bb0ee 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:25a2af14107c1c2ae96916dd5c4086195ebd4117975ea0ae458855ac21f46099", - "compiled_at": "2026-10-05T13:00:44Z", + "compiled_at": "2026-10-05T19:19:49Z", "compiler": "crumb-compile/1", - "digest": "sha256:e9fd609c869a1f64d7d8c5e192b407adad34f50cfd25ec92ae84b1db2e34d53a", + "digest": "sha256:d2b7dc151c8acb7896ad59cb1bf525b7a380502eda063a9dc24bc83d60d76d07", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 58, - "generated_at_commit": "47216c3161e3d69356a5ef0f08be5355a6286c2b", - "source_tree": "sha256:783c83e2171308054345aa053762fea7951c045f53765b9d3a8c92d2d855d502" + "files": 59, + "generated_at_commit": "6bbd3c685159e4c4db1bb45fdcf6f40c03c0d0a2", + "source_tree": "sha256:eac6b5430f0fafba3178dd56d2f4923f42873a295b545d6aab5c5e724cbda693" }, "owner_lane": "", "provenance": { diff --git a/docs/TRUST-1-ATTENDED-PACKAGE.md b/docs/TRUST-1-ATTENDED-PACKAGE.md new file mode 100644 index 00000000..bf35b562 --- /dev/null +++ b/docs/TRUST-1-ATTENDED-PACKAGE.md @@ -0,0 +1,145 @@ +# TRUST-1 attended package: what Drake does in person, in order + +## In plain words first + +This page is the one document to follow when you sit at the Spark for the security work. It +says what to prepare, what to do in each sitting, what you should see, what to do if it goes +wrong, and which security checks each sitting can help finish. It adds nothing new to the +plan. It gathers [TRUST-1-ATTENDED-SEQUENCE.md](TRUST-1-ATTENDED-SEQUENCE.md), +[TRUST-1-OPERATOR-STEPS.md](TRUST-1-OPERATOR-STEPS.md) and +[TRUST-1-M5-GATE-MATRIX.md](TRUST-1-M5-GATE-MATRIX.md) into one path, with the prerequisites +checked against the live machine on 2026-10-05 (19:17 UTC). + +Words used here, one sentence each: **Secure Boot** is the firmware switch that lets the +computer start only signed software (it is OFF now). **TPM** is the security chip. A **PCR** +is one numbered logbook slot in the TPM that records what started up. **Relock script** is +our helper that re-locks the three stored passwords to the current Secure Boot state. +**Evidence checker** is a new helper (below) that reads the files a sitting leaves behind and +refuses them if they are incomplete, wrong or failing. + +**Honest status (2026-10-05).** No attended boot, no recovery-stick boot under Secure Boot and +no key ceremony has happened since the baseline of 2026-10-03. Every row below that needs one of +those stays BLOCKED until it really happens and its evidence is recorded. Nothing on this page +marks a physical result as done. + +## 1. Prerequisites, checked against the live repos and machine + +Result column: OK means observed on 2026-10-05 19:17 UTC; the other tags are explained after the table. + +| # | Prerequisite | How to check (read-only) | Result | +|---|---|---|---| +| 1 | Repository is at the pinned work | `gh api repos/aien-dev/aienos/commits/main -q .sha` | OK: main is `6bbd3c6` (docs only after `bbad5e4`; the scripts are unchanged between them, `git diff --stat` lists only docs and crumbs) | +| 2 | Gate 2 tool copy is the one the runbook names | `sha256sum ~/workspace/aienos-recovery-gate/scripts/tpm_measurement_campaign.sh` | OK: `aac10377...4529`, byte-identical to main's file | +| 3 | Secure Boot state | `mokutil --sb-state` | OK for the Gate 2 sittings: `SecureBoot disabled` (it must be enabled only after sitting 3) | +| 4 | Booted by UEFI, boot entries | `efibootmgr` | OK: BootCurrent 0001, BootOrder 0001,0003, no stale USB entry | +| 5 | Recovery stick not plugged in | `lsblk` | OK: only the internal NVMe drive is present | +| 6 | Firmware-update timer paused | `systemctl is-enabled fwupd-refresh.timer` | OK: `disabled` | +| 7 | You may use the TPM | `id -nG` lists `tss`; `ls -l /dev/tpmrm0` | OK | +| 8 | Tools present | `command -v tpm2_pcrread tpm2_eventlog efibootmgr mokutil age sbsign sbverify openssl jq swtpm` | OK: all present | +| 9 | Spare copies of the three passwords on the Spark | `ls -l ~/.config/atlas/offline-spares/` | OK: five `.age` files, `MANIFEST.txt`, the public recipient file | +| 10 | Same spares on the MacBook | `ssh macbook 'ls -l ~/aienos-offline-recovery'` and compare `MANIFEST.txt` | OK, with a correction: MANIFEST.txt has the same digest on both machines (`093624fd...`). The MacBook folder holds a sixth file, `atlas-forge-state-luks-recovery-key.txt.age`, that the manifest does not list (see stale item S2) | +| 11 | Relock script exists | `ls -l ~/handoffs/secure-boot-off/after-restart.sh` | OK, but it lives only in the home folder, not in any repo (S3). Its three expected digests match the manifest | +| 12 | Test file from Step 3 | `cat ~/trust1-evidence/step3-roundtrip-fingerprint.txt` | OK: `32b2dc31...98a1` | +| 13 | Recovery stick `AIENOSRECOV` built and holding no secrets | `~/trust1-evidence/step4-stick-rebuild.txt` | OK on paper (built 2026-10-03 on `130aa20`); the stick itself is not plugged in, so its contents are UNVERIFIED today | +| 14 | No chip run in progress | `test -e ~/workspace/.spark-quiet` | OK: file absent at 19:17 UTC. Check again just before any restart: a restart during a chip run ruins that run | +| 15 | Gate 7 pre-flight | `bash scripts/trust1_gate7_preflight.sh` | EXPECTED FAIL: 23 passed, 2 failed (the two Secure Boot checks), as the sequence page predicts | +| 16 | Gate 2 attended runs already done | `ls ~/trust1-evidence` | None: no `g2-exp*` folders. Only the four baseline boots exist | +| 17 | Spare USB sticks | physical | MISSING: none (`step5-decision.txt`, 2026-10-03). Needed: 1 for the key (decision below) and 2 for the Gate 3 backups | +| 18 | Where the recovery key lives | `step5-decision.txt` | OPEN: Option B (key on the stick) was chosen, then Steps 4 to 6 were deferred. Option B clashes with the stick builder's "no secrets on the stick" rule; that rule needs a decision first | +| 19 | Firmware screen key and Secure Boot menu names | none recorded | UNVERIFIED: sitting 3 of Gate 2 is where you write them down | + +### Stale or imprecise items found in the existing docs and handoff + +- **S1.** The handoff and the sequence page say the chip window holds the quiet flag until about 14:25 UTC. It is over: the flag is absent now. Still re-check before a restart. +- **S2.** The handoff says the MacBook list "matches" the Spark: five `.age` spares. The MacBook folder actually has six `.age` files; the extra forge-state recovery key is not in `MANIFEST.txt`, and the relock script does not touch it. Whether anything needs it after Secure Boot flips is UNVERIFIED. +- **S3.** The sequence page names the relock script without a path. Its only copy is `~/handoffs/secure-boot-off/after-restart.sh`, outside git. Back it up before the Secure Boot sitting (a lost script leaves only the manual route). +- **S4.** The sequence page says the exact arguments of `tpm_measurement_campaign.sh receipt` are UNVERIFIED. They are now verified from the script (`scripts/tpm_measurement_campaign.sh` lines 13 and 216 to 232): `receipt --variable NAME --before DIR --after DIR --post-rollback DIR --out FILE`, with optional `--prev FILE --baseline FILE --explain TEXT`. +- **S5.** Parts 3 and 4 of the sequence page recommend "a runner or a recorded-receipt check". That check now exists as a host-only checker (section 4 below). It does not make any blocked row pass. +- **S6.** The sequence page and runbook are written against `bbad5e4` and `9d41efc`; main is now `6bbd3c6`. No script they cite changed. The line numbers they cite inside `docs/TRUST-1-OPERATOR-STEPS.md` (Step 6 at 168 to 234, Step 8 at 244 to 296, Gate 2 run at 297 to 598) and in `scripts/trust1_m5_qualify.sh` (rows at 69 to 86) were re-checked on `6bbd3c6` and are right; the new gate row was added at the end of the table so those numbers do not move. + +## 2. The sittings, in order + +General rules (from the runbook): one step at a time; if anything differs from "expected", stop and give the output to the orchestrator; never improvise with security settings. Emergency stop for a stuck restart: plain power off, wait 30 seconds, one press of the power button, nothing else. + +### Sitting A. Gate 2 restarts with Secure Boot staying OFF (about 2 hours) + +- **What it is for.** Learn whether a warm restart's PCR1 value is stable, whether the firmware-update timer moves any measurement, and whether just visiting the firmware screen moves any. Sitting 3 also teaches us the real menu names Sitting C needs. +- **Where and how.** At the Spark, in a terminal, following `docs/TRUST-1-OPERATOR-STEPS.md` "Gate 2 attended run" (Before the first sitting, Sitting 1 with 4 boots, Sitting 2 with 3 boots, Sitting 3 with 3 boots). Per experiment, the receipt command is `bash scripts/tpm_measurement_campaign.sh receipt --variable NAME --before ~/trust1-evidence/ --after ~/trust1-evidence/ --post-rollback ~/trust1-evidence/ --baseline --out `. +- **Does it change anything?** No firmware setting, key or TPM. It restarts the machine and, in Sitting 2, turns one timer on then off. In Sitting 3, look and photograph only; leave with "exit without saving"; open no Secure Boot, key or TPM menu. +- **Success looks like.** The `compare` lines in the runbook (cold against cold shows `changed=0`); each receipt prints `result=RECORDED`. +- **Expected evidence.** Folders `~/trust1-evidence/g2-exp1-*`, `g2-exp2-*`, `g2-exp4-*`, the `compare` text, one receipt per experiment, and a note of the setup key and menu names. The orchestrator copies them into `evidence/trust1_gate2_experiments_/` in a pull request. Photos must have location data stripped before they go into a repository. +- **If a step fails.** PCR 7 moves, Ubuntu does not start, or storage or vault will not unlock: emergency stop above, then give the output to the orchestrator. A setting changed by mistake: restore it by hand and say so before the next boot. Timer: `sudo systemctl disable --now fwupd-refresh.timer`. +- **Can unlock.** Evidence toward `t1_gate2_reboot_campaign` (hardware) and `t1_gate0_firmware_refresh_pause` (operator). It does not finish either: the experiments are OFF-only and 3 and 5 have no written steps. Check a receipt with `gate2-receipt` (section 4). + +### Sitting B. Decide the key location, get three sticks, make the second offline copy + +- **Decision (the orchestrator will ask in the usual format).** Option A: key on a separate stick, so the recovery stick holds no secrets. Option B: key on the recovery stick (needs a rule change). Either way you need 3 spare sticks in total, one for the key and two for the Gate 3 backups kept in two different places. +- **Changes anything?** Only the new sticks, which are wiped first. Nothing on the Spark. +- **Success.** The identity's `sha256sum` at both places matches, written to `~/trust1-evidence/` as a note holding the fingerprint only, never the secret. Do not copy the identity until the orchestrator names the file. +- **If wrong.** Wipe the new stick. Nothing on the Spark changed. +- **Can unlock.** Evidence for `t1_gate0_second_offline_location` (operator). It stays BLOCKED until the note exists. + +### Sitting C. Turn Secure Boot ON, relock, repeat the cold-boot baseline + +- **Do not start unless all four are true:** Sitting A is done and the firmware setup key and the Secure Boot menu name are written down; the `AIENOSRECOV` stick is plugged in; the MacBook is on and its spares match `MANIFEST.txt`; and your written approval is recorded. Also back up the relock script (S3). +- **Why it is risky.** Turning Secure Boot on changes PCR 7, so the three stored passwords (private storage, forge storage, vault) can stop unlocking. On 2026-09-24 that happened when it was turned off. The fallback is the relock script, proven on 2026-10-01. +- **Steps.** Follow `docs/TRUST-1-ATTENDED-SEQUENCE.md` Action 3 steps 1 to 7: capture "before"; plug in the stick; `sudo systemctl reboot --firmware-setup`; set Secure Boot to enabled, save and exit, touching no key menus; log in; `mokutil --sb-state` must say `SecureBoot enabled`; if a credential refuses, retry once, then run `~/handoffs/secure-boot-off/after-restart.sh` (needs the MacBook online; it prints `MATCH` three times and `private storage: OPEN`); then three cold boots, each `sudo poweroff`, 30 seconds, power button, capture. +- **Changes anything?** Yes: the firmware Secure Boot setting and the TPM state of the three stored passwords. +- **Success.** `SecureBoot enabled`; PCR 7 differs from the OFF value and is identical across the three cold boots; all three credentials open. +- **If it fails.** `sudo systemctl reboot --firmware-setup` again and set Secure Boot back to disabled; boot Ubuntu; run the relock script (it re-locks to the OFF state and checks the digests). If Ubuntu will not start at all: power off, remove the stick, power on (Ubuntu is entry 0001); last resort is the recovery stick to read the disk. +- **Expected evidence.** `~/trust1-evidence/sb-on-before`, `sb-on-boot1`, `sb-on-boot2`, `sb-on-boot3`, the `compare` text, the relock output, the `mokutil` output. Check with `gate0-stability` (section 4). +- **Can unlock.** `t1_gate7_preflight` (the one software FAIL) is expected to turn PASS: re-run `bash scripts/trust1_gate7_preflight.sh`. Evidence for `t1_gate0_cold_boot_pcr_stability` (hardware). + +### Sitting D. Gate 1 recovery-stick boot with Secure Boot ON + +- **Needs:** Sitting C done and kept in the ON state; the stick and the key stick plugged in. +- **Steps.** `docs/TRUST-1-OPERATOR-STEPS.md` Step 6: read the stick's entry number from `efibootmgr`; `sudo efibootmgr --bootnext `; `sudo reboot`; at the recovery prompt mount the internal drive read-only; run `/usr/local/sbin/collect_recovery_boot_evidence /mnt/root` with the unlock settings and `AIENOS_UNLOCK_EXPECT="trust1-roundtrip-test.txt 32b2dc3155e92e071800370f9578e0ebf404df8513ca4b6213f015bacab498a1"`; save the output to a file on the key stick (for example with `| tee /mnt/key/gate1-output.txt`), unmount, remove the sticks, `reboot -f`, then `mokutil --sb-state`. +- **Changes anything?** One one-shot boot instruction that the firmware erases itself. Everything else is read-only. +- **Success.** Banner `AIENOS Standalone Hardware Recovery Core`; `PASS recovery_unlock_readonly`; `PASS test_artifact_round_trip`; `RECOVERY_BOOT_GATE: PASS`; Ubuntu starts again and says `SecureBoot enabled`. +- **If it fails.** Pick the stick's own entry (`UEFI: USB ...`) from the firmware boot menu, never a hand-made `AIENOS` entry (that bypassed the signed starter on 2026-09-24). If stuck: power off, remove the stick, power on. +- **Expected evidence.** The saved collector output, `efibootmgr` before and after, the final `mokutil` output. Check with `gate1`. +- **Can unlock.** Evidence for `t1_gate1_attended_recovery_boot` (operator). It needs Gate 0 closed first. + +### Sitting E. Gate 3 owner key ceremony (MacBook, network off) + +- **Needs:** the two backup sticks, a long passphrase written on paper, and your choice of machine. +- **Steps.** `docs/TRUST-1-OPERATOR-STEPS.md` Step 8: `preflight`, `generate`, `backup` twice (A and B), `record`. Only the `public` folder returns to the Spark. Write down the `manifest_sha256` printed by the tool on screen, on paper, so the checker has a value that did not come from the file itself. Then replace the placeholder `operator_signature=` line in `ceremony_record.txt` by hand with your own signature text. +- **Changes anything?** Creates a folder on the ceremony machine and files on the two sticks. Nothing is installed into the firmware. +- **Success.** Four `PASS ... matches manifest`, four `PASS ... decrypts from the backup copy` per backup, a `generated:` line, and a record with no private material. +- **If it fails.** Nothing in the firmware changed. Destroy or quarantine the folder and rerun. +- **Expected evidence.** The `public` folder committed under `evidence/`. Check with `gate3`. +- **Can unlock.** Evidence for `t1_gate3_offline_key_ceremony` (operator); it is also the first requirement of `m5_migration_owner_signature` (operator), which still needs a real owner signature. + +### Not yet possible (no written steps or no tool) + +Gate 2 experiments 3 and 5 and the Secure Boot ON experiment list; Gate 6 (needs the real-TPM sealing code); Gate 7 (needs its own checklist, an enrollment tool for the firmware's trusted-signer list, and an owner-signed loader); Gates 8 and 9. These are listed in Part 3 of the sequence page. No sitting above starts them. + +## 3. What each sitting can unlock + +"Row" means a line of `scripts/trust1_m5_qualify.sh`. No row below goes PASS by itself: the qualify script marks a row PASS only when it has a runner, and these rows have none by design (the sequence page, Part 4). The evidence checker output is a pre-check that the files are sound. The owner records the physical result separately. + +| Sitting | Row | State today | After the sitting | +|---|---|---|---| +| C | `t1_gate7_preflight` | FAIL (Secure Boot OFF) | Expected PASS once Secure Boot is ON; re-run the pre-flight | +| A | `t1_gate0_firmware_refresh_pause` | BLOCKED_OPERATOR | Still blocked: owes a written approval and a service baseline | +| A | `t1_gate2_reboot_campaign` | BLOCKED_HARDWARE | Still blocked: experiments 3 and 5 and the ON list are missing | +| B | `t1_gate0_second_offline_location` | BLOCKED_OPERATOR | Evidence once the matching hashes are recorded | +| C | `t1_gate0_cold_boot_pcr_stability` | BLOCKED_HARDWARE | Evidence (three ON cold boots). Only the OFF repeat exists today | +| D | `t1_gate1_attended_recovery_boot` | BLOCKED_OPERATOR | Evidence once the log is checked and recorded | +| E | `t1_gate3_offline_key_ceremony`, `m5_migration_owner_signature` | BLOCKED_OPERATOR | Evidence for the first; the second also needs a real signature | +| none | `t1_gate4_manifest_ab`, `t1_gate6`, `t1_gate7`, `t1_gate8`, `t1_gate9`, `m5_sealed_volume_keys_real_tpm`, `m5_store_kernel_binding`, `m5_owner_signed_chain_machine1`, `m5_production_store_512b` | blocked or missing | Cannot start from any sitting listed here | + +## 4. The evidence checker (HOST VALIDATION ONLY) + +`scripts/trust1_attended_evidence_check.sh` reads the files a sitting leaves behind and prints `TRUST1_ATTENDED_EVIDENCE : ACCEPT` or `REJECT` with the reasons. Every run starts with the line `HOST VALIDATION ONLY`. It checks files only, so a forged file could pass: ACCEPT means "well formed and matches the digests you named", never "the boot happened". It does not touch the TPM, firmware, sticks or keys, and it is not wired to change any row in the qualify script. Its own test is `bash scripts/test_trust1_attended_evidence_check.sh` and the qualify script runs it as the row `t1_attended_evidence_checker`. + +It rejects, for every command: a missing record, a record with the wrong digest or candidate, a partial record, and a failing record. + +| Sitting | Command | +|---|---| +| A | `bash scripts/trust1_attended_evidence_check.sh gate2-receipt RECEIPT.json --expect-baseline-sha --expect-variable NAME --before DIR --after DIR --post-rollback DIR` | +| C | `bash scripts/trust1_attended_evidence_check.sh gate0-stability ~/trust1-evidence/sb-on-boot1 .../sb-on-boot2 .../sb-on-boot3 --expect-secure-boot 1` (give cold boots only; add `--expect-pcr7 HEX` once you know the value to expect) | +| D | `bash scripts/trust1_attended_evidence_check.sh gate1 gate1-output.txt --expect-test-sha 32b2dc3155e92e071800370f9578e0ebf404df8513ca4b6213f015bacab498a1 [--expect-loader-sha SHA]` | +| E | `bash scripts/trust1_attended_evidence_check.sh gate3 public --expect-manifest-sha ` | + +Limits stated plainly: it cannot tell a cold boot from a warm one; for Gate 1 the collector log carries no commit id, so candidate binding rests on the test-file digest and, if given, the loader digest; the second-location note for Sitting B has no checker because no record format exists for it yet. diff --git a/docs/TRUST-1-ATTENDED-SEQUENCE.md b/docs/TRUST-1-ATTENDED-SEQUENCE.md index 1f7657c2..07b788ec 100644 --- a/docs/TRUST-1-ATTENDED-SEQUENCE.md +++ b/docs/TRUST-1-ATTENDED-SEQUENCE.md @@ -21,7 +21,7 @@ Status: documentation only. Machine-independent companion to [TRUST-1-M5-GATE-MATRIX.md](TRUST-1-M5-GATE-MATRIX.md). Written 2026-10-05 against aienos main bbad5e4 (CAND-1 TRUST receipt: pass 20, fail 1, blocked 11, missing 5, NOT_QUALIFIED). It records no live machine state; the live preflight results and the request to the operator live in the -operator's private handoff, not here. Nothing in this page was run on Machine 1. +operator's private handoff, not here. Nothing in this page was run on Machine 1. The single in-person document, with live-checked prerequisites and corrections to this page, is [TRUST-1-ATTENDED-PACKAGE.md](TRUST-1-ATTENDED-PACKAGE.md). Secure Boot has been OFF since 2026-10-01. The one software FAIL, `t1_gate7_preflight`, reports that state and is not a code regression. diff --git a/scripts/.crumb b/scripts/.crumb index ba7c2930..53e13d0b 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-05T03:53:55Z", + "compiled_at": "2026-10-05T19:26:03Z", "compiler": "crumb-compile/1", - "digest": "sha256:b5c64f0277790e020d9c0fde19cc064fafc5c64e1d37d4e92ed88f5a40e36da3", + "digest": "sha256:987eb5d8a450f5aaf1f821e428d30c06538cc5135d943892339157f9359e6938", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 63, - "generated_at_commit": "9d41efc9d1bea31be0640ca70eeeec9d1d000fad", - "source_tree": "sha256:41d218b96b3ce89b24b934fa7f023dc268c71d1b113e1a18e2b64a1e58b2e094" + "files": 65, + "generated_at_commit": "32256ba94a0bbabbe8f7ba201e7126b57fe4e4ea", + "source_tree": "sha256:61a25c98d59872bd3962dbae7bf7874793edc56d56063e3b316986654ef52f39" }, "owner_lane": "", "provenance": { diff --git a/scripts/test_trust1_attended_evidence_check.sh b/scripts/test_trust1_attended_evidence_check.sh new file mode 100755 index 00000000..2ab9c378 --- /dev/null +++ b/scripts/test_trust1_attended_evidence_check.sh @@ -0,0 +1,212 @@ +#!/usr/bin/env bash +# test_trust1_attended_evidence_check.sh: HOST VALIDATION ONLY fixture tests +# for scripts/trust1_attended_evidence_check.sh. Every fixture is synthetic or +# made with throwaway keys in a temp folder; nothing touches Machine 1, a TPM, +# firmware, boot media or a real key. +# +# For every gate the checker must ACCEPT one good record and REJECT each of: +# missing, mismatched (wrong digest or candidate), partial and failing records. +# Negative control: the whole suite is first run against a stub checker that +# accepts everything; that run must be RED (catch nothing). Then the real +# checker must be GREEN. Marker on success: +# TRUST1_ATTENDED_EVIDENCE_CHECK self-test (HOST VALIDATION ONLY): ALL PASS +# Env: AIENOS_QUIET_FLAG is not used; no chip or QEMU is started. +set -uo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +real="${repo_root}/scripts/trust1_attended_evidence_check.sh" +campaign="${repo_root}/scripts/tpm_measurement_campaign.sh" +ceremony="${repo_root}/scripts/trust1_key_ceremony.sh" +for t in jq sha256sum openssl; do command -v "${t}" >/dev/null || { echo "Error: ${t} not installed" >&2; exit 2; }; done + +work="$(mktemp -d)" +trap 'rm -rf --one-file-system "${work}"' EXIT +chmod 700 "${work}" +echo "HOST VALIDATION ONLY: fixture tests, no hardware, throwaway keys" + +# ------------------------------------------------------------------ fixtures +hex() { printf '%064x' "$1"; } +make_capture() { # dir label boot_id secure_boot pcr7_seed [pcr1_seed] + local d="$1" i + mkdir -p "${d}/efivars" + for i in 0 1 2 3 4 5 6 7 10; do + local seed="${i}" + [[ "${i}" == 7 ]] && seed="${5}" + [[ "${i}" == 1 && -n "${6:-}" ]] && seed="${6}" + echo "${i} 0x$(hex "$((seed + 100))")" + done >"${d}/pcr_sha256.norm" + echo "fake pcrs" >"${d}/pcr_sha256.txt" + echo "fake efivar" >"${d}/efivars/PK.efivar" + { + echo "capture_label=$2"; echo "capture_utc=2026-10-05T00:00:00Z"; echo "host=fixture" + echo "boot_id=$3"; echo "firmware_version=5.36_0ACUM018" + echo "secure_boot=$4"; echo "setup_mode=0" + echo "PK_efivar_sha256=$(hex 1)"; echo "KEK_efivar_sha256=$(hex 2)" + echo "db_efivar_sha256=$(hex 3)"; echo "dbx_efivar_sha256=$(hex 4)" + echo "eventlog_replay=match" + } >"${d}/capture.env" + (cd "${d}" && find . -type f ! -name SHA256SUMS -print0 | sort -z | xargs -0 sha256sum >SHA256SUMS) +} +resum() { (cd "$1" && find . -type f ! -name SHA256SUMS -print0 | sort -z | xargs -0 sha256sum >SHA256SUMS); } + +TEST_SHA="$(hex 4242)" +LOADER_SHA="$(hex 7777)" +make_log() { # out + cat >"$1" <&1)"; rc=$? + if [[ "${want}" == accept ]]; then + if [[ "${rc}" -eq 0 && "${out}" == *"ACCEPT"* ]]; then echo "ok accept: ${name}"; return; fi + else + if [[ "${rc}" -eq 1 && "${out}" == *"REJECT"* && "${out}" == *"${needle}"* ]]; then echo "ok reject: ${name}"; return; fi + fi + echo "MISS ${want} expected: ${name} (exit ${rc}; needle '${needle}')" + FAILS=$((FAILS + 1)) +} + +run_suite() { + FAILS=0 + local w="${work}/s$RANDOM"; mkdir -p "${w}" + # ---- gate 1 + make_log "${w}/g1.log" + expect accept "gate1 good log" "" -- gate1 "${w}/g1.log" --expect-test-sha "${TEST_SHA}" --expect-loader-sha "${LOADER_SHA}" + expect reject "gate1 missing log" "missing or empty" -- gate1 "${w}/nope.log" --expect-test-sha "${TEST_SHA}" + : >"${w}/empty.log" + expect reject "gate1 empty log" "missing or empty" -- gate1 "${w}/empty.log" --expect-test-sha "${TEST_SHA}" + expect reject "gate1 wrong test digest" "digest mismatch" -- gate1 "${w}/g1.log" --expect-test-sha "$(hex 9)" + expect reject "gate1 wrong candidate loader" "wrong candidate loader" -- gate1 "${w}/g1.log" --expect-test-sha "${TEST_SHA}" --expect-loader-sha "$(hex 8)" + sed '/^RECOVERY_BOOT_GATE/d;/^== verdict/d' "${w}/g1.log" >"${w}/g1-cut.log" + expect reject "gate1 cut-off log (no verdict)" "cut-off log" -- gate1 "${w}/g1-cut.log" --expect-test-sha "${TEST_SHA}" + sed 's/^PASS test_artifact_round_trip:.*/FAIL test_artifact_round_trip: expected x/;s/^RECOVERY_BOOT_GATE: PASS/RECOVERY_BOOT_GATE: FAIL/' "${w}/g1.log" >"${w}/g1-fail.log" + expect reject "gate1 failing record" "failing checks" -- gate1 "${w}/g1-fail.log" --expect-test-sha "${TEST_SHA}" + { cat "${w}/g1.log"; echo "RECOVERY_BOOT_GATE: FAIL"; } >"${w}/g1-both.log" + expect reject "gate1 log with both PASS and FAIL verdicts" "contains RECOVERY_BOOT_GATE: FAIL" -- gate1 "${w}/g1-both.log" --expect-test-sha "${TEST_SHA}" + sed '/recovery_unlock_readonly/d;/test_artifact/d;/^PASS test_artifact/d' "${w}/g1.log" >"${w}/g1-part.log" + echo 'recovery_unlock: not authorized for this run (set AIENOS_UNLOCK_CIPHER, AIENOS_UNLOCK_SPARE, AIENOS_UNLOCK_IDENTITY)' >>"${w}/g1-part.log" + expect reject "gate1 partial (unlock not run)" "partial record" -- gate1 "${w}/g1-part.log" --expect-test-sha "${TEST_SHA}" + sed 's/^secure_boot_byte: 1/secure_boot_byte: 0/' "${w}/g1.log" >"${w}/g1-sb0.log" + expect reject "gate1 Secure Boot OFF" "Secure Boot was not recorded ON" -- gate1 "${w}/g1-sb0.log" --expect-test-sha "${TEST_SHA}" + + # ---- gate 0 stability + make_capture "${w}/c1" b1 id-1 1 7; make_capture "${w}/c2" b2 id-2 1 7; make_capture "${w}/c3" b3 id-3 1 7 + expect accept "gate0 three identical cold captures" "" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/c3" --expect-pcr7 "$(hex 107)" + expect reject "gate0 only two captures" "needs at least 3" -- gate0-stability "${w}/c1" "${w}/c2" + expect reject "gate0 missing folder" "partial capture" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/none" + make_capture "${w}/d3" b3 id-3 1 8 + expect reject "gate0 PCR7 moved" "PCR7 changed" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/d3" + expect reject "gate0 wrong expected PCR7 (wrong candidate)" "wrong candidate state" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/c3" --expect-pcr7 "$(hex 999)" + make_capture "${w}/e3" b3 id-3 1 7 50 + expect reject "gate0 PCR1 moved (warm-style)" "PCR1 changed" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/e3" + cp -r "${w}/c3" "${w}/t3"; echo "0 0x$(hex 1)" >>"${w}/t3/pcr_sha256.norm" + expect reject "gate0 tampered capture" "SHA256SUMS" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/t3" + cp -r "${w}/c3" "${w}/p3"; rm "${w}/p3/capture.env" + expect reject "gate0 partial capture (no capture.env)" "partial capture" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/p3" + make_capture "${w}/s3" b3 id-3 0 7 + expect reject "gate0 Secure Boot OFF capture" "secure_boot=0" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/s3" + make_capture "${w}/s1" b1 id-1 0 7; make_capture "${w}/s2" b2 id-2 0 7 + expect accept "gate0 OFF captures with --expect-secure-boot 0" "" -- gate0-stability "${w}/s1" "${w}/s2" "${w}/s3" --expect-secure-boot 0 + make_capture "${w}/r3" b3 id-1 1 7 + expect reject "gate0 same boot counted twice" "repeats an earlier folder" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/r3" + cp -r "${w}/c3" "${w}/m3"; sed -i 's/^eventlog_replay=match/eventlog_replay=mismatch/' "${w}/m3/capture.env"; resum "${w}/m3" + expect reject "gate0 event log replay mismatch" "not 'match'" -- gate0-stability "${w}/c1" "${w}/c2" "${w}/m3" + + # ---- gate 2 receipt (written by the real campaign tool from fixtures) + make_capture "${w}/before" before id-b 1 7; make_capture "${w}/after" after id-a 1 8; make_capture "${w}/post" post id-p 1 7 + : >"${w}/baseline.json"; echo '{"baseline":1}' >"${w}/baseline.json" + bash "${campaign}" receipt --variable timer --before "${w}/before" --after "${w}/after" --post-rollback "${w}/post" \ + --baseline "${w}/baseline.json" --out "${w}/r.json" >/dev/null 2>&1 || { echo "MISS could not build gate2 fixture receipt"; FAILS=$((FAILS + 1)); } + local bs; bs="$(sha256sum "${w}/baseline.json" | cut -d' ' -f1)" + expect accept "gate2 good receipt with folders" "" -- gate2-receipt "${w}/r.json" --expect-baseline-sha "${bs}" --expect-variable timer \ + --before "${w}/before" --after "${w}/after" --post-rollback "${w}/post" + expect reject "gate2 good receipt without capture folders" "capture folder not given" -- gate2-receipt "${w}/r.json" --expect-baseline-sha "${bs}" --expect-variable timer + expect reject "gate2 good receipt missing post-rollback folder" "post_rollback: capture folder not given" -- gate2-receipt "${w}/r.json" --expect-baseline-sha "${bs}" --expect-variable timer --before "${w}/before" --after "${w}/after" + expect reject "gate2 missing receipt" "missing or empty" -- gate2-receipt "${w}/none.json" + echo '{ not json' >"${w}/bad.json" + expect reject "gate2 garbage receipt" "not valid JSON" -- gate2-receipt "${w}/bad.json" + jq 'del(.rollback_restored)' "${w}/r.json" >"${w}/r-part.json" + expect reject "gate2 partial receipt (field removed)" "lacks field 'rollback_restored'" -- gate2-receipt "${w}/r-part.json" + jq '.result="STOP_UNEXPECTED_STATE" | .rollback_restored=false' "${w}/r.json" >"${w}/r-fail.json" + expect reject "gate2 failing receipt" "not RECORDED" -- gate2-receipt "${w}/r-fail.json" + expect reject "gate2 wrong baseline digest" "wrong chain" -- gate2-receipt "${w}/r.json" --expect-baseline-sha "$(hex 5)" + expect reject "gate2 wrong variable" "expected 'boot_order'" -- gate2-receipt "${w}/r.json" --expect-variable boot_order + expect reject "gate2 folder does not match receipt digest" "does not match folder digest" -- gate2-receipt "${w}/r.json" --before "${w}/after" + jq '.receipt_type="other"' "${w}/r.json" >"${w}/r-type.json" + expect reject "gate2 wrong receipt type" "receipt_type" -- gate2-receipt "${w}/r-type.json" + + # ---- gate 3 (real ceremony tool, throwaway keys) + local c="${w}/cer" + printf 'throwaway-test-passphrase\n' >"${w}/pass" + export AIENOS_CEREMONY_PASS_FILE="${w}/pass" + mkdir -p "${w}/mA" "${w}/mB" + if bash "${ceremony}" generate "${c}" --allow-online >/dev/null 2>&1 \ + && bash "${ceremony}" backup "${c}" "${w}/mA" backup-A >/dev/null 2>&1 \ + && bash "${ceremony}" backup "${c}" "${w}/mB" backup-B >/dev/null 2>&1 \ + && bash "${ceremony}" record "${c}" >/dev/null 2>&1; then + local pub="${c}/public" ms + ms="$(sha256sum "${pub}/authority_manifest.txt" | cut -d' ' -f1)" + # a record the operator has not signed yet is a partial record + expect reject "gate3 unsigned record (placeholder)" "placeholder" -- gate3 "${pub}" --expect-manifest-sha "${ms}" + cp -r "${pub}" "${w}/signed" + sed -i 's/^operator_signature=.*/operator_signature=fixture-operator-signature/' "${w}/signed/ceremony_record.txt" + expect accept "gate3 good signed record" "" -- gate3 "${w}/signed" --expect-manifest-sha "${ms}" + expect reject "gate3 wrong manifest digest (wrong candidate)" "wrong candidate" -- gate3 "${w}/signed" --expect-manifest-sha "$(hex 3)" + expect reject "gate3 missing folder" "missing" -- gate3 "${w}/nope" --expect-manifest-sha "${ms}" + cp -r "${w}/signed" "${w}/g3a"; sed -i 's/^backup_count=2/backup_count=1/;0,/^backup label=/{//d}' "${w}/g3a/ceremony_record.txt" + expect reject "gate3 only one backup" "below 2" -- gate3 "${w}/g3a" --expect-manifest-sha "${ms}" + cp -r "${w}/signed" "${w}/g3b"; sed -i '/^role\.release_signer\.pub_sha256=/d' "${w}/g3b/ceremony_record.txt" + expect reject "gate3 partial record (role fingerprint missing)" "role release_signer" -- gate3 "${w}/g3b" --expect-manifest-sha "${ms}" + cp -r "${w}/signed" "${w}/g3c"; sed -i 's/^generation=1$/generation=2/' "${w}/g3c/authority_manifest.txt" + expect reject "gate3 manifest altered after record" "does not match the manifest file" -- gate3 "${w}/g3c" --expect-manifest-sha "${ms}" + cp -r "${w}/signed" "${w}/g3d"; echo "-----BEGIN PRIVATE KEY-----" >>"${w}/g3d/ceremony_record.txt" + expect reject "gate3 private material in record" "private key material" -- gate3 "${w}/g3d" --expect-manifest-sha "${ms}" + cp -r "${w}/signed" "${w}/g3e"; sed -i 's/^firmware_changed=no/firmware_changed=yes/' "${w}/g3e/ceremony_record.txt" + expect reject "gate3 firmware changed" "firmware_changed=no" -- gate3 "${w}/g3e" --expect-manifest-sha "${ms}" + cp -r "${w}/signed" "${w}/g3f"; cp "${w}/g3c/authority_manifest.txt" "${w}/g3f/authority_manifest.txt" + sed -i "s/^manifest_sha256=.*/manifest_sha256=$(sha256sum "${w}/g3f/authority_manifest.txt" | cut -d' ' -f1)/" "${w}/g3f/ceremony_record.txt" + expect reject "gate3 re-pointed record, manifest signature fails" "verify failed" -- gate3 "${w}/g3f" --expect-manifest-sha "$(sha256sum "${w}/g3f/authority_manifest.txt" | cut -d' ' -f1)" + else + echo "MISS could not build gate3 throwaway ceremony"; FAILS=$((FAILS + 1)) + fi + unset AIENOS_CEREMONY_PASS_FILE + # ---- usage + local rc; bash "${CHECKER}" bogus >/dev/null 2>&1; rc=$? + if [[ "${rc}" -eq 2 ]]; then echo "ok usage: unknown subcommand exits 2"; else echo "MISS usage exit ${rc}"; FAILS=$((FAILS + 1)); fi + return 0 +} + +# Negative control: a stub that accepts everything must be caught. +stub="${work}/accept-all.sh" +printf '#!/usr/bin/env bash\necho "TRUST1_ATTENDED_EVIDENCE stub: ACCEPT"\nexit 0\n' >"${stub}" +echo "== RED run: stub checker that accepts everything" +CHECKER="${stub}"; run_suite >"${work}/red.log"; red_fails="${FAILS}" +grep -c '^MISS' "${work}/red.log" | sed 's/^/stub misses caught by the suite: /' +if [[ "${red_fails}" -lt 10 ]]; then echo "FAIL the suite did not go red against an accept-all stub (${red_fails} misses)"; exit 1; fi +echo "== GREEN run: real checker" +CHECKER="${real}"; run_suite >"${work}/green.log"; grep -v "^ok" "${work}/green.log" +if [[ "${FAILS}" -ne 0 ]]; then echo "TRUST1_ATTENDED_EVIDENCE_CHECK self-test (HOST VALIDATION ONLY): FAIL (${FAILS})"; exit 1; fi +echo "checks passed: $(grep -c '^ok' "${work}/green.log")" +echo "TRUST1_ATTENDED_EVIDENCE_CHECK self-test (HOST VALIDATION ONLY): ALL PASS" diff --git a/scripts/trust1_attended_evidence_check.sh b/scripts/trust1_attended_evidence_check.sh new file mode 100755 index 00000000..e31de498 --- /dev/null +++ b/scripts/trust1_attended_evidence_check.sh @@ -0,0 +1,282 @@ +#!/usr/bin/env bash +# trust1_attended_evidence_check.sh: HOST VALIDATION ONLY. +# +# Reads evidence that an attended TRUST-1 sitting left behind and says whether +# the evidence is well formed and bound to what the operator expects. It +# REJECTS missing, mismatched (wrong digest or candidate), partial and failing +# records. It does not and cannot prove the physical event happened: a file +# can be forged. ACCEPT means "this record is internally consistent and +# matches the digests you named", never "the boot or ceremony was done". +# Gate rows in scripts/trust1_m5_qualify.sh stay NOT_RUN (BLOCKED_OPERATOR / +# BLOCKED_HARDWARE) until the physical event is recorded by the operator; this +# tool is not wired into those rows. +# +# Read-only: no sudo, no TPM, no efivar or disk writes. Works on files only. +# +# Subcommands (each prints REJECT lines with the reason, then one verdict): +# gate1 COLLECTOR_LOG --expect-test-sha SHA [--expect-loader-sha SHA] +# Gate 1 attended recovery-stick boot: output of +# scripts/collect_recovery_boot_evidence.sh. Needs Secure Boot ON. +# gate0-stability DIR1 DIR2 DIR3 [DIR...] [--expect-secure-boot 0|1 (default 1)] +# [--expect-pcr7 HEX] [--expect-firmware VERSION] +# Gate 0 cold-boot PCR stability: three or more capture folders made by +# scripts/tpm_measurement_campaign.sh capture. The operator must give +# cold boots only (a warm restart legitimately moves PCR1); this tool +# cannot tell the difference. +# gate2-receipt RECEIPT.json --before DIR --after DIR --post-rollback DIR +# [--expect-baseline-sha SHA] [--expect-variable NAME] +# Gate 2 per-experiment receipt written by tpm_measurement_campaign.sh +# receipt. The three capture folders are required; their digests must match +# the receipt (a missing folder is a partial record and is rejected). +# gate3 PUBLIC_DIR --expect-manifest-sha SHA +# Gate 3 key ceremony public folder (ceremony_record.txt, manifest). +# Runs scripts/trust1_key_ceremony.sh verify when openssl is usable. +# +# Output: "HOST VALIDATION ONLY" banner, REJECT/NOTE lines, and +# TRUST1_ATTENDED_EVIDENCE : ACCEPT | REJECT (n reasons) +# Exit: 0 ACCEPT, 1 REJECT, 2 usage error. +set -uo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +REASONS=0 +GATE="?" + +banner() { echo "HOST VALIDATION ONLY: checks recorded files, does not prove the physical event happened"; } +usage() { sed -n '/^# Subcommands/,/^# Exit/p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//' >&2; exit 2; } +rej() { echo "REJECT $*"; REASONS=$((REASONS + 1)); } +note() { echo "NOTE $*"; } +is_sha() { [[ "$1" =~ ^[0-9a-f]{64}$ ]]; } +verdict() { + if [[ "${REASONS}" -eq 0 ]]; then + echo "TRUST1_ATTENDED_EVIDENCE ${GATE}: ACCEPT (host validation only)" + exit 0 + fi + echo "TRUST1_ATTENDED_EVIDENCE ${GATE}: REJECT (${REASONS} reason(s))" + exit 1 +} +need_sha_arg() { # name value + [[ -n "$2" ]] || { echo "usage: $1 is required" >&2; exit 2; } + is_sha "$2" || { echo "usage: $1 must be 64 lowercase hex characters" >&2; exit 2; } +} + +# ------------------------------------------------------------------ gate 1 +cmd_gate1() { + GATE="gate1" + local log="${1:-}" test_sha="" loader_sha="" + [[ -n "${log}" ]] || usage + shift + while [[ $# -gt 0 ]]; do + case "$1" in + --expect-test-sha) test_sha="${2:-}"; shift 2 ;; + --expect-loader-sha) loader_sha="${2:-}"; shift 2 ;; + *) echo "usage: unknown option $1" >&2; exit 2 ;; + esac + done + need_sha_arg --expect-test-sha "${test_sha}" + [[ -z "${loader_sha}" ]] || need_sha_arg --expect-loader-sha "${loader_sha}" + banner + if [[ ! -s "${log}" ]]; then rej "collector log missing or empty: ${log}"; verdict; fi + + local pass_n fail_n + pass_n="$(grep -c '^RECOVERY_BOOT_GATE: PASS$' "${log}")" + fail_n="$(grep -c '^RECOVERY_BOOT_GATE: FAIL$' "${log}")" + [[ "${fail_n}" -eq 0 ]] || rej "log contains RECOVERY_BOOT_GATE: FAIL" + [[ "${pass_n}" -eq 1 ]] || rej "log has ${pass_n} 'RECOVERY_BOOT_GATE: PASS' lines (need exactly 1; a cut-off log has none)" + if grep -q '^FAIL ' "${log}"; then rej "log contains failing checks: $(grep '^FAIL ' "${log}" | head -n 3 | tr '\n' ';')"; fi + local c + for c in booted_from_removable_media secure_boot_state_recorded nvme_root_mounted pcrs_read \ + event_log_recorded esp_loaders_hashed recovery_unlock_readonly test_artifact_round_trip; do + grep -q "^PASS ${c}:" "${log}" || rej "required check '${c}' has no PASS line (missing or partial record)" + done + if grep -q '^recovery_unlock: not authorized' "${log}"; then rej "recovery unlock was not run (partial record)"; fi + grep -qx 'secure_boot_byte: 1' "${log}" || rej "Secure Boot was not recorded ON (need 'secure_boot_byte: 1'; Gate 1 requires Secure Boot ON)" + local got + got="$(sed -n 's/^test_artifact: .* sha256=\([0-9a-f]\{64\}\)$/\1/p' "${log}" | head -n 1)" + if [[ -z "${got}" ]]; then + rej "no 'test_artifact: ... sha256=' line (test file not read back)" + elif [[ "${got}" != "${test_sha}" ]]; then + rej "test file digest mismatch: log ${got}, expected ${test_sha}" + fi + if [[ -n "${loader_sha}" ]] && ! grep -q "^efi_image: .* sha256=${loader_sha}\$" "${log}"; then + rej "no efi_image line with expected loader digest ${loader_sha} (wrong candidate loader)" + fi + verdict +} + +# -------------------------------------------------------- gate 0 stability +env_get() { sed -n "s/^$2=//p" "$1/capture.env" | head -n 1; } +pcr_get() { awk -v n="$2" '$1 == n { print $2 }' "$1/pcr_sha256.norm"; } + +# Prints the reason to stdout; returns 0 if the capture folder is intact. +capture_intact() { + local d="$1" f listed present + for f in capture.env pcr_sha256.norm SHA256SUMS; do + [[ -f "${d}/${f}" ]] || { echo "${d}: missing ${f} (partial capture)"; return 1; } + done + if ! (cd "${d}" && sha256sum --quiet -c SHA256SUMS >/dev/null 2>&1); then + echo "${d}: files do not match its SHA256SUMS (tampered or damaged)"; return 1 + fi + listed="$(sed 's/^[0-9a-f]* //' "${d}/SHA256SUMS" | sort)" + present="$(cd "${d}" && find . -type f ! -name SHA256SUMS | sort)" + [[ "${listed}" == "${present}" ]] || { echo "${d}: files added or removed since capture"; return 1; } + [[ "$(wc -l <"${d}/pcr_sha256.norm")" -ge 8 ]] || { echo "${d}: fewer than 8 SHA-256 PCRs (partial capture)"; return 1; } + return 0 +} + +cmd_gate0_stability() { + GATE="gate0-stability" + local dirs=() sb=1 want7="" want_fw="" + while [[ $# -gt 0 ]]; do + case "$1" in + --expect-secure-boot) sb="${2:-}"; shift 2 ;; + --expect-pcr7) want7="${2:-}"; shift 2 ;; + --expect-firmware) want_fw="${2:-}"; shift 2 ;; + --*) echo "usage: unknown option $1" >&2; exit 2 ;; + *) dirs+=("$1"); shift ;; + esac + done + [[ "${sb}" == 0 || "${sb}" == 1 ]] || { echo "usage: --expect-secure-boot is 0 or 1" >&2; exit 2; } + [[ ${#dirs[@]} -ge 1 ]] || usage + banner + [[ ${#dirs[@]} -ge 3 ]] || rej "${#dirs[@]} capture folder(s) given; stability needs at least 3 boots" + local d msg bid ok=() ids="" + for d in "${dirs[@]}"; do + if msg="$(capture_intact "${d}")"; then + ok+=("${d}") + else + rej "${msg}"; continue + fi + [[ "$(env_get "${d}" eventlog_replay)" == "match" ]] || rej "${d}: event log replay is '$(env_get "${d}" eventlog_replay)', not 'match'" + [[ "$(env_get "${d}" secure_boot)" == "${sb}" ]] || rej "${d}: secure_boot=$(env_get "${d}" secure_boot), expected ${sb}" + [[ "$(env_get "${d}" setup_mode)" == "0" ]] || rej "${d}: setup_mode=$(env_get "${d}" setup_mode), expected 0" + bid="$(env_get "${d}" boot_id)" + if [[ -z "${bid}" || "${bid}" == unknown ]]; then rej "${d}: no usable boot_id" + elif grep -qx "${bid}" <<<"${ids}"; then rej "${d}: boot_id ${bid} repeats an earlier folder (same boot counted twice)" + else ids+="${bid}"$'\n'; fi + [[ -z "${want_fw}" || "$(env_get "${d}" firmware_version)" == "${want_fw}" ]] \ + || rej "${d}: firmware_version=$(env_get "${d}" firmware_version), expected ${want_fw}" + [[ -z "${want7}" || "$(pcr_get "${d}" 7)" == "0x${want7#0x}" ]] \ + || rej "${d}: PCR7 $(pcr_get "${d}" 7) differs from expected ${want7} (wrong candidate state)" + done + # Compare every intact folder with the first intact one. + if [[ ${#ok[@]} -ge 2 ]]; then + local ref="${ok[0]}" k va vb + for d in "${ok[@]:1}"; do + for k in 0 1 2 3 4 5 6 7; do + va="$(pcr_get "${ref}" "${k}")"; vb="$(pcr_get "${d}" "${k}")" + [[ "${va}" == "${vb}" ]] || rej "PCR${k} changed between ${ref} and ${d} (not stable; variation must be explained, not accepted)" + done + for k in PK_efivar_sha256 KEK_efivar_sha256 db_efivar_sha256 dbx_efivar_sha256 firmware_version; do + [[ "$(env_get "${ref}" "${k}")" == "$(env_get "${d}" "${k}")" ]] || rej "${k} changed between ${ref} and ${d}" + [[ "$(env_get "${d}" "${k}")" != "unreadable" ]] || rej "${d}: ${k} unreadable (partial capture)" + done + done + fi + note "cannot tell cold from warm restarts; the operator must supply cold boots only" + verdict +} + +# ------------------------------------------------------------- gate 2 receipt +cmd_gate2_receipt() { + GATE="gate2-receipt" + local rc="${1:-}" base="" var="" before="" after="" post="" + [[ -n "${rc}" ]] || usage + shift + while [[ $# -gt 0 ]]; do + case "$1" in + --expect-baseline-sha) base="${2:-}"; shift 2 ;; + --expect-variable) var="${2:-}"; shift 2 ;; + --before) before="${2:-}"; shift 2 ;; + --after) after="${2:-}"; shift 2 ;; + --post-rollback) post="${2:-}"; shift 2 ;; + *) echo "usage: unknown option $1" >&2; exit 2 ;; + esac + done + [[ -z "${base}" ]] || need_sha_arg --expect-baseline-sha "${base}" + command -v jq >/dev/null || { echo "usage: jq is required" >&2; exit 2; } + banner + if [[ ! -s "${rc}" ]]; then rej "receipt missing or empty: ${rc}"; verdict; fi + if ! jq -e . "${rc}" >/dev/null 2>&1; then rej "receipt is not valid JSON"; verdict; fi + local f + for f in receipt_type variable before after post_rollback changed_by_mutation not_restored_after_rollback \ + rollback_restored previous_receipt_sha256 baseline_receipt_sha256 result; do + jq -e "has(\"${f}\")" "${rc}" >/dev/null 2>&1 || rej "receipt lacks field '${f}' (partial record)" + done + [[ "$(jq -r '.receipt_type // ""' "${rc}")" == "trust1_gate2_measurement" ]] || rej "receipt_type is not trust1_gate2_measurement" + [[ "$(jq -r '.result // ""' "${rc}")" == "RECORDED" ]] || rej "result is '$(jq -r '.result // "absent"' "${rc}")', not RECORDED (failing record)" + [[ "$(jq -r '.rollback_restored // ""' "${rc}")" == "true" ]] || rej "rollback_restored is not true" + [[ "$(jq -r '(.not_restored_after_rollback // ["x"]) | length' "${rc}")" == "0" ]] || rej "items not restored after rollback" + [[ -z "${var}" || "$(jq -r '.variable // ""' "${rc}")" == "${var}" ]] || rej "variable is '$(jq -r '.variable // ""' "${rc}")', expected '${var}'" + local rb + rb="$(jq -r '.baseline_receipt_sha256 // ""' "${rc}")" + if [[ -n "${base}" && "${rb}" != "${base}" ]]; then rej "baseline_receipt_sha256 '${rb}' does not match expected ${base} (wrong chain)"; fi + local pair key dir want got msg + for pair in "before:${before}" "after:${after}" "post_rollback:${post}"; do + key="${pair%%:*}"; dir="${pair#*:}" + if [[ -z "${dir}" ]]; then rej "${key}: capture folder not given (--${key/_/-}); its digest cannot be checked (partial evidence)"; continue; fi + if [[ ! -f "${dir}/SHA256SUMS" ]]; then rej "${key}: folder ${dir} has no SHA256SUMS"; continue; fi + want="$(jq -r ".${key}.capture_digest // \"\"" "${rc}")" + got="$(sha256sum "${dir}/SHA256SUMS" | cut -d' ' -f1)" + [[ "${want}" == "${got}" ]] || rej "${key}: receipt digest '${want:-absent}' does not match folder digest ${got}" + if ! msg="$(capture_intact "${dir}")"; then rej "${msg}"; fi + done + verdict +} + +# ------------------------------------------------------------------ gate 3 +cmd_gate3() { + GATE="gate3" + local pub="${1:-}" want="" + [[ -n "${pub}" ]] || usage + shift + while [[ $# -gt 0 ]]; do + case "$1" in + --expect-manifest-sha) want="${2:-}"; shift 2 ;; + *) echo "usage: unknown option $1" >&2; exit 2 ;; + esac + done + need_sha_arg --expect-manifest-sha "${want}" + banner + local rec="${pub}/ceremony_record.txt" man="${pub}/authority_manifest.txt" + if [[ ! -f "${rec}" ]]; then rej "ceremony_record.txt missing in ${pub}"; verdict; fi + if [[ ! -f "${man}" ]]; then rej "authority_manifest.txt missing in ${pub}"; verdict; fi + grep -qx 'aienos_key_ceremony_record=1' "${rec}" || rej "record header 'aienos_key_ceremony_record=1' missing" + local rv actual r ra ma n sig out + rv="$(sed -n 's/^manifest_sha256=//p' "${rec}" | head -n 1)" + actual="$(sha256sum "${man}" | cut -d' ' -f1)" + [[ "${rv}" == "${actual}" ]] || rej "record manifest_sha256 '${rv:-absent}' does not match the manifest file ${actual} (altered after the record)" + [[ "${actual}" == "${want}" ]] || rej "manifest digest ${actual} does not match expected ${want} (wrong candidate)" + if grep -q 'PRIVATE KEY' "${rec}" "${man}"; then rej "private key material found in the public record"; fi + for r in owner_root boot_signer release_signer operator_approval; do + ra="$(sed -n "s/^role\\.${r}\\.pub_sha256=//p" "${rec}" | head -n 1)" + ma="$(sed -n "s/^role\\.${r}\\.pub_sha256=//p" "${man}" | head -n 1)" + if [[ -z "${ra}" ]]; then rej "record has no fingerprint line for role ${r} (partial record)" + elif [[ "${ra}" != "${ma}" ]]; then rej "role ${r} fingerprint in the record differs from the manifest"; fi + done + n="$(sed -n 's/^backup_count=//p' "${rec}" | head -n 1)" + if ! [[ "${n:-}" =~ ^[0-9]+$ ]] || [[ "${n}" -lt 2 ]]; then rej "backup_count '${n:-absent}' is below 2 (Gate 3 needs two verified backups)"; fi + [[ "$(grep -c '^backup ' "${rec}")" -ge 2 ]] || rej "fewer than two 'backup ' lines in the record" + grep -qx 'firmware_changed=no' "${rec}" || rej "'firmware_changed=no' missing (Gate 3 must not touch firmware)" + sig="$(sed -n 's/^operator_signature=//p' "${rec}" | head -n 1)" + if [[ -z "${sig}" || "${sig}" == "/dev/null 2>&1 && [[ -f "${repo_root}/scripts/trust1_key_ceremony.sh" ]]; then + if ! out="$(bash "${repo_root}/scripts/trust1_key_ceremony.sh" verify "${pub}" 2>&1)"; then + rej "trust1_key_ceremony.sh verify failed: $(tail -n 2 <<<"${out}" | tr '\n' ' ')" + fi + else + note "openssl not available: manifest signature NOT re-verified" + fi + verdict +} + +sub="${1:-}" +[[ -n "${sub}" ]] || usage +shift +case "${sub}" in + gate1) cmd_gate1 "$@" ;; + gate0-stability) cmd_gate0_stability "$@" ;; + gate2-receipt) cmd_gate2_receipt "$@" ;; + gate3) cmd_gate3 "$@" ;; + -h|--help|help) usage ;; + *) echo "usage: unknown subcommand ${sub}" >&2; usage ;; +esac diff --git a/scripts/trust1_m5_qualify.sh b/scripts/trust1_m5_qualify.sh index b3f77210..b9fe8d01 100755 --- a/scripts/trust1_m5_qualify.sh +++ b/scripts/trust1_m5_qualify.sh @@ -84,6 +84,7 @@ m5_production_store_512b|missing|-|-|-|M5: production Store on 512-byte geometry t1_gate4_manifest_ab|missing|-|-|-|Gate 4: signed boot manifest + A/B slot selection in the loader (awaits the C/asm loader) m5_migration_sig_test_key|auto|run_native_m5_migsig|-|^AIENOS_M5_MIGRATION_SIG: PASS$|M5: owner-signed migration record (native/m5 + native/sig Ed25519), host test with TEST keys only m5_migration_owner_signature|operator|-|-|-|M5: migration signed by the real owner key (needs the Gate 3 offline key ceremony) +t1_attended_evidence_checker|software|run_attended_evidence_checker|2|^TRUST1_ATTENDED_EVIDENCE_CHECK self-test \(HOST VALIDATION ONLY\): ALL PASS$|HOST VALIDATION ONLY: attended-evidence checker rejects missing, wrong-digest, partial and failing records (fixtures; proves no physical event, gate rows stay NOT_RUN) ' # =========================================================================== @@ -162,6 +163,7 @@ run_key_ceremony() { } run_gate7_preflight() { bash "${repo_root}/scripts/trust1_gate7_preflight.sh"; } run_recovery_tools() { bash "${repo_root}/scripts/verify_recovery_tools.sh"; } +run_attended_evidence_checker() { bash "${repo_root}/scripts/test_trust1_attended_evidence_check.sh"; } # The native Makefiles run ./$(TEST), so OUT must be relative to the # Makefile folder; it still points outside the tree. native_make_test() {