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/aien-sovereign-core-mv/blob/main/scripts/key-ceremony.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / scripts / key-ceremony.sh` 189 lines ยท 10423 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 # AIEN public-release key ceremony and offline signing (Drake ruling 1, sc#385; operator checklist sc#118). 18 # Plain-English guide: docs/release/KEY_CEREMONY.md. This script walks the operator through it on an OFFLINE machine. 19 # 20 # scripts/key-ceremony.sh ceremony --out DIR --backup DIR1 --backup DIR2 [--rehearsal] 21 # make the dedicated offline Ed25519 release key, show its fingerprint for the witness, run the public-key 22 # verification test (a good signature verifies, an altered file does not), copy the key to two backups and prove 23 # each backup signs, and write DIR/public/ (allowed_signers line + ceremony record: public data only) 24 # scripts/key-ceremony.sh verify-backup KEY ALLOWED_SIGNERS [--rehearsal] 25 # prove a backup copy of the key still signs and matches the pinned public key (run any time) 26 # scripts/key-ceremony.sh sign KEY ALLOWED_SIGNERS SHA256SUMS.txt [--rehearsal] 27 # stage 2 of a release: sign the checksum file offline and verify the signature before it leaves the machine 28 # 29 # --rehearsal: a throwaway key with no passphrase, labelled REHEARSAL everywhere, for practice and for the tests 30 # (scripts/test-offline-signing.sh). A rehearsal key is never a release key. Without --rehearsal the script refuses to 31 # run on a machine with a network route, under CI, or with any output inside a git checkout. 32 # AIEN_CEREMONY_ASSUME_YES=1 answers the prompts; it is honoured only with --rehearsal. 33 set -euo pipefail 34 NS=aien-release 35 die() { echo; echo "STOPPED: $*" >&2; exit 1; } 36 say() { printf '\n== %s\n' "$*"; } 37 REHEARSAL=0; OUT=""; BACKUPS=(); ARGS=() 38 while [[ $# -gt 0 ]]; do 39 case "$1" in 40 --rehearsal) REHEARSAL=1 ;; 41 --out) OUT="${2:?--out needs a directory}"; shift ;; 42 --backup) BACKUPS+=("${2:?--backup needs a directory}"); shift ;; 43 *) ARGS+=("$1") ;; 44 esac 45 shift 46 done 47 set -- "${ARGS[@]+"${ARGS[@]}"}" 48 CMD="${1:-}"; shift || true 49 YES=0; [[ "$REHEARSAL" == 1 && "${AIEN_CEREMONY_ASSUME_YES:-}" == 1 ]] && YES=1 50 LABEL=""; [[ "$REHEARSAL" == 0 ]] || LABEL="REHEARSAL " 51 52 ask() { # ask : the operator types yes to go on 53 [[ "$YES" == 0 ]] || { echo "$1 [rehearsal: yes]"; return 0; } 54 local a; read -r -p "$1 Type yes to continue: " a < /dev/tty 55 [[ "$a" == yes ]] || die "the operator did not type yes" 56 } 57 answer() { # answer 58 [[ "$YES" == 0 ]] || { echo "$2"; return 0; } 59 local a; read -r -p "$1 " a < /dev/tty; [[ -n "$a" ]] || die "an answer is required"; echo "$a" 60 } 61 in_git() { local d="$1"; while [[ ! -d "$d" ]]; do d="$(dirname "$d")"; done; git -C "$d" rev-parse --is-inside-work-tree >/dev/null 2>&1; } 62 preflight() { 63 command -v ssh-keygen >/dev/null || die "ssh-keygen is not installed (it comes with OpenSSH)" 64 echo "ssh-keygen: $(ssh -V 2>&1)" 65 if [[ "$REHEARSAL" == 1 ]]; then echo "REHEARSAL: throwaway key, not a release key; the offline checks are skipped"; return 0; fi 66 [[ -z "${CI:-}${GITHUB_ACTIONS:-}" ]] || die "this looks like a CI machine; the release key is never made or used in CI" 67 if command -v ip >/dev/null 2>&1; then 68 [[ -z "$(ip route show default 2>/dev/null)$(ip -6 route show default 2>/dev/null)" ]] \ 69 || die "this machine has a network route. Unplug the network cable and turn Wi-Fi off, then start again" 70 elif command -v route >/dev/null 2>&1 && route -n get default >/dev/null 2>&1; then 71 die "this machine has a network route. Unplug the network cable and turn Wi-Fi off, then start again" 72 fi 73 ask "Is this machine offline (no cable, Wi-Fi off) and is the witness watching the screen?" 74 } 75 # selftest : a fresh file signed by key verifies; the same file with one byte 76 # changed does not. Prints two result lines. 77 selftest() { 78 local k="$1" s="$2" w="$3" 79 printf 'AIEN key check %s %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$RANDOM$RANDOM" > "$w/challenge.txt" 80 rm -f "$w/challenge.txt.sig" 81 ssh-keygen -q -Y sign -f "$k" -n "$NS" "$w/challenge.txt" || die "the key could not sign (wrong passphrase?)" 82 ssh-keygen -q -Y verify -f "$s" -I "$NS" -n "$NS" -s "$w/challenge.txt.sig" < "$w/challenge.txt" >/dev/null \ 83 || die "a signature made by this key does NOT verify against $s" 84 echo " good signature verifies: yes" 85 sed -i.bak '1s/^A/B/' "$w/challenge.txt"; rm -f "$w/challenge.txt.bak" 86 if ssh-keygen -q -Y verify -f "$s" -I "$NS" -n "$NS" -s "$w/challenge.txt.sig" < "$w/challenge.txt" >/dev/null 2>&1; then 87 die "an ALTERED file verified; this verification setup is broken" 88 fi 89 echo " altered file is refused: yes" 90 rm -f "$w/challenge.txt" "$w/challenge.txt.sig" 91 } 92 93 ceremony() { 94 [[ -n "$OUT" ]] || die "give --out DIR (an empty folder on the offline machine)" 95 [[ "${#BACKUPS[@]}" -ge 2 ]] || die "give two --backup folders (for example two USB sticks)" 96 local d 97 for d in "$OUT" "${BACKUPS[@]}"; do ! in_git "$d" || die "$d is inside a git checkout; the private key must never be near a repository"; done 98 [[ ! -e "$OUT" || -z "$(ls -A "$OUT")" ]] || die "$OUT is not empty" 99 preflight 100 say "${LABEL}Step 1 of 6: who is here" 101 local op wit; op="$(answer "Operator's full name:" "REHEARSAL operator")"; wit="$(answer "Witness's full name:" "REHEARSAL witness")" 102 say "${LABEL}Step 2 of 6: make the key" 103 mkdir -p "$OUT/public"; chmod 700 "$OUT" 104 local stamp key comment 105 stamp="$(date -u +%Y-%m-%dT%H:%M:%SZ)" 106 if [[ "$REHEARSAL" == 1 ]]; then 107 key="$OUT/REHEARSAL-aien_release_`ed25519`"; comment="aien-REHEARSAL-throwaway-NOT-A-RELEASE-KEY" 108 ssh-keygen -q -t `ed25519` -N '' -C "$comment" -f "$key" 109 else 110 key="$OUT/aien_release_`ed25519`"; comment="aien-release-key-${stamp%%T*}" 111 echo "ssh-keygen will now ask for a passphrase twice. Choose a long one; the witness does not see it." 112 ssh-keygen -t `ed25519` -a 100 -C "$comment" -f "$key" 113 fi 114 chmod 600 "$key" 115 local fp line; fp="$(ssh-keygen -lf "$key.pub" | awk '{ print $2 }')" 116 line="$NS $(cut -d' ' -f1,2 "$key.pub")" 117 say "${LABEL}Step 3 of 6: fingerprint for the witness" 118 echo " Fingerprint: $fp" 119 echo " The witness writes this down on paper, by hand." 120 local tail8; tail8="$(answer "Witness: type the LAST 8 characters you wrote down:" "${fp: -8}")" 121 [[ "$tail8" == "${fp: -8}" ]] || die "the witness's copy does not match the fingerprint on screen" 122 { [[ "$REHEARSAL" == 0 ]] || echo "# REHEARSAL KEY: throwaway, NOT a release key. Never pin this line."; echo "$line"; } > "$OUT/public/allowed_signers" 123 say "${LABEL}Step 4 of 6: public-key verification test" 124 selftest "$key" "$OUT/public/allowed_signers" "$OUT" 125 say "${LABEL}Step 5 of 6: backups (each copy must sign and verify on its own)" 126 local b i=0 results="" 127 for b in "${BACKUPS[@]}"; do 128 i=$((i + 1)) 129 ask "Backup $i goes to $b. Is that medium plugged in?" 130 mkdir -p "$b"; chmod 700 "$b" 131 cp "$key" "$key.pub" "$b/"; chmod 600 "$b/$(basename "$key")"; sync 132 cmp -s "$key" "$b/$(basename "$key")" || die "backup $i is not an exact copy" 133 echo " backup $i is an exact copy: yes" 134 selftest "$b/$(basename "$key")" "$OUT/public/allowed_signers" "$b" 135 results="${results}backup-$i: exact copy yes; signs and verifies yes; altered file refused yes"$'\n' 136 done 137 say "${LABEL}Step 6 of 6: the public record" 138 { 139 [[ "$REHEARSAL" == 0 ]] || echo "REHEARSAL: throwaway key, not a release key, not a ceremony." 140 echo "AIEN public-release key ceremony record" 141 echo "date-utc: $stamp" 142 echo "mode: $([[ "$REHEARSAL" == 1 ]] && echo rehearsal || echo ceremony)" 143 echo "operator: $op" 144 echo "witness: $wit" 145 echo "tool: $(ssh -V 2>&1)" 146 echo "key-type: `ed25519`" 147 echo "key-comment: $comment" 148 echo "fingerprint: $fp" 149 echo "allowed_signers: $line" 150 echo "public-key verification test: good signature verifies yes; altered file refused yes" 151 printf '%s' "$results" 152 echo "private key: stays on the offline machine and the backups; it is not in this record" 153 } > "$OUT/public/ceremony-record.txt" 154 cat "$OUT/public/ceremony-record.txt" 155 echo 156 echo "Copy ONLY the folder $OUT/public to a USB stick for the connected computer. Never copy the key file." 157 } 158 159 verify_backup() { 160 local k="${1:?KEY}" s="${2:?ALLOWED_SIGNERS}" w 161 [[ -f "$k" && -f "$s" ]] || die "key or signer file missing" 162 w="$(mktemp -d)"; trap 'rm -rf "$w"' RETURN 163 echo "${LABEL}checking backup $k against $s" 164 selftest "$k" "$s" "$w" 165 echo "backup OK" 166 } 167 168 sign_sums() { 169 local k="${1:?KEY}" s="${2:?ALLOWED_SIGNERS}" f="${3:?SHA256SUMS.txt}" 170 [[ -f "$k" && -f "$s" && -f "$f" ]] || die "key, signer file or checksum file missing" 171 preflight 172 grep -qvE '^[0-9a-f]{64} \*?[A-Za-z0-9._-]+$' "$f" && die "$f has a line that is not ' '" 173 [[ -s "$f" ]] || die "$f is empty" 174 say "${LABEL}Files this signature will vouch for" 175 awk '{ print " " $2 }' "$f" 176 ask "Are these exactly the files of the release you mean to sign?" 177 rm -f "$f.sig" 178 ssh-keygen -q -Y sign -f "$k" -n "$NS" "$f" || die "signing failed (wrong passphrase?)" 179 ssh-keygen -q -Y verify -f "$s" -I "$NS" -n "$NS" -s "$f.sig" < "$f" >/dev/null || { rm -f "$f.sig"; die "the new signature does not verify against $s; nothing to upload"; } 180 echo "${LABEL}signed and verified: $f.sig" 181 echo "Carry $f.sig (only that file) to the connected computer and attach it to the draft release." 182 } 183 184 case "$CMD" in 185 ceremony) ceremony ;; 186 verify-backup) verify_backup "$@" ;; 187 sign) sign_sums "$@" ;; 188 *) sed -n '2,20p' "$0"; exit 2 ;; 189 esac