AtlatestRepositorycore-channel
core-channel / tree / scriptsgate-hash-verify.sh
1
#!/bin/sh2
set -eu4
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)5
scratch=$(mktemp -d /tmp/sigil-channel-hash.XXXXXX)6
trap 'rm -rf "$scratch"' EXIT HUP INT TERM7
git clone --quiet --no-hardlinks "$repo" "$scratch/channel"9
manifest="$scratch/channel/seed/MANIFEST"10
awk 'BEGIN { changed=0 }11
/^#/ || NF == 0 { print; next }12
changed == 0 { sub(/^./, "0"); changed=1 }13
{ print }14
' "$manifest" > "$manifest.tampered"15
mv "$manifest.tampered" "$manifest"17
set +e18
SIGIL_BOOTSTRAP_SEED_URL="${SIGIL_BOOTSTRAP_SEED_URL:?set SIGIL_BOOTSTRAP_SEED_URL to the seed archive}" \19
SIGIL_BOOTSTRAP_ZIG_URL="${SIGIL_BOOTSTRAP_ZIG_URL:-}" \20
"$scratch/channel/bootstrap" >"$scratch/out" 2>&121
status=$?22
set -e23
[ "$status" -ne 0 ] || { echo "hash gate: bootstrap accepted a tampered hash" >&2; exit 1; }24
grep -q 'REFUSING.*sha256 mismatch' "$scratch/out"25
echo "hash gate: tampered manifest refused"