interplane.io
Source of interplane.io: a Rust generator that renders the page from the protocol repository's public record, deployed hourly from the Spark.
Brought by drakestapleton
interplane.io / content / receipts-page / verify.sh
| 1 | #!/bin/sh |
| 2 | # verify.sh: walk the whole Interplane receipts list and print its head. |
| 3 | # |
| 4 | # sh verify.sh checks https://interplane.io/receipts |
| 5 | # sh verify.sh ADDRESS checks a copy served somewhere else |
| 6 | # |
| 7 | # It fetches the list, starts at record 1, and for each record checks three |
| 8 | # things: its number, that it carries the fingerprint (SHA-256) of the record |
| 9 | # before it, and that its evidence file has the fingerprint the record names. |
| 10 | # It stops at the first record that fails, and it fails when the list does |
| 11 | # not end with a line feed, so a cut-off last record is not skipped. It |
| 12 | # needs curl, cut, tail and either sha256sum or shasum. It writes only to a temporary folder, which it removes. |
| 13 | # |
| 14 | # A head that matches the page shows the list and the page agree. To know the |
| 15 | # list was not replaced after publication, compare the head with one you saved |
| 16 | # earlier, or with content/receipts/head.txt in the site's source. |
| 17 | # Plain Git does not check a signature; a head saved earlier is the stronger comparison. |
| 18 | set -eu |
| 19 | BASE=${1:-https://interplane.io/receipts} |
| 20 | if command -v sha256sum >/dev/null 2>&1; then |
| 21 | sum() { sha256sum | cut -d' ' -f1; } |
| 22 | else |
| 23 | sum() { shasum -a 256 | cut -d' ' -f1; } |
| 24 | fi |
| 25 | fail() { |
| 26 | if [ "$n" -gt 0 ]; then echo "FAIL record $n: $1"; else echo "FAIL: $1"; fi |
| 27 | exit 1 |
| 28 | } |
| 29 | T=$(mktemp -d) |
| 30 | trap 'rm -rf "$T"' 0 |
| 31 | n=0 |
| 32 | curl -fsS "$BASE/ledger.tsv" -o "$T/ledger.tsv" || fail 'the list could not be fetched' |
| 33 | [ -s "$T/ledger.tsv" ] || fail 'the list is empty' |
| 34 | [ -z "$(tail -c 1 "$T/ledger.tsv")" ] || fail 'the list does not end with a line feed' |
| 35 | prev=GENESIS |
| 36 | while IFS= read -r line; do |
| 37 | n=$((n + 1)) |
| 38 | seq=$(printf '%s' "$line" | cut -f1) |
| 39 | payload=$(printf '%s' "$line" | cut -f6) |
| 40 | link=$(printf '%s' "$line" | cut -f7) |
| 41 | [ "$seq" = "$n" ] || fail "its number is $seq" |
| 42 | [ "$link" = "$prev" ] || fail 'it does not carry the fingerprint of the record before it' |
| 43 | case $payload in *[!0-9a-f]*) fail 'its evidence name is not a fingerprint' ;; esac |
| 44 | [ "${#payload}" -eq 64 ] || fail 'its evidence name is not a fingerprint' |
| 45 | curl -fsS "$BASE/payload/$payload.txt" -o "$T/evidence" || fail 'its evidence file could not be fetched' |
| 46 | [ "$(sum < "$T/evidence")" = "$payload" ] || fail 'its evidence file does not match its fingerprint' |
| 47 | prev=$(printf '%s' "$line" | sum) |
| 48 | done < "$T/ledger.tsv" |
| 49 | [ "$n" -gt 0 ] || fail 'the list is empty' |
| 50 | echo "records $n" |
| 51 | echo "head $prev" |