interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / ipl / tests / run.sh
| 1 | #!/bin/bash |
| 2 | # tests/run.sh OMC SHA2_OM CHAIN_OM: the step 1 gate. Builds bin/landrec and bin/chain with OMC (its |
| 3 | # sha256 must be PIN's), then checks the record rules, a full project life and every tamper control. |
| 4 | # Prints PASS/FAIL per case and ends "GATE PASS cases=N" (exit 0) or "GATE FAIL ..." (exit 1); |
| 5 | # exit 2 on a pin or build error. Scratch files only; no network, no old store. |
| 6 | set -u |
| 7 | cd "$(dirname "$0")/.." || exit 2 |
| 8 | omc=${1:?OMC}; sha2=${2:?SHA2_OM}; chainom=${3:?CHAIN_OM} |
| 9 | want=$(sed -n 's/^omc-sha256 //p' PIN); got=$(sha256sum "$omc" | cut -d' ' -f1) |
| 10 | [ "$got" = "$want" ] || { echo "GATE FAIL omc sha256 $got, PIN wants $want" >&2; exit 2; } |
| 11 | [ "$(sha256sum "$sha2" | cut -d' ' -f1)" = "$(sed -n 's/^sha2-om-sha256 //p' PIN)" ] || { echo "GATE FAIL sha2.om is not PIN's" >&2; exit 2; } |
| 12 | [ "$(sha256sum "$chainom" | cut -d' ' -f1)" = "$(sed -n 's/^chain-om-sha256 //p' PIN)" ] || { echo "GATE FAIL chain.om is not PIN's" >&2; exit 2; } |
| 13 | T=$(mktemp -d /tmp/ipl-gate.XXXXXX) || exit 2; trap 'rm -rf "$T"' EXIT |
| 14 | mkdir "$T/bin"; cp ipl "$T/ipl" || exit 2 |
| 15 | "$omc" < om/landrec.om > "$T/bin/landrec" || { echo "GATE FAIL landrec.om did not compile" >&2; exit 2; } |
| 16 | { printf 'om2\n'; cat "$sha2" "$chainom"; } | "$omc" > "$T/bin/chain" || { echo "GATE FAIL chain did not compile" >&2; exit 2; } |
| 17 | chmod +x "$T/bin/landrec" "$T/bin/chain" "$T/ipl"; cp "$T/bin/chain" "$T/chain" |
| 18 | L=$T/bin/landrec; pass=0; fail=0; NC=0123456789abcdef0123456789abcdef |
| 19 | t() { # NAME WANT_EXIT cmd... |
| 20 | local name=$1 want=$2 rc; shift 2; "$@" > "$T/out" 2> "$T/err"; rc=$? |
| 21 | if [ "$rc" = "$want" ]; then pass=$((pass + 1)); echo "PASS $name"; else fail=$((fail + 1)); echo "FAIL $name: exit $rc, want $want: $(head -c 200 "$T/err")"; fi |
| 22 | } |
| 23 | Z=0000000000000000000000000000000000000000; A=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 24 | H=$(printf x | sha256sum | cut -c1-64); FP="SHA256:bBVPM9xU/+oMCeKoeBrBmyI4XkGmp3YeBKYF/0hvArU" |
| 25 | # ---- record rules |
| 26 | t rec-land 0 $L land a main $Z $A $H $H r |
| 27 | t rec-land-branch 0 $L land AienOS-nv feature/x-1.2 $Z $A $H $H r |
| 28 | t rec-project 0 $L project interplane.io main private "$FP" - $NC |
| 29 | t rec-project-alias 0 $L project a main public "$FP" rad:z6do9WDBhuSnvopDkgFdFr1yWA62 $NC |
| 30 | t no-nonce-short 1 $L project a main public "$FP" - ${NC%?} |
| 31 | t no-nonce-upper 1 $L project a main public "$FP" - ${NC%f}F |
| 32 | t usage-project-no-nonce 2 $L project a main public "$FP" - |
| 33 | printf 'interplane-land 1\nproject a\nbranch main\nold %s\nnew %s\nreceipt %s\nverdict %s\nrequest r\n' $Z $A $H $H > "$T/want" |
| 34 | $L land a main $Z $A $H $H r > "$T/gotp" 2>/dev/null; t rec-canonical-bytes 0 cmp -s "$T/want" "$T/gotp" |
| 35 | t no-name-dot 1 $L land .a main $Z $A $H $H r |
| 36 | t no-name-enddot 1 $L land a. main $Z $A $H $H r |
| 37 | t no-name-space 1 $L land "a b" main $Z $A $H $H r |
| 38 | t no-name-newline 1 $L land "$(printf 'a\nb')" main $Z $A $H $H r |
| 39 | t no-name-empty 1 $L land "" main $Z $A $H $H r |
| 40 | t no-name-slash 1 $L land a/b main $Z $A $H $H r |
| 41 | t no-branch-dash 1 $L land a -main $Z $A $H $H r |
| 42 | t no-branch-dotdot 1 $L land a a..b $Z $A $H $H r |
| 43 | t no-branch-slashes 1 $L land a a//b $Z $A $H $H r |
| 44 | t no-branch-dotpart 1 $L land a a/.b $Z $A $H $H r |
| 45 | t no-branch-trail 1 $L land a main/ $Z $A $H $H r |
| 46 | t no-old-long 1 $L land a main ${Z}0 $A $H $H r |
| 47 | t no-new-upper 1 $L land a main $Z ${A%a}A $H $H r |
| 48 | t no-new-short 1 $L land a main $Z ${A%a} $H $H r |
| 49 | t no-receipt-short 1 $L land a main $Z $A ${H%?} $H r |
| 50 | t no-verdict-nonhex 1 $L land a main $Z $A $H ${H%?}g r |
| 51 | t no-request-space 1 $L land a main $Z $A $H $H "r 1" |
| 52 | t no-request-tab 1 $L land a main $Z $A $H $H "$(printf 'r\tx')" |
| 53 | t no-visibility 1 $L project a main secret "$FP" - $NC |
| 54 | t no-owner-short 1 $L project a main public SHA256:short - $NC |
| 55 | t no-owner-kind 1 $L project a main public "MD5:bBVPM9xU/+oMCeKoeBrBmyI4XkGmp3YeBKYF/0hvArUab" - $NC |
| 56 | t no-alias 1 $L project a main public "$FP" rad:x6do9WDBhuSnvopDkgFdFr1yWA62 $NC |
| 57 | t no-alias-dashes 1 $L project a main public "$FP" -- $NC |
| 58 | t usage-few 2 $L land a main $Z $A $H $H |
| 59 | t usage-many 2 $L land a main $Z $A $H $H r extra |
| 60 | t usage-word 2 $L nothing |
| 61 | $L land .a main $Z $A $H $H r > "$T/gotp" 2>/dev/null; t refusal-prints-nothing 0 test ! -s "$T/gotp" |
| 62 | t no-branch-lock 1 $L land a feature.lock $Z $A $H $H r |
| 63 | t no-branch-lock-part 1 $L land a a.lock/b $Z $A $H $H r |
| 64 | t rec-branch-lockish 0 $L land a a.locked/blocks $Z $A $H $H r |
| 65 | N128=$(head -c 128 /dev/zero | tr '\0' a) |
| 66 | t rec-name-128 0 $L land "$N128" main $Z $A $H $H r |
| 67 | t rec-name-129 0 $L land "${N128}a" main $Z $A $H $H r |
| 68 | t rec-branch-129 0 $L land a "${N128}a" $Z $A $H $H r |
| 69 | # a request id has no size chosen here: the longest argument Linux allows passes and comes back whole |
| 70 | BIG=$(head -c 131071 /dev/zero | tr '\0' r) |
| 71 | t rec-request-longest 0 $L land a main $Z $A $H $H "$BIG" |
| 72 | $L land a main $Z $A $H $H "$BIG" 2>/dev/null | tail -n 1 > "$T/gotp"; t rec-request-longest-whole 0 test "$(wc -c < "$T/gotp")" = 131080 |
| 73 | t no-request-bad-byte-late 1 $L land a main $Z $A $H $H "${BIG%r}!" |
| 74 | t check-name 0 $L check name interplane.io |
| 75 | t check-name-traversal 1 $L check name ../demo |
| 76 | t check-name-slash 1 $L check name a/b |
| 77 | t check-branch 0 $L check branch feature/x |
| 78 | t check-request-newline 1 $L check request "$(printf 'x\nrequest req-1')" |
| 79 | t check-unknown-rule 2 $L check colour red |
| 80 | PUB68=$(head -c 68 /dev/zero | tr '\0' A) |
| 81 | FP2=SHA256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 82 | t rec-successor 0 $L successor a "$FP" "$FP2" "$PUB68" rotate-1 |
| 83 | printf 'interplane-successor 1\nproject a\nold %s\nnew %s\npub %s\nreason rotate-1\n' "$FP" "$FP2" "$PUB68" > "$T/want" |
| 84 | $L successor a "$FP" "$FP2" "$PUB68" rotate-1 > "$T/gotp" 2>/dev/null; t rec-successor-canonical-bytes 0 cmp -s "$T/want" "$T/gotp" |
| 85 | t rec-successor-dash-reason 0 $L successor a "$FP" "$FP2" "$PUB68" - |
| 86 | t no-successor-pub-short 1 $L successor a "$FP" "$FP2" "${PUB68%A}" rotate-1 |
| 87 | t no-successor-reason-space 1 $L successor a "$FP" "$FP2" "$PUB68" "rotate 1" |
| 88 | t no-successor-old-short 1 $L successor a SHA256:short "$FP2" "$PUB68" rotate-1 |
| 89 | t no-successor-new-kind 1 $L successor a "$FP" "MD5:bBVPM9xU/+oMCeKoeBrBmyI4XkGmp3YeBKYF/0hvArUab" "$PUB68" - |
| 90 | t check-pub 0 $L check pub "$PUB68" |
| 91 | t check-pub-short 1 $L check pub "${PUB68%A}" |
| 92 | t check-owner 0 $L check owner "$FP" |
| 93 | t check-reason 0 $L check reason rotate-1 |
| 94 | t check-reason-dash 0 $L check reason - |
| 95 | t check-reason-space 1 $L check reason "a b" |
| 96 | t usage-successor-few 2 $L successor a "$FP" "$FP2" "$PUB68" |
| 97 | t usage-successor-many 2 $L successor a "$FP" "$FP2" "$PUB68" - extra |
| 98 | # ---- one project's life |
| 99 | export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid |
| 100 | R=$T/root; P=$R/projects/demo; mkdir -p "$P" |
| 101 | ssh-keygen -q -t ed25519 -N "" -C gate -f "$T/key"; ssh-keygen -q -t ed25519 -N "" -C other -f "$T/key2" |
| 102 | FPK=$(ssh-keygen -lf "$T/key.pub" | awk '{print $2}') |
| 103 | printf '* %s\n' "$FPK" > "$T/owner-pins" |
| 104 | chmod 600 "$T/owner-pins" |
| 105 | export IPL_OWNER_PINS="$T/owner-pins" |
| 106 | git init -q -b main "$T/work"; cd "$T/work" || exit 2 |
| 107 | echo a > f; git add f; git commit -q -m one; C1=$(git rev-parse HEAD) |
| 108 | echo b >> f; git commit -q -am two; C2=$(git rev-parse HEAD) |
| 109 | echo c >> f; git commit -q -am three; C4=$(git rev-parse HEAD) |
| 110 | git checkout -q -b side "$C1"; echo z > g; git add g; git commit -q -m side; C3=$(git rev-parse HEAD) |
| 111 | cd - >/dev/null || exit 2 |
| 112 | git init -q --bare "$P/repo.git"; git --git-dir="$P/repo.git" fetch -q "$T/work" "$C1"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C1" |
| 113 | echo ev > "$T/ev"; echo note > "$T/note"; echo rc > "$T/rc"; echo vd > "$T/vd" |
| 114 | I=$T/ipl |
| 115 | t init 0 $I init "$R" demo main public - "$T/key" |
| 116 | n=$(wc -l < "$P/chain.tsv") |
| 117 | t init-again-same-terms 0 $I init "$R" demo main public - "$T/key" |
| 118 | t init-again-adds-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n" |
| 119 | t init-again-other-terms 2 $I init "$R" demo main private - "$T/key" |
| 120 | t init-again-other-key 2 $I init "$R" demo main public - "$T/key2" |
| 121 | # a name or branch longer than the chain's subject field goes in as a digest; only the file system says no |
| 122 | N200=$(head -c 200 /dev/zero | tr '\0' n); mkdir -p "$R/projects/$N200"; git init -q --bare "$R/projects/$N200/repo.git" |
| 123 | t long-name-init 0 $I init "$R" "$N200" main public - "$T/key" |
| 124 | t long-name-subject-is-digest 0 grep -q " PROJECT [^ ]* sha256:[0-9a-f]\{64\} " "$R/projects/$N200/chain.tsv" |
| 125 | t long-name-verify 0 $I verify "$R" "$N200"; rm -rf "$R/projects/$N200" |
| 126 | t no-name-longer-than-file-names 2 $I verify "$R" "$(head -c 300 /dev/zero | tr '\0' n)" |
| 127 | mkdir -p "$R/projects/Demo"; git init -q --bare "$R/projects/Demo/repo.git" |
| 128 | t init-case-collision 2 $I init "$R" Demo main public - "$T/key"; rm -rf "$R/projects/Demo" |
| 129 | t import 0 $I import "$R" demo main "$T/ev" "$T/note" import-1 "$T/key" |
| 130 | t import-twice-new-request 4 $I import "$R" demo main "$T/ev" "$T/note" import-2 "$T/key" |
| 131 | t land 0 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key" |
| 132 | n=$(wc -l < "$P/chain.tsv") |
| 133 | t replay-same 0 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key" |
| 134 | t replay-adds-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n" |
| 135 | t replay-other-head 4 $I land "$R" demo main "$C3" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key" |
| 136 | t no-non-fast-forward 4 $I land "$R" demo main "$C3" "$T/work" "$T/rc" "$T/vd" req-2 "$T/key" |
| 137 | t no-same-head 4 $I land "$R" demo main "$C2" - "$T/rc" "$T/vd" req-3 "$T/key" |
| 138 | t no-unknown-commit 4 $I land "$R" demo main 1111111111111111111111111111111111111111 - "$T/rc" "$T/vd" req-4 "$T/key" |
| 139 | t no-bad-request 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" "bad req" "$T/key" |
| 140 | t no-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-5 "$T/key2" |
| 141 | t no-missing-verdict 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/absent" req-6 "$T/key" |
| 142 | t refusals-add-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n" |
| 143 | t verify 0 $I verify "$R" demo |
| 144 | # ---- crafted arguments: refused before anything is read or written outside the project |
| 145 | n=$(wc -l < "$P/chain.tsv"); h=$(git --git-dir="$P/repo.git" rev-parse refs/heads/main) |
| 146 | mkdir -p "$T/outside"; cp -a "$P" "$T/outside/demo" |
| 147 | t no-traversal-verify 2 $I verify "$R" ../../outside/demo |
| 148 | t no-traversal-land 2 $I land "$R" ../../outside/demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-t "$T/key" |
| 149 | ln -s "$T/outside/demo" "$R/projects/linked"; t no-symlink-project 2 $I verify "$R" linked; rm "$R/projects/linked" |
| 150 | t no-request-newline 2 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" "$(printf 'x\nrequest req-1')" "$T/key" |
| 151 | t no-source-option 2 $I land "$R" demo main "$C4" "--upload-pack=touch $T/pwned" "$T/rc" "$T/vd" req-o "$T/key" |
| 152 | t no-source-remote 2 $I land "$R" demo main "$C4" "ssh://example.invalid/x" "$T/rc" "$T/vd" req-o "$T/key" |
| 153 | t no-source-ext 2 $I land "$R" demo main "$C4" "ext::sh -c touch% $T/pwned" "$T/rc" "$T/vd" req-o "$T/key" |
| 154 | t source-ran-nothing 0 test ! -e "$T/pwned" |
| 155 | t no-branch-lock-land 2 $I land "$R" demo x.lock "$C4" "$T/work" "$T/rc" "$T/vd" req-l "$T/key" |
| 156 | t no-branch-under-existing 4 $I land "$R" demo main/sub "$C4" "$T/work" "$T/rc" "$T/vd" req-d "$T/key" |
| 157 | ssh-keygen -q -t rsa -b 2048 -N "" -C rsa -f "$T/rsa" |
| 158 | mkdir -p "$R/projects/rsaproj"; git init -q --bare "$R/projects/rsaproj/repo.git" |
| 159 | t no-rsa-owner 2 $I init "$R" rsaproj main public - "$T/rsa" |
| 160 | t rsa-init-wrote-nothing 0 test ! -e "$R/projects/rsaproj/chain.tsv" -a ! -e "$R/projects/rsaproj/owner.pub" |
| 161 | t no-bad-init-name 2 $I init "$R" "bad name" main public - "$T/key" |
| 162 | # the owner's public key beside another private key: refused before anything is appended |
| 163 | cp "$T/key2" "$T/mixed"; cp "$T/key.pub" "$T/mixed.pub" |
| 164 | t no-mismatched-key-pair 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-m "$T/mixed" |
| 165 | t crafted-add-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n" -a "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$h" |
| 166 | # the same request with other evidence is not the same request |
| 167 | echo other > "$T/vd2"; t replay-other-verdict 4 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd2" req-1 "$T/key" |
| 168 | t replay-as-import 4 $I import "$R" demo main "$T/rc" "$T/vd" req-1 "$T/key" |
| 169 | # a second branch, and landings racing on one request id: one record, both answer the same |
| 170 | t land-new-branch 0 $I land "$R" demo topic "$C3" "$T/work" "$T/rc" "$T/vd" req-b "$T/key" |
| 171 | ( $I land "$R" demo topic/x "$C3" - "$T/rc" "$T/vd" req-c "$T/key" >/dev/null 2>&1; echo $? > "$T/r1" ) & |
| 172 | ( $I land "$R" demo topic/x "$C3" - "$T/rc" "$T/vd" req-c "$T/key" >/dev/null 2>&1; echo $? > "$T/r2" ) & wait |
| 173 | t race-topic-child-refused 0 test "$(cat "$T/r1")$(cat "$T/r2")" = 44 |
| 174 | git --git-dir="$P/repo.git" update-ref -d refs/heads/topic; t tamper-second-branch-removed 3 $I verify "$R" demo |
| 175 | git --git-dir="$P/repo.git" update-ref refs/heads/topic "$C3"; t second-branch-back 0 $I verify "$R" demo |
| 176 | # ---- tamper controls: each starts from the good copy |
| 177 | cp -a "$P" "$T/good"; fresh() { rm -rf "$P"; cp -a "$T/good" "$P"; } |
| 178 | sed -i '3s/main/maim/' "$P/chain.tsv"; t tamper-chain-byte 3 $I verify "$R" demo; fresh |
| 179 | sed -i '5d' "$P/chain.tsv"; t tamper-record-removed 3 $I verify "$R" demo; fresh |
| 180 | echo x >> "$P/records/3"; t tamper-payload 3 $I verify "$R" demo; fresh |
| 181 | rm "$P/records/5"; t tamper-payload-missing 3 $I verify "$R" demo; fresh |
| 182 | git --git-dir="$P/repo.git" update-ref refs/heads/main "$C1"; t tamper-ref-behind 3 $I verify "$R" demo; fresh |
| 183 | git --git-dir="$P/repo.git" fetch -q "$T/work" "$C3"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C3"; t tamper-ref-elsewhere 3 $I verify "$R" demo; fresh |
| 184 | cp "$T/key2.pub" "$P/owner.pub"; t tamper-owner-key 3 $I verify "$R" demo; fresh |
| 185 | head -n 5 "$T/good/chain.tsv" > "$P/chain.tsv"; t tamper-signature-dropped 3 $I verify "$R" demo; fresh |
| 186 | # a valid signature moved to stand for another record must not verify (records 2 and 6 are both SIG) |
| 187 | cp "$P/records/2" "$T/sig2"; cp "$T/sig2" "$P/records/6"; t tamper-signature-swapped 3 $I verify "$R" demo; fresh |
| 188 | # a well-formed record 6 whose signature is over other bytes, by another key or for another purpose |
| 189 | FPK=$(ssh-keygen -lf "$T/key.pub" | awk '{print $2}') |
| 190 | lmsg() { awk -F'\t' -v n="$1" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$T/good/chain.tsv"; } |
| 191 | forge() { head -n 5 "$T/good/chain.tsv" > "$P/chain.tsv"; "$T/chain" add "$P/chain.tsv" SIG "$FPK" 5 < "$1" >/dev/null; cp "$1" "$P/records/6"; } |
| 192 | printf 'deadbeef\n' > "$T/m1"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m1" 2>/dev/null |
| 193 | forge "$T/m1.sig"; t tamper-signature-over-other-bytes 3 $I verify "$R" demo; fresh |
| 194 | lmsg 3 > "$T/m0"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m0" 2>/dev/null |
| 195 | forge "$T/m0.sig"; t tamper-signature-of-another-record 3 $I verify "$R" demo; fresh |
| 196 | lmsg 5 > "$T/m2"; ssh-keygen -q -Y sign -n interplane -f "$T/key2" "$T/m2" 2>/dev/null |
| 197 | forge "$T/m2.sig"; t tamper-signature-by-other-key 3 $I verify "$R" demo; fresh |
| 198 | lmsg 5 > "$T/m3"; ssh-keygen -q -Y sign -n other-purpose -f "$T/key" "$T/m3" 2>/dev/null |
| 199 | forge "$T/m3.sig"; t tamper-signature-for-other-purpose 3 $I verify "$R" demo; fresh |
| 200 | lmsg 5 > "$T/m4"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m4" 2>/dev/null |
| 201 | forge "$T/m4.sig"; t control-honest-resigned-record-verifies 0 $I verify "$R" demo; fresh |
| 202 | # the last line is not covered by a later record: its actor is checked on its own |
| 203 | sed -i "\$s#$FPK#SHA256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA#" "$P/chain.tsv"; t tamper-last-actor 3 $I verify "$R" demo; fresh |
| 204 | # an owner-signed record that is not canonical (no new head) must not verify |
| 205 | printf 'interplane-land 1\nproject demo\nbranch main\nold %s\nreceipt %s\nverdict %s\nrequest bad\n' "$C2" $H $H > "$T/badpay" |
| 206 | head -n 6 "$T/good/chain.tsv" > "$P/chain.tsv"; "$T/chain" add "$P/chain.tsv" LAND "$FPK" main < "$T/badpay" >/dev/null; cp "$T/badpay" "$P/records/7" |
| 207 | awk -F'\t' 'NR==7 {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$P/chain.tsv" > "$T/m5"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m5" 2>/dev/null |
| 208 | "$T/chain" add "$P/chain.tsv" SIG "$FPK" 7 < "$T/m5.sig" >/dev/null; cp "$T/m5.sig" "$P/records/8" |
| 209 | t tamper-signed-but-malformed 3 $I verify "$R" demo; fresh |
| 210 | # a whole project copied under another name is not that project |
| 211 | cp -a "$T/good" "$R/projects/demo2"; t tamper-copied-under-other-name 3 $I verify "$R" demo2; rm -rf "$R/projects/demo2" |
| 212 | # ---- interruptions: only the same request, by the owner, finishes one; nothing else gets in |
| 213 | t land-2 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key" |
| 214 | n=$(wc -l < "$P/chain.tsv"); cp -a "$P" "$T/done"; redo() { rm -rf "$P"; cp -a "$T/done" "$P"; } |
| 215 | # (a) signed, branch not moved yet |
| 216 | git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2" |
| 217 | t pending-ref-seen 3 $I verify "$R" demo |
| 218 | t pending-ref-blocks-other 3 $I land "$R" demo main "$C4" - "$T/rc" "$T/vd" req-8 "$T/key" |
| 219 | t pending-ref-not-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2" |
| 220 | t pending-ref-still-behind 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C2" |
| 221 | t pending-ref-finished 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key" |
| 222 | t finish-adds-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n" |
| 223 | # (b) recorded, not signed yet, branch not moved |
| 224 | redo; sed -i '$d' "$P/chain.tsv"; rm "$P/records/$n"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2" |
| 225 | t pending-sig-seen 3 $I verify "$R" demo |
| 226 | t pending-sig-blocks-other 3 $I land "$R" demo main "$C4" - "$T/rc" "$T/vd" req-8 "$T/key" |
| 227 | t pending-sig-not-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2" |
| 228 | t pending-sig-not-for-mixed-pair 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/mixed" |
| 229 | t pending-sig-untouched 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C2" -a "$(wc -l < "$P/chain.tsv")" = "$((n - 1))" |
| 230 | t pending-sig-finished 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key" |
| 231 | t pending-sig-result 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C4" -a "$(wc -l < "$P/chain.tsv")" = "$n" |
| 232 | # (c) recorded, the payload file did not reach records/ but is still in staging |
| 233 | redo; mkdir -p "$P/staging"; mv "$P/records/$((n - 1))" "$P/staging/req-req-7.payload" |
| 234 | t payload-lost-seen 3 $I verify "$R" demo |
| 235 | t payload-lost-healed 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key" |
| 236 | # (d) recorded, the payload is gone for good: refused whole, nothing moves |
| 237 | redo; rm "$P/records/$((n - 1))"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2" |
| 238 | t payload-gone-refused 3 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key" |
| 239 | t payload-gone-untouched 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C2" |
| 240 | # an old request repeated after later landings answers and moves nothing |
| 241 | redo; t replay-historical 0 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key" |
| 242 | t replay-historical-moved-nothing 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C4" -a "$(wc -l < "$P/chain.tsv")" = "$n" |
| 243 | # init interrupted before its signature is finished by the same init, not by another key |
| 244 | mkdir -p "$R/projects/half"; git init -q --bare "$R/projects/half/repo.git" |
| 245 | t half-init 0 $I init "$R" half main private - "$T/key" |
| 246 | sed -i '$d' "$R/projects/half/chain.tsv"; rm "$R/projects/half/records/2" |
| 247 | t half-init-seen 3 $I verify "$R" half |
| 248 | t half-init-not-other-key 2 $I init "$R" half main private - "$T/key2" |
| 249 | t half-init-not-other-terms 2 $I init "$R" half main public - "$T/key" |
| 250 | t half-init-finished 0 $I init "$R" half main private - "$T/key" |
| 251 | # ---- second review round |
| 252 | ref() { git --git-dir="$P/repo.git" rev-parse -q --verify "refs/heads/$1" 2>/dev/null; } |
| 253 | lines() { wc -l < "$P/chain.tsv"; } |
| 254 | # PENDING_REF is not finished by the owner's public key beside another private key |
| 255 | redo; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2" |
| 256 | t pending-ref-not-for-mixed-pair 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/mixed" |
| 257 | t pending-ref-mixed-untouched 0 test "$(ref main)" = "$C2" |
| 258 | # an annotated tag is not a commit, even though it leads to one |
| 259 | redo; TAG=$(cd "$T/work" && git tag -a -m t vt "$C3" && git rev-parse vt); n=$(lines) |
| 260 | t no-tag-object 4 $I land "$R" demo tagbr "$TAG" "$T/work" "$T/rc" "$T/vd" req-tag "$T/key" |
| 261 | t tag-added-nothing 0 test "$(lines)" = "$n" -a -z "$(ref tagbr)" |
| 262 | t tag-commit-control 0 $I land "$R" demo tagbr "$C3" "$T/work" "$T/rc" "$T/vd" req-tag2 "$T/key" |
| 263 | # a landing stopped at each write boundary: seen, closed to others, finished by the same request |
| 264 | C5=$(cd "$T/work" && git checkout -q main && echo d >> f && git commit -q -am four && git rev-parse HEAD) |
| 265 | for s in after-stage mid-record after-record after-sig; do |
| 266 | redo; n=$(lines) |
| 267 | IPL_TEST_STOP=$s t "stop-$s" 9 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key" |
| 268 | t "stop-$s-branch-not-moved" 0 test "$(ref main)" = "$C4" |
| 269 | if [ $s = after-stage ]; then t "stop-$s-nothing-recorded" 0 $I verify "$R" demo |
| 270 | else |
| 271 | t "stop-$s-seen" 3 $I verify "$R" demo |
| 272 | t "stop-$s-closed-to-others" 3 $I land "$R" demo topic "$C4" "$T/work" "$T/rc" "$T/vd" req-g "$T/key" |
| 273 | t "stop-$s-not-for-other-key" 2 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key2" |
| 274 | fi |
| 275 | t "stop-$s-finished" 0 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key" |
| 276 | t "stop-$s-result" 0 test "$(ref main)" = "$C5" -a "$(lines)" = "$((n + 2))" -a -z "$(ls "$P/staging")" |
| 277 | t "stop-$s-catalog-follows" 0 grep -q "^demo [0-9a-f]\{64\} main $C5 public$" "$R/catalog.tsv" |
| 278 | done |
| 279 | # stopped after the branch moved, before the catalog: the project verifies, the same request publishes |
| 280 | redo; n=$(lines); $I catalog "$R" >/dev/null 2>&1 |
| 281 | IPL_TEST_STOP=after-ref t stop-after-ref 9 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key" |
| 282 | t stop-after-ref-verifies 0 $I verify "$R" demo |
| 283 | t stop-after-ref-catalog-behind 1 grep -q "^demo [0-9a-f]\{64\} main $C5 public$" "$R/catalog.tsv" |
| 284 | t stop-after-ref-finished 0 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key" |
| 285 | t stop-after-ref-result 0 test "$(lines)" = "$((n + 2))" -a -z "$(ls "$P/staging")" |
| 286 | t stop-after-ref-catalog-follows 0 grep -q "^demo [0-9a-f]\{64\} main $C5 public$" "$R/catalog.tsv" |
| 287 | # a longer branch part than the chain's subject field lands; one the file system cannot hold is refused |
| 288 | redo; B200=$(head -c 200 /dev/zero | tr '\0' b) |
| 289 | t long-branch-lands 0 $I land "$R" demo "x/$B200" "$C3" "$T/work" "$T/rc" "$T/vd" req-lb "$T/key" |
| 290 | t long-branch-verifies 0 $I verify "$R" demo |
| 291 | t no-branch-part-too-long 2 $I land "$R" demo "y/$(head -c 252 /dev/zero | tr '\0' b)" "$C3" "$T/work" "$T/rc" "$T/vd" req-lb2 "$T/key" |
| 292 | # a folder part may be as long as a file name; only the last part needs room for git's .lock |
| 293 | t long-branch-folder-part 0 $I land "$R" demo "$(head -c 255 /dev/zero | tr '\0' f)/x" "$C3" "$T/work" "$T/rc" "$T/vd" req-lb3 "$T/key" |
| 294 | mkdir -p "$R/projects/lb"; git init -q --bare "$R/projects/lb/repo.git" |
| 295 | t no-default-branch-too-long 2 $I init "$R" lb "$(head -c 252 /dev/zero | tr '\0' b)" public - "$T/key" |
| 296 | t long-default-refusal-wrote-nothing 0 test ! -e "$R/projects/lb/owner.pub" -a ! -e "$R/projects/lb/chain.tsv"; rm -rf "$R/projects/lb" |
| 297 | # name, branch and request all as long as an argument can be: the payload holds them whole |
| 298 | t rec-all-longest 0 $L land "$BIG" "$BIG" $Z $A $H $H "$BIG" |
| 299 | $L land "$BIG" "$BIG" $Z $A $H $H "$BIG" 2>/dev/null > "$T/gotp"; t rec-all-longest-whole 0 test "$(wc -c < "$T/gotp")" = 393493 |
| 300 | # init stopped at each point: only the key that started it goes on |
| 301 | for s in after-stage mid-record after-record after-sig; do |
| 302 | Q=$R/projects/i-$s; mkdir -p "$Q"; git init -q --bare "$Q/repo.git" |
| 303 | IPL_TEST_STOP=$s t "init-stop-$s" 9 $I init "$R" "i-$s" main public - "$T/key" |
| 304 | cp "$Q/owner.pub" "$T/owner.before" |
| 305 | t "init-stop-$s-not-other-key" 2 $I init "$R" "i-$s" main public - "$T/key2" |
| 306 | t "init-stop-$s-owner-kept" 0 cmp -s "$T/owner.before" "$Q/owner.pub" |
| 307 | t "init-stop-$s-not-mixed-pair" 2 $I init "$R" "i-$s" main public - "$T/mixed" |
| 308 | t "init-stop-$s-owner-still-kept" 0 cmp -s "$T/owner.before" "$Q/owner.pub" |
| 309 | t "init-stop-$s-not-other-terms" 2 $I init "$R" "i-$s" main private - "$T/key" |
| 310 | t "init-stop-$s-finished" 0 $I init "$R" "i-$s" main public - "$T/key" |
| 311 | t "init-stop-$s-two-records" 0 test "$(wc -l < "$Q/chain.tsv")" = 2 |
| 312 | t "init-stop-$s-in-catalog" 0 grep -q "^i-$s " "$R/catalog.tsv" |
| 313 | rm -rf "$Q" |
| 314 | done |
| 315 | # a first init with someone's public key beside another private key: refused, and nothing is left behind |
| 316 | Q=$R/projects/mix1; mkdir -p "$Q"; git init -q --bare "$Q/repo.git" |
| 317 | t no-fresh-init-with-mixed-pair 2 $I init "$R" mix1 main public - "$T/mixed" |
| 318 | t mixed-init-left-nothing 0 test ! -e "$Q/owner.pub" -a ! -e "$Q/staging/init.payload" -a ! -e "$Q/chain.tsv"; rm -rf "$Q" |
| 319 | # a first chain line that was never finished: the owner's same init cuts it and completes, in one call |
| 320 | Q=$R/projects/torn1; mkdir -p "$Q"; git init -q --bare "$Q/repo.git" |
| 321 | IPL_TEST_STOP=after-stage t torn-first-setup 9 $I init "$R" torn1 main public - "$T/key" |
| 322 | printf '1\t2026' > "$Q/chain.tsv" |
| 323 | t torn-first-line-finished 0 $I init "$R" torn1 main public - "$T/key" |
| 324 | t torn-first-line-two-records 0 test "$(wc -l < "$Q/chain.tsv")" = 2; rm -rf "$Q" |
| 325 | # a repair on the owner's call is said out loud, even when the request itself is then refused |
| 326 | redo; printf '99\tgarbage' >> "$P/chain.tsv" |
| 327 | t torn-then-altered-request 4 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd2" req-7 "$T/key" |
| 328 | cp "$T/err" "$T/err.kept"; t repair-was-announced 0 grep -q "repaired: cut a torn last line" "$T/err.kept" |
| 329 | # a torn last line is never a record: the owner's next call cuts it, nobody else's does |
| 330 | redo; printf '99\tgarbage' >> "$P/chain.tsv" |
| 331 | t torn-seen 3 $I verify "$R" demo |
| 332 | t torn-not-cut-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2" |
| 333 | t torn-still-there 0 grep -q garbage "$P/chain.tsv" |
| 334 | t torn-cut-for-owner 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key" |
| 335 | t torn-gone 0 test "$(lines)" = "$(wc -l < "$T/done/chain.tsv")" -a -z "$(grep garbage "$P/chain.tsv")" |
| 336 | # an init that created the chain file and wrote nothing starts over |
| 337 | mkdir -p "$R/projects/e"; git init -q --bare "$R/projects/e/repo.git"; : > "$R/projects/e/chain.tsv" |
| 338 | t empty-chain-init 0 $I init "$R" e main public - "$T/key"; rm -rf "$R/projects/e" |
| 339 | # a staged payload is put in place only for the owner |
| 340 | redo; n=$(lines); mkdir -p "$P/staging"; mv "$P/records/$((n - 1))" "$P/staging/x" |
| 341 | t staged-not-restored-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2" |
| 342 | t staged-still-staged 0 test ! -e "$P/records/$((n - 1))" |
| 343 | # the original import request, repeated after later landings, answers and adds nothing |
| 344 | redo; n=$(lines) |
| 345 | t import-replay-after-landings 0 $I import "$R" demo main "$T/ev" "$T/note" import-1 "$T/key" |
| 346 | t import-replay-added-nothing 0 test "$(lines)" = "$n" -a "$(ref main)" = "$C4" |
| 347 | # the project id is the digest of the signed record 1 payload |
| 348 | t id-is-payload-digest 0 test "$($I verify "$R" demo | cut -d' ' -f3)" = "$(sha256sum < "$P/records/1" | cut -c1-64)" |
| 349 | # git settings in the caller's environment do not reach the store |
| 350 | GIT_DIR=/nonexistent GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.bare GIT_CONFIG_VALUE_0=nonsense GIT_WORK_TREE=/nonexistent t env-not-inherited 0 $I verify "$R" demo |
| 351 | # a project whose repository is a link is no project, for verify and for the catalog alike |
| 352 | mkdir -p "$R/projects/lnk"; ln -s "$P/repo.git" "$R/projects/lnk/repo.git" |
| 353 | t no-linked-repository 2 $I verify "$R" lnk |
| 354 | $I catalog "$R" > /dev/null 2> "$T/caterr"; t catalog-leaves-out-linked 0 grep -q "lnk is not a project" "$T/caterr"; rm -rf "$R/projects/lnk" |
| 355 | # a linked project folder is left out, and nothing behind the link is touched |
| 356 | mkdir -p "$T/elsewhere"; echo keep > "$T/elsewhere/catalog.row"; ln -s "$T/elsewhere" "$R/projects/away" |
| 357 | $I catalog "$R" > /dev/null 2>&1; t linked-folder-untouched 0 test "$(cat "$T/elsewhere/catalog.row")" = keep; rm "$R/projects/away" |
| 358 | redo |
| 359 | # two catalog runs at once: one whole catalog, no leftovers |
| 360 | ( $I catalog "$R" >/dev/null 2>&1 ) & ( $I catalog "$R" >/dev/null 2>&1 ) & wait |
| 361 | cp "$R/catalog.tsv" "$T/err.cat"; t catalog-race-whole 0 test "$(wc -l < "$R/catalog.tsv")" = 2 -a -z "$(ls "$R" | grep 'catalog.tsv\.')" |
| 362 | [ "$(wc -l < "$R/catalog.tsv")" = 2 ] || { echo "catalog was:"; cut -f1,4 "$R/catalog.tsv"; ls "$R" "$R/projects"; } |
| 363 | rm -rf "$R/projects/rsaproj" "$R/projects/half"; t catalog 0 $I catalog "$R" |
| 364 | t catalog-row 0 grep -q "^demo [0-9a-f]\{64\} main $C4 public$" "$R/catalog.tsv" |
| 365 | echo x >> "$P/records/1"; t catalog-leaves-out-broken 3 $I catalog "$R"; t catalog-empty 0 test ! -s "$R/catalog.tsv" |
| 366 | # ---- owner-key handover. Throwaway ed25519 keys in this temp store only; never ~/.ssh, never the live store. |
| 367 | HR=$T/hroot; HP=$HR/projects/demo; mkdir -p "$HP" |
| 368 | ssh-keygen -q -t ed25519 -N "" -C ho0 -f "$T/h0" |
| 369 | ssh-keygen -q -t ed25519 -N "" -C ho1 -f "$T/h1" |
| 370 | ssh-keygen -q -t ed25519 -N "" -C ho2 -f "$T/h2" |
| 371 | FP0=$(ssh-keygen -lf "$T/h0.pub" | awk '{print $2}') |
| 372 | FP1=$(ssh-keygen -lf "$T/h1.pub" | awk '{print $2}') |
| 373 | FP2=$(ssh-keygen -lf "$T/h2.pub" | awk '{print $2}') |
| 374 | BLOB0=$(awk '{print $2}' "$T/h0.pub") |
| 375 | BLOB2=$(awk '{print $2}' "$T/h2.pub") |
| 376 | write_pin() { printf '* %s\n' "$1" > "$T/owner-pins"; chmod 600 "$T/owner-pins"; } |
| 377 | write_pin "$FP0" |
| 378 | git init -q --bare "$HP/repo.git" |
| 379 | git --git-dir="$HP/repo.git" fetch -q "$T/work" "$C1" |
| 380 | git --git-dir="$HP/repo.git" update-ref refs/heads/main "$C1" |
| 381 | t ho-init 0 $I init "$HR" demo main public - "$T/h0" |
| 382 | t ho-import 0 $I import "$HR" demo main "$T/ev" "$T/note" h-import-1 "$T/h0" |
| 383 | t ho-land-before 0 $I land "$HR" demo main "$C2" "$T/work" "$T/rc" "$T/vd" h-req-1 "$T/h0" |
| 384 | n=$(wc -l < "$HP/chain.tsv") |
| 385 | t ho-pre-history-verifies 0 $I verify "$HR" demo |
| 386 | t ho-legacy-no-successor 0 test "$(grep -c $'\tSUCCESSOR\t' "$HP/chain.tsv" || true)" = 0 |
| 387 | own0=$(sha256sum < "$HP/owner.pub" | cut -c1-64) |
| 388 | mkdir -p "$T/legacy-root/projects" |
| 389 | cp -a "$HP" "$T/legacy-root/projects/demo" |
| 390 | t ho-legacy-copy-still-verifies 0 $I verify "$T/legacy-root" demo |
| 391 | t ho-handover 0 $I handover "$HR" demo "$T/h0" "$T/h1.pub" rotate-1 |
| 392 | cp "$T/err" "$T/err.handover" |
| 393 | t ho-pin-line-printed 0 grep -q "ipl: pin: demo $FP1" "$T/err.handover" |
| 394 | t ho-pin-file-updated 0 grep -q "$FP1" "$T/owner-pins" |
| 395 | t ho-adds-two-records 0 test "$(wc -l < "$HP/chain.tsv")" = "$((n + 2))" |
| 396 | t ho-owner-pub-unchanged 0 test "$(sha256sum < "$HP/owner.pub" | cut -c1-64)" = "$own0" |
| 397 | t ho-verify-after 0 $I verify "$HR" demo |
| 398 | $I verify "$HR" demo > "$T/ok" |
| 399 | t ho-ok-current-owner 0 test "$(awk '{print $7}' "$T/ok")" = "$FP1" |
| 400 | t ho-ok-chain-seq 0 test "$(awk '{print $8}' "$T/ok")" = "$(wc -l < "$HP/chain.tsv")" |
| 401 | t ho-ok-chain-head 0 test "$(awk '{print $9}' "$T/ok")" = "$(tail -n 1 "$HP/chain.tsv" | tr -d '\n' | sha256sum | cut -c1-64)" |
| 402 | t ho-expect-new 0 $I verify "$HR" demo --expect-owner "$FP1" |
| 403 | t ho-expect-old-fails 3 $I verify --expect-owner "$FP0" "$HR" demo |
| 404 | printf '* %s\n' "$FP0" > "$T/pin-old"; chmod 600 "$T/pin-old" |
| 405 | IPL_OWNER_PINS="$T/pin-old" t ho-legacy-with-old-pin 0 $I verify "$T/legacy-root" demo |
| 406 | nleg=$(wc -l < "$T/legacy-root/projects/demo/chain.tsv") |
| 407 | t ho-fork-expect-new-fails 3 $I verify "$T/legacy-root" demo --expect-owner "$FP1" |
| 408 | t ho-fork-land-expect-fails 3 $I land "$T/legacy-root" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-fork-1 "$T/h0" --expect-owner "$FP1" |
| 409 | t ho-fork-land-expect-adds-nothing 0 test "$(wc -l < "$T/legacy-root/projects/demo/chain.tsv")" = "$nleg" |
| 410 | # required: a pin file (successor FP) catches a pre-handover fork and an attacker re-hand, without --expect-owner |
| 411 | t ho-fork-pin-verify 3 $I verify "$T/legacy-root" demo |
| 412 | t ho-fork-pin-catalog 3 $I catalog "$T/legacy-root" |
| 413 | cp -a "$T/legacy-root" "$T/rehand-root" |
| 414 | printf '* %s\n' "$FP0" > "$T/attacker-pins"; chmod 600 "$T/attacker-pins" |
| 415 | IPL_OWNER_PINS="$T/attacker-pins" t ho-attacker-rehand 0 $I handover "$T/rehand-root" demo "$T/h0" "$T/h2.pub" attack |
| 416 | t ho-rehand-fork-pin-verify 3 $I verify "$T/rehand-root" demo |
| 417 | t ho-rehand-fork-pin-catalog 3 $I catalog "$T/rehand-root" |
| 418 | # pin file inside ROOT, group-writable, missing, and a disagreeing --expect-owner |
| 419 | printf '* %s\n' "$FP1" > "$HR/owner-pins"; chmod 600 "$HR/owner-pins" |
| 420 | IPL_OWNER_PINS="$HR/owner-pins" t ho-pin-inside-root 3 $I verify "$HR" demo |
| 421 | rm -f "$HR/owner-pins" |
| 422 | printf '* %s\n' "$FP1" > "$T/pin-gw"; chmod 660 "$T/pin-gw" |
| 423 | IPL_OWNER_PINS="$T/pin-gw" t ho-pin-group-writable 3 $I verify "$HR" demo |
| 424 | IPL_OWNER_PINS="$T/no-such-pins" t ho-pin-missing 3 $I verify "$HR" demo |
| 425 | t ho-pin-disagree 3 $I verify "$HR" demo --expect-owner "$FP0" |
| 426 | # catalog drops a project whose current owner is not the pin |
| 427 | write_pin "$FP1" |
| 428 | CR=$T/catpin |
| 429 | for spec in "p-ok:$T/h1" "p-bad:$T/h0"; do |
| 430 | name=${spec%%:*}; key=${spec#*:} |
| 431 | mkdir -p "$CR/projects/$name" |
| 432 | git init -q --bare "$CR/projects/$name/repo.git" |
| 433 | git --git-dir="$CR/projects/$name/repo.git" fetch -q "$T/work" "$C1" |
| 434 | git --git-dir="$CR/projects/$name/repo.git" update-ref refs/heads/main "$C1" |
| 435 | $I init "$CR" "$name" main public - "$key" >/dev/null |
| 436 | done |
| 437 | t ho-catalog-drops-mismatch 3 $I catalog "$CR" |
| 438 | cp "$T/err" "$T/err.catpin" |
| 439 | t ho-catalog-drops-mismatch-reason 0 grep -q "p-bad: current owner is $FP0, not $FP1" "$T/err.catpin" |
| 440 | t ho-catalog-keeps-pinned 0 grep -q "^p-ok " "$CR/catalog.tsv" |
| 441 | t ho-catalog-omits-mismatch 0 test "$(grep -c "^p-bad" "$CR/catalog.tsv" || true)" = 0 |
| 442 | mkdir -p "$T/ipltmp" |
| 443 | TMPDIR="$T/ipltmp" $I verify "$HR" demo >/dev/null |
| 444 | t ho-verify-cleans-temp 0 test -z "$(ls -A "$T/ipltmp")" |
| 445 | n=$(wc -l < "$HP/chain.tsv") |
| 446 | t ho-idempotent 0 $I handover "$HR" demo "$T/h0" "$T/h1.pub" rotate-1 |
| 447 | t ho-idempotent-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n" |
| 448 | cp -a "$HP" "$T/ho-after1" |
| 449 | t ho-new-key-land 0 $I land "$HR" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-req-2 "$T/h1" --expect-owner "$FP1" |
| 450 | t ho-new-key-land-verifies 0 $I verify "$HR" demo |
| 451 | n=$(wc -l < "$HP/chain.tsv") |
| 452 | t ho-land-expect-old-fails 3 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-expect "$T/h1" --expect-owner "$FP0" |
| 453 | t ho-land-expect-old-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n" |
| 454 | n=$(wc -l < "$HP/chain.tsv") |
| 455 | t ho-old-key-land-rejected 2 $I land "$HR" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-req-3 "$T/h0" |
| 456 | t ho-old-key-land-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n" |
| 457 | # swapping owner.pub to the successor key must still fail: owner.pub is the key record 1 names |
| 458 | cp "$T/h1.pub" "$HP/owner.pub" |
| 459 | t ho-tamper-owner-to-successor 3 $I verify "$HR" demo |
| 460 | cp "$T/ho-after1/owner.pub" "$HP/owner.pub" |
| 461 | t ho-owner-restored-after-tamper 0 $I verify "$HR" demo |
| 462 | # a forged SUCCESSOR not signed by the current key fails verify (actor is the attacker) |
| 463 | rm -rf "$HP"; cp -a "$T/ho-after1" "$HP" |
| 464 | "$L" successor demo "$FP1" "$FP2" "$BLOB2" forged > "$T/hpay" |
| 465 | head -n "$(wc -l < "$HP/chain.tsv")" "$HP/chain.tsv" > "$T/hchain.bak" |
| 466 | "$T/chain" add "$HP/chain.tsv" SUCCESSOR "$FP2" "$FP2" < "$T/hpay" >/dev/null |
| 467 | hs=$(wc -l < "$HP/chain.tsv") |
| 468 | cp "$T/hpay" "$HP/records/$hs" |
| 469 | awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/hmsg" |
| 470 | ssh-keygen -q -Y sign -n interplane -f "$T/h2" "$T/hmsg" 2>/dev/null |
| 471 | "$T/chain" add "$HP/chain.tsv" SIG "$FP2" "$hs" < "$T/hmsg.sig" >/dev/null |
| 472 | cp "$T/hmsg.sig" "$HP/records/$((hs + 1))" |
| 473 | t ho-forged-handover-fails 3 $I verify "$HR" demo |
| 474 | # P1: a SUCCESSOR whose actor is the current key, but whose SIG is by another key, must fail on the signature |
| 475 | rm -rf "$HP"; cp -a "$T/ho-after1" "$HP" |
| 476 | "$L" successor demo "$FP1" "$FP2" "$BLOB2" forged-sig > "$T/hpay2" |
| 477 | "$T/chain" add "$HP/chain.tsv" SUCCESSOR "$FP1" "$FP2" < "$T/hpay2" >/dev/null |
| 478 | hs=$(wc -l < "$HP/chain.tsv") |
| 479 | cp "$T/hpay2" "$HP/records/$hs" |
| 480 | awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/hmsg2" |
| 481 | ssh-keygen -q -Y sign -n interplane -f "$T/h2" "$T/hmsg2" 2>/dev/null |
| 482 | "$T/chain" add "$HP/chain.tsv" SIG "$FP1" "$hs" < "$T/hmsg2.sig" >/dev/null |
| 483 | cp "$T/hmsg2.sig" "$HP/records/$((hs + 1))" |
| 484 | t ho-forged-successor-bad-sig 3 $I verify "$HR" demo |
| 485 | cp "$T/err" "$T/err.forgedsig" |
| 486 | t ho-forged-successor-bad-sig-reason 0 grep -q "does not verify" "$T/err.forgedsig" |
| 487 | # an old-key LAND after a real handover, even if well-formed and signed by the old key, fails verify |
| 488 | rm -rf "$HP"; cp -a "$T/ho-after1" "$HP" |
| 489 | rd=$(sha256sum < "$T/rc" | cut -c1-64); vd=$(sha256sum < "$T/vd" | cut -c1-64) |
| 490 | "$L" land demo main "$C2" "$C4" "$rd" "$vd" forged-land > "$T/lpay" |
| 491 | "$T/chain" add "$HP/chain.tsv" LAND "$FP0" main < "$T/lpay" >/dev/null |
| 492 | hs=$(wc -l < "$HP/chain.tsv") |
| 493 | cp "$T/lpay" "$HP/records/$hs" |
| 494 | awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/lmsg" |
| 495 | ssh-keygen -q -Y sign -n interplane -f "$T/h0" "$T/lmsg" 2>/dev/null |
| 496 | "$T/chain" add "$HP/chain.tsv" SIG "$FP0" "$hs" < "$T/lmsg.sig" >/dev/null |
| 497 | cp "$T/lmsg.sig" "$HP/records/$((hs + 1))" |
| 498 | # the branch also needs to move for a would-be-honest land; either way it must fail |
| 499 | git --git-dir="$HP/repo.git" fetch -q "$T/work" "$C4" |
| 500 | git --git-dir="$HP/repo.git" update-ref refs/heads/main "$C4" |
| 501 | t ho-forged-old-key-land-after-fails 3 $I verify "$HR" demo |
| 502 | # two sequential handovers |
| 503 | rm -rf "$HP"; cp -a "$T/ho-after1" "$HP" |
| 504 | t ho-second-handover 0 $I handover "$HR" demo "$T/h1" "$T/h2.pub" rotate-2 |
| 505 | t ho-second-verifies 0 $I verify "$HR" demo |
| 506 | t ho-third-key-land 0 $I land "$HR" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-req-4 "$T/h2" |
| 507 | t ho-third-key-land-verifies 0 $I verify "$HR" demo |
| 508 | n=$(wc -l < "$HP/chain.tsv") |
| 509 | t ho-first-key-after-two-rejected 2 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-5 "$T/h0" |
| 510 | t ho-second-key-after-two-rejected 2 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-6 "$T/h1" |
| 511 | t ho-retired-keys-add-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n" |
| 512 | t ho-third-key-lands-on 0 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-5 "$T/h2" |
| 513 | t ho-after-two-verifies 0 $I verify "$HR" demo |
| 514 | # --all: two projects, one call |
| 515 | AR=$T/allroot |
| 516 | for name in p1 p2; do |
| 517 | mkdir -p "$AR/projects/$name" |
| 518 | git init -q --bare "$AR/projects/$name/repo.git" |
| 519 | git --git-dir="$AR/projects/$name/repo.git" fetch -q "$T/work" "$C1" |
| 520 | git --git-dir="$AR/projects/$name/repo.git" update-ref refs/heads/main "$C1" |
| 521 | $I init "$AR" "$name" main public - "$T/h0" >/dev/null |
| 522 | done |
| 523 | write_pin "$FP0" |
| 524 | t ho-all 0 $I handover "$AR" --all "$T/h0" "$T/h1.pub" rotate-all |
| 525 | t ho-all-pin-updated 0 grep -q "$FP1" "$T/owner-pins" |
| 526 | t ho-all-p1-verifies 0 $I verify "$AR" p1 |
| 527 | t ho-all-p2-verifies 0 $I verify "$AR" p2 |
| 528 | t ho-all-p1-has-successor 0 grep -q $'\tSUCCESSOR\t' "$AR/projects/p1/chain.tsv" |
| 529 | t ho-all-p2-has-successor 0 grep -q $'\tSUCCESSOR\t' "$AR/projects/p2/chain.tsv" |
| 530 | t ho-all-idempotent 0 $I handover "$AR" --all "$T/h0" "$T/h1.pub" rotate-all |
| 531 | # a5: single-project handovers leave NAME lines; --all must rewrite them, not leave them stale |
| 532 | A5=$T/a5root |
| 533 | for name in demo other; do |
| 534 | mkdir -p "$A5/projects/$name" |
| 535 | git init -q --bare "$A5/projects/$name/repo.git" |
| 536 | git --git-dir="$A5/projects/$name/repo.git" fetch -q "$T/work" "$C1" |
| 537 | git --git-dir="$A5/projects/$name/repo.git" update-ref refs/heads/main "$C1" |
| 538 | $I init "$A5" "$name" main public - "$T/h0" >/dev/null |
| 539 | done |
| 540 | write_pin "$FP0" |
| 541 | t ho-a5-single-demo 0 $I handover "$A5" demo "$T/h0" "$T/h1.pub" a5-demo |
| 542 | t ho-a5-single-other 0 $I handover "$A5" other "$T/h0" "$T/h1.pub" a5-other |
| 543 | cp -a "$A5" "$T/a5-at-h1" |
| 544 | t ho-a5-all 0 $I handover "$A5" --all "$T/h1" "$T/h2.pub" a5-all |
| 545 | t ho-a5-pin-demo 0 grep -q "^demo $FP2$" "$T/owner-pins" |
| 546 | t ho-a5-pin-other 0 grep -q "^other $FP2$" "$T/owner-pins" |
| 547 | t ho-a5-pin-no-stale-demo 0 test "$(grep -c "^demo $FP1$" "$T/owner-pins" || true)" = 0 |
| 548 | t ho-a5-pin-no-stale-other 0 test "$(grep -c "^other $FP1$" "$T/owner-pins" || true)" = 0 |
| 549 | t ho-a5-demo-verifies 0 $I verify "$A5" demo |
| 550 | t ho-a5-other-verifies 0 $I verify "$A5" other |
| 551 | t ho-a5-catalog 0 $I catalog "$A5" |
| 552 | t ho-a5-catalog-rows 0 test "$(wc -l < "$A5/catalog.tsv")" = 2 |
| 553 | t ho-a5-frozen-h1-verify 3 $I verify "$T/a5-at-h1" demo |
| 554 | t ho-a5-frozen-h1-other 3 $I verify "$T/a5-at-h1" other |
| 555 | t ho-a5-frozen-h1-catalog 3 $I catalog "$T/a5-at-h1" |
| 556 | # a3: a pre-existing per-name line that matches * must be rewritten by --all, not left at the old key |
| 557 | A3=$T/a3root |
| 558 | for name in a1 c3; do |
| 559 | mkdir -p "$A3/projects/$name" |
| 560 | git init -q --bare "$A3/projects/$name/repo.git" |
| 561 | git --git-dir="$A3/projects/$name/repo.git" fetch -q "$T/work" "$C1" |
| 562 | git --git-dir="$A3/projects/$name/repo.git" update-ref refs/heads/main "$C1" |
| 563 | $I init "$A3" "$name" main public - "$T/h0" >/dev/null |
| 564 | done |
| 565 | printf '* %s\n' "$FP0" > "$T/owner-pins" |
| 566 | printf 'c3 %s\n' "$FP0" >> "$T/owner-pins" |
| 567 | chmod 600 "$T/owner-pins" |
| 568 | t ho-a3-all 0 $I handover "$A3" --all "$T/h0" "$T/h1.pub" a3-all |
| 569 | t ho-a3-c3-rewritten 0 grep -q "^c3 $FP1$" "$T/owner-pins" |
| 570 | t ho-a3-c3-not-stale 0 test "$(grep -c "^c3 $FP0$" "$T/owner-pins" || true)" = 0 |
| 571 | t ho-a3-star-rewritten 0 grep -q "^\* $FP1$" "$T/owner-pins" |
| 572 | t ho-a3-c3-verifies 0 $I verify "$A3" c3 |
| 573 | t ho-a3-a1-verifies 0 $I verify "$A3" a1 |
| 574 | t ho-a3-catalog 0 $I catalog "$A3" |
| 575 | t ho-a3-catalog-rows 0 test "$(wc -l < "$A3/catalog.tsv")" = 2 |
| 576 | # --all preflight is all-or-nothing: a mixed-owner store writes nothing |
| 577 | MR=$T/mixroot |
| 578 | for spec in "a1:$T/h0" "b2:$T/h2" "c3:$T/h0"; do |
| 579 | name=${spec%%:*}; key=${spec#*:} |
| 580 | mkdir -p "$MR/projects/$name" |
| 581 | git init -q --bare "$MR/projects/$name/repo.git" |
| 582 | git --git-dir="$MR/projects/$name/repo.git" fetch -q "$T/work" "$C1" |
| 583 | git --git-dir="$MR/projects/$name/repo.git" update-ref refs/heads/main "$C1" |
| 584 | $I init "$MR" "$name" main public - "$key" >/dev/null |
| 585 | done |
| 586 | na1=$(wc -l < "$MR/projects/a1/chain.tsv"); nb2=$(wc -l < "$MR/projects/b2/chain.tsv"); nc3=$(wc -l < "$MR/projects/c3/chain.tsv") |
| 587 | write_pin "$FP0" |
| 588 | t ho-all-preflight-mixed 2 $I handover "$MR" --all "$T/h0" "$T/h1.pub" rotate-mix |
| 589 | cp "$T/err" "$T/err.preflight" |
| 590 | t ho-all-preflight-announced 0 grep -q "preflight failed; nothing was recorded" "$T/err.preflight" |
| 591 | t ho-all-preflight-names-b2 0 grep -q "b2: current owner is $FP2, not $FP0" "$T/err.preflight" |
| 592 | t ho-all-preflight-a1-untouched 0 test "$(wc -l < "$MR/projects/a1/chain.tsv")" = "$na1" -a "$(grep -c $'\tSUCCESSOR\t' "$MR/projects/a1/chain.tsv" || true)" = 0 |
| 593 | t ho-all-preflight-b2-untouched 0 test "$(wc -l < "$MR/projects/b2/chain.tsv")" = "$nb2" |
| 594 | t ho-all-preflight-c3-untouched 0 test "$(wc -l < "$MR/projects/c3/chain.tsv")" = "$nc3" -a "$(grep -c $'\tSUCCESSOR\t' "$MR/projects/c3/chain.tsv" || true)" = 0 |
| 595 | # a retired key cannot become the owner again |
| 596 | rm -rf "$HP"; cp -a "$T/ho-after1" "$HP" |
| 597 | write_pin "$FP1" |
| 598 | n=$(wc -l < "$HP/chain.tsv") |
| 599 | t ho-refuse-prior-owner 2 $I handover "$HR" demo "$T/h1" "$T/h0.pub" rotate-back |
| 600 | cp "$T/err" "$T/err.prior" |
| 601 | t ho-refuse-prior-owner-reason 0 grep -q "already an owner" "$T/err.prior" |
| 602 | t ho-refuse-prior-owner-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n" |
| 603 | # a crafted h0->h1->h0 chain, even honestly signed by h1, does not verify |
| 604 | "$L" successor demo "$FP1" "$FP0" "$BLOB0" rotate-back > "$T/hback" |
| 605 | "$T/chain" add "$HP/chain.tsv" SUCCESSOR "$FP1" "$FP0" < "$T/hback" >/dev/null |
| 606 | hs=$(wc -l < "$HP/chain.tsv") |
| 607 | cp "$T/hback" "$HP/records/$hs" |
| 608 | awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/hbackmsg" |
| 609 | ssh-keygen -q -Y sign -n interplane -f "$T/h1" "$T/hbackmsg" 2>/dev/null |
| 610 | "$T/chain" add "$HP/chain.tsv" SIG "$FP1" "$hs" < "$T/hbackmsg.sig" >/dev/null |
| 611 | cp "$T/hbackmsg.sig" "$HP/records/$((hs + 1))" |
| 612 | t ho-verify-refuses-returned-owner 3 $I verify "$HR" demo |
| 613 | cp "$T/err" "$T/err.back" |
| 614 | t ho-verify-refuses-returned-owner-reason 0 grep -q "already an owner" "$T/err.back" |
| 615 | # interrupted handover at each write point is finished by the same keys; after-sig no-op clears staging |
| 616 | for s in after-stage mid-record after-record after-sig; do |
| 617 | rm -rf "$HP"; cp -a "$T/ho-after1" "$HP" |
| 618 | write_pin "$FP1" |
| 619 | n=$(wc -l < "$HP/chain.tsv") |
| 620 | IPL_TEST_STOP=$s t "ho-stop-$s" 9 $I handover "$HR" demo "$T/h1" "$T/h2.pub" rotate-stop |
| 621 | n1=$(wc -l < "$HP/chain.tsv") |
| 622 | if [ "$s" = after-stage ]; then |
| 623 | t "ho-stop-$s-nothing-recorded" 0 $I verify "$HR" demo |
| 624 | t "ho-stop-$s-lines" 0 test "$n1" = "$n" |
| 625 | elif [ "$s" = after-sig ]; then |
| 626 | t "ho-stop-$s-verifies" 0 $I verify "$HR" demo |
| 627 | t "ho-stop-$s-lines" 0 test "$n1" = "$((n + 2))" |
| 628 | else |
| 629 | t "ho-stop-$s-seen" 3 $I verify "$HR" demo |
| 630 | t "ho-stop-$s-lines" 0 test "$n1" = "$((n + 1))" |
| 631 | fi |
| 632 | if [ "$s" = after-record ]; then |
| 633 | t ho-stop-not-other-key 2 $I handover "$HR" demo "$T/h0" "$T/h2.pub" rotate-stop |
| 634 | fi |
| 635 | t "ho-stop-$s-finished" 0 $I handover "$HR" demo "$T/h1" "$T/h2.pub" rotate-stop |
| 636 | t "ho-stop-$s-result" 0 test "$(wc -l < "$HP/chain.tsv")" = "$((n + 2))" -a -z "$(ls "$HP/staging" 2>/dev/null)" |
| 637 | t "ho-stop-$s-final-verifies" 0 $I verify "$HR" demo |
| 638 | done |
| 639 | |
| 640 | echo "tools: $(git --version), $(ssh -V 2>&1), $(bash --version | head -1), $(sha256sum --version | head -1), $(flock --version), $(awk -W version 2>&1 | head -1), $(sed --version | head -1), $(cmp --version | head -1), $(getconf --version | head -1)" |
| 641 | if [ "$fail" = 0 ]; then echo "GATE PASS cases=$pass"; else echo "GATE FAIL pass=$pass fail=$fail"; exit 1; fi |