aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / scripts / test-offline-signing.sh
| 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 | # The offline-signing handoff end to end, offline, with throwaway keys only (Drake ruling 1, sc#385): |
| 18 | # 1. key ceremony rehearsal (scripts/key-ceremony.sh --rehearsal): key, fingerprint, public-key verification test, |
| 19 | # two backups that each sign; a corrupted backup is caught by verify-backup |
| 20 | # 2. stage 1 draft (archive + SHA256SUMS.txt, no signature): the publish gate refuses it (unsigned) |
| 21 | # 3. stage 2 operator signs offline with the rehearsal key (key-ceremony.sh sign) |
| 22 | # 4. stage 3 publish gate (scripts/release-publish-gate.sh): passes under the key that signed; refuses under the real |
| 23 | # docs/release/allowed_signers while it is the PLACEHOLDER, under the internal test key, under another key, after a |
| 24 | # one-byte change, and for dry-run assets or a dry-run-labelled package even when the signature is valid |
| 25 | # No real key is made, read or needed. Every key lives in a temp folder that is deleted on exit. |
| 26 | set -euo pipefail |
| 27 | ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 28 | W="$(mktemp -d "${TMPDIR:-/tmp}/aien-test-offline-signing.XXXXXX")" |
| 29 | trap 'rm -rf "$W"' EXIT |
| 30 | fail() { echo "FAIL: $*" >&2; exit 1; } |
| 31 | pass() { echo "ok: $*"; } |
| 32 | KC=(env AIEN_CEREMONY_ASSUME_YES=1 bash "$ROOT/scripts/key-ceremony.sh") |
| 33 | GATE=(bash "$ROOT/scripts/release-publish-gate.sh") |
| 34 | |
| 35 | # 1. ceremony rehearsal |
| 36 | "${KC[@]}" ceremony --rehearsal --out "$W/offline" --backup "$W/usb1" --backup "$W/usb2" > "$W/cer.log" 2>&1 \ |
| 37 | || { tail -20 "$W/cer.log" >&2; fail "ceremony rehearsal failed"; } |
| 38 | K="$W/offline/REHEARSAL-aien_release_ed25519"; S="$W/offline/public/allowed_signers" |
| 39 | [[ -f "$K" && -f "$S" && -f "$W/offline/public/ceremony-record.txt" ]] || fail "ceremony outputs missing" |
| 40 | grep -q '^REHEARSAL: throwaway key' "$W/offline/public/ceremony-record.txt" || fail "rehearsal record not labelled REHEARSAL" |
| 41 | grep -q '^# REHEARSAL KEY' "$S" || fail "rehearsal allowed_signers not labelled" |
| 42 | [[ "$(grep -c 'signs and verifies yes' "$W/offline/public/ceremony-record.txt")" -eq 2 ]] || fail "record does not show two verified backups" |
| 43 | ! grep -rqs 'PRIVATE KEY' "$W/offline/public" || fail "private key material in the public folder" |
| 44 | grep -q 'altered file is refused: yes' "$W/cer.log" || fail "public-key verification test has no negative row" |
| 45 | pass "ceremony rehearsal: key, witness fingerprint check, verification test, two backups that sign, public folder only public" |
| 46 | "${KC[@]}" verify-backup "$W/usb2/$(basename "$K")" "$S" --rehearsal > "$W/vb.log" 2>&1 || fail "intact backup failed verify-backup" |
| 47 | BK="$W/usb2/$(basename "$K")"; C3="$(sed -n 3p "$BK" | cut -c20)"; [[ "$C3" == A ]] && R=B || R=A |
| 48 | sed -i "3s/^\(.\{19\}\)./\1$R/" "$BK" # one character of the key body changed |
| 49 | if "${KC[@]}" verify-backup "$W/usb2/$(basename "$K")" "$S" --rehearsal > "$W/vb.log" 2>&1; then fail "corrupted backup passed verify-backup"; fi |
| 50 | pass "verify-backup accepts an intact backup and refuses a corrupted one" |
| 51 | if "${KC[@]}" ceremony --rehearsal --out "$ROOT/docs/release/x" --backup "$W/b1" --backup "$W/b2" > "$W/cer2.log" 2>&1; then |
| 52 | rm -rf "$ROOT/docs/release/x"; fail "ceremony wrote a key inside a git checkout" |
| 53 | fi |
| 54 | grep -q 'inside a git checkout' "$W/cer2.log" || fail "in-repo refusal not named" |
| 55 | [[ ! -e "$ROOT/docs/release/x" ]] || fail "ceremony left files in the repository" |
| 56 | pass "ceremony refuses to put a key inside a git checkout" |
| 57 | if env CI=true bash "$ROOT/scripts/key-ceremony.sh" ceremony --out "$W/ci" --backup "$W/c1" --backup "$W/c2" < /dev/null > "$W/cer3.log" 2>&1; then |
| 58 | fail "real-mode ceremony ran under CI" |
| 59 | fi |
| 60 | grep -qE 'CI machine|network route' "$W/cer3.log" || fail "real-mode ceremony on this machine not refused by name" |
| 61 | pass "real (non-rehearsal) mode refuses to run on a CI or networked machine" |
| 62 | |
| 63 | # fixture release package (no dry-run label), as stage 1 drafts it |
| 64 | mk_assets() { # dir [dry] |
| 65 | local d="$1" p="$W/pkg"; rm -rf "$d" "$p"; mkdir -p "$d" "$p/bin" |
| 66 | printf '#!/bin/sh\necho aien\n' > "$p/bin/aien" |
| 67 | { echo 'schema = "AienReleaseV1"'; echo 'candidate = "CAND-1"'; [[ -z "${2:-}" ]] || echo 'dry-run = true'; } > "$p/release.toml" |
| 68 | tar -czf "$d/sovereign-linux-aarch64.tar.gz" -C "$p" . |
| 69 | (cd "$d" && sha256sum sovereign-* > SHA256SUMS.txt) |
| 70 | } |
| 71 | # 2. stage 1 draft is unsigned: refused |
| 72 | mk_assets "$W/draft" |
| 73 | if "${GATE[@]}" "$W/draft" "$S" > "$W/g.log" 2>&1; then fail "unsigned draft passed the publish gate"; fi |
| 74 | grep -q "SHA256SUMS.txt.sig is missing" "$W/g.log" || fail "unsigned draft not refused by name" |
| 75 | pass "stage 3 refuses an unsigned draft" |
| 76 | # 3. stage 2: the operator signs offline |
| 77 | "${KC[@]}" sign "$K" "$S" "$W/draft/SHA256SUMS.txt" --rehearsal > "$W/s.log" 2>&1 || { cat "$W/s.log" >&2; fail "offline sign failed"; } |
| 78 | [[ -f "$W/draft/SHA256SUMS.txt.sig" ]] || fail "no signature produced" |
| 79 | pass "stage 2 signs offline and verifies before upload" |
| 80 | # 4. stage 3 publish gate |
| 81 | "${GATE[@]}" "$W/draft" "$S" > "$W/g.log" 2>&1 || { cat "$W/g.log" >&2; fail "signed draft refused under the key that signed it"; } |
| 82 | pass "stage 3 passes a draft signed by the pinned key" |
| 83 | if "${GATE[@]}" "$W/draft" "$ROOT/docs/release/allowed_signers" > "$W/g.log" 2>&1; then fail "gate passed under docs/release/allowed_signers"; fi |
| 84 | if ! grep -qvE '^[[:space:]]*(#|$)' "$ROOT/docs/release/allowed_signers"; then |
| 85 | grep -q "PLACEHOLDER" "$W/g.log" || fail "placeholder refusal not named" |
| 86 | pass "stage 3 refuses everything while allowed_signers is the PLACEHOLDER" |
| 87 | fi |
| 88 | if "${GATE[@]}" "$W/draft" "$ROOT/docs/release/internal_test_signers" > "$W/g.log" 2>&1; then fail "gate passed under the internal test key"; fi |
| 89 | grep -q "internal test key" "$W/g.log" || fail "internal test key refusal not named" |
| 90 | pass "stage 3 refuses the internal test key as a release key" |
| 91 | ssh-keygen -q -t ed25519 -N '' -f "$W/other"; printf 'aien-release %s\n' "$(cut -d' ' -f1,2 "$W/other.pub")" > "$W/other_signers" |
| 92 | if "${GATE[@]}" "$W/draft" "$W/other_signers" > "$W/g.log" 2>&1; then fail "gate passed under another key"; fi |
| 93 | grep -q "NOT valid" "$W/g.log" || fail "wrong key not refused by name" |
| 94 | pass "stage 3 refuses a signature from a key that is not pinned" |
| 95 | cp -r "$W/draft" "$W/flip"; A="$W/flip/sovereign-linux-aarch64.tar.gz"; SZ=$(wc -c < "$A"); OFF=$((SZ / 2)) |
| 96 | B="$(dd if="$A" bs=1 skip="$OFF" count=1 2>/dev/null | od -An -tu1 | tr -d ' ')" |
| 97 | printf "$(printf '\\%03o' $(( (B + 1) % 256 )))" | dd of="$A" bs=1 seek="$OFF" count=1 conv=notrunc 2>/dev/null |
| 98 | if "${GATE[@]}" "$W/flip" "$S" > "$W/g.log" 2>&1; then fail "gate passed an archive with one byte changed"; fi |
| 99 | grep -q "does not match the signed checksum" "$W/g.log" || fail "one-byte change not refused by name (checksum)" |
| 100 | pass "stage 3 refuses an archive with one byte changed (checksum)" |
| 101 | cp -r "$W/draft" "$W/dryfile"; echo "DRY RUN" > "$W/dryfile/DRY-RUN-NOT-A-RELEASE.txt" |
| 102 | if "${GATE[@]}" "$W/dryfile" "$S" > "$W/g.log" 2>&1; then fail "gate passed a draft holding a DRY-RUN file"; fi |
| 103 | grep -q "dry-run asset" "$W/g.log" || fail "dry-run file refusal not named" |
| 104 | mk_assets "$W/drypkg" dry; "${KC[@]}" sign "$K" "$S" "$W/drypkg/SHA256SUMS.txt" --rehearsal > /dev/null 2>&1 |
| 105 | if "${GATE[@]}" "$W/drypkg" "$S" > "$W/g.log" 2>&1; then fail "gate passed a dry-run-labelled package with a valid signature"; fi |
| 106 | grep -q "labelled dry-run" "$W/g.log" || fail "dry-run package refusal not named" |
| 107 | pass "stage 3 refuses dry-run assets and dry-run-labelled packages even with a valid signature" |
| 108 | echo "PASS: offline-signing handoff: ceremony rehearsal with verified backups, unsigned draft refused, offline signature verified, publish gate refuses placeholder, internal test key, wrong key, one-byte change and dry runs" |