aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / site / verify-omc.sh
| 1 | #!/bin/sh |
| 2 | # verify-omc.sh -- refuse the vendored Omega compiler unless omega-mv vouches for it. |
| 3 | # |
| 4 | # A digest committed next to the binary proves nothing: one PR can change both. |
| 5 | # The trust anchor is omega-mv instead. The lock (om/site/omc.provenance) names |
| 6 | # a fixed omega-mv revision; this script fetches omega-mv fresh and requires |
| 7 | # 1. the revision is an ancestor of omega-mv main (it landed through review), |
| 8 | # 2. seed/out/omc.sha256 at that revision names the locked digest, |
| 9 | # 3. seed/out/omc at that revision is byte-identical to the vendored binary, |
| 10 | # 4. seed/omega-from-seed.sh at that revision rebuilds omc from the |
| 11 | # hand-written seed hex and the result is byte-identical too. |
| 12 | # Moving to a newer compiler is a visible diff of the lock, never silent. |
| 13 | # Runs on Linux AArch64 only (the seed chain emits AArch64 executables); any |
| 14 | # other host fails, it does not skip. |
| 15 | # |
| 16 | # Usage: sh om/site/verify-omc.sh [vendored-omc [lock]] |
| 17 | # Prints OMC-PIN PASS and exits 0, or OMC-PIN FAIL <reason> and exits 1. |
| 18 | set -eu |
| 19 | REPO=https://interplane.io/drakestapleton/omega-mv |
| 20 | OMC=${1:-om/site/omc} |
| 21 | LOCK=${2:-om/site/omc.provenance} |
| 22 | |
| 23 | fail() { printf 'OMC-PIN FAIL %s\n' "$*"; exit 1; } |
| 24 | field() { sed -n "s/^$1 //p" "$LOCK"; } |
| 25 | |
| 26 | [ -f "$OMC" ] || fail "no vendored compiler at $OMC" |
| 27 | [ -f "$LOCK" ] || fail "no lock at $LOCK" |
| 28 | [ "$(uname -s) $(uname -m)" = "Linux aarch64" ] || fail "host $(uname -s) $(uname -m) cannot run the seed chain; need Linux aarch64" |
| 29 | |
| 30 | repo=$(field repository) |
| 31 | rev=$(field revision) |
| 32 | path=$(field path) |
| 33 | want=$(field sha256) |
| 34 | [ "$repo" = "$REPO" ] || fail "lock repository '$repo' is not $REPO" |
| 35 | printf '%s\n' "$rev" | grep -Eq '^[0-9a-f]{40}$' || fail "lock revision '$rev' is not a full commit sha" |
| 36 | printf '%s\n' "$want" | grep -Eq '^[0-9a-f]{64}$' || fail "lock sha256 '$want' is not a sha256" |
| 37 | [ "$path" = "seed/out/omc" ] || fail "lock path '$path' is not seed/out/omc" |
| 38 | |
| 39 | have=$(sha256sum "$OMC" | cut -d' ' -f1) |
| 40 | [ "$have" = "$want" ] || fail "vendored $OMC is $have, lock says $want" |
| 41 | |
| 42 | W=$(mktemp -d) |
| 43 | trap 'rm -rf "$W"' EXIT |
| 44 | git -C "$W" init -q |
| 45 | git -C "$W" fetch -q --filter=blob:none "$REPO" main "$rev" || fail "cannot fetch $REPO main and $rev" |
| 46 | main=$(git -C "$W" ls-remote "$REPO" refs/heads/main | awk -F"\t" '$2 == "refs/heads/main" {print $1}') |
| 47 | [ -n "$main" ] || fail "cannot read $REPO main" |
| 48 | git -C "$W" cat-file -e "$main^{commit}" || fail "fetched main $main is missing" |
| 49 | git -C "$W" merge-base --is-ancestor "$rev" "$main" || fail "$rev is not on $REPO main ($main)" |
| 50 | printf 'omc-pin: %s is an ancestor of omega-mv main %s\n' "$rev" "$main" |
| 51 | |
| 52 | recorded=$(git -C "$W" show "$rev:seed/out/omc.sha256" | cut -d' ' -f1) || fail "no seed/out/omc.sha256 at $rev" |
| 53 | [ "$recorded" = "$want" ] || fail "omega-mv $rev records $recorded, lock says $want" |
| 54 | git -C "$W" show "$rev:seed/out/omc" > "$W/omc.committed" || fail "no seed/out/omc at $rev" |
| 55 | cmp -s "$W/omc.committed" "$OMC" || fail "vendored $OMC differs from seed/out/omc at $rev" |
| 56 | printf 'omc-pin: vendored binary equals seed/out/omc at %s (%s)\n' "$rev" "$want" |
| 57 | |
| 58 | git -C "$W" -c advice.detachedHead=false checkout -q "$rev" || fail "cannot check out $rev" |
| 59 | sh "$W/seed/omega-from-seed.sh" > "$W/birth.log" 2>&1 || { cat "$W/birth.log"; fail "seed rebuild failed at $rev"; } |
| 60 | grep -q '^RC=0$' "$W/birth.log" || { cat "$W/birth.log"; fail "seed rebuild did not report RC=0"; } |
| 61 | cmp -s "$W/seed/out/omc" "$OMC" || fail "seed rebuild at $rev is $(sha256sum "$W/seed/out/omc" | cut -d' ' -f1), not the vendored binary" |
| 62 | printf 'omc-pin: seed/omega-from-seed.sh at %s rebuilt the same %s bytes\n' "$rev" "$(wc -c < "$OMC")" |
| 63 | printf 'OMC-PIN PASS %s %s\n' "$rev" "$want" |