e2e: run evidence_seal and the local TSA through functions !6

merged merged by cmc on 2026-11-01 07:20 UTC · audit-labs/evidence-seal:e2e-quoting into main

1 file changed, +34 −34

Layout: unified · split

scripts/e2e.sh +34 −34
@@ -22,8 +22,8 @@ if [[ -x "$REPO/.venv/bin/python" ]]; then
2222else
2323 PY="$(command -v python3 || command -v python)"
2424fi
25ES="$PY -m evidence_seal"
26TSA="$PY $SCRIPT_DIR/_local_tsa.py"
25es() { "$PY" -m evidence_seal "$@"; }
26tsa() { "$PY" "$SCRIPT_DIR/_local_tsa.py" "$@"; }
2727
2828W="$(mktemp -d)"
2929trap 'rm -rf "$W"' EXIT
@@ -45,7 +45,7 @@ assert_exit() {
4545}
4646
4747step "0. Version + command surface"
48run "$ES --version"
48run "es --version"
4949
5050step "1. SEAL a realistic evidence package (with provenance metadata)"
5151mkdir -p "$W/pkg/logs"
@@ -54,23 +54,23 @@ printf 'repo,branch,protected\napp,main,true\n' > "$W/pkg/branch_protections.csv
5454printf 'GitHub Audit — acme\n' > "$W/pkg/summary.txt"
5555printf 'scratch\n' > "$W/pkg/logs/debug.tmp"
5656assert_exit 0 "seal writes a manifest" \
57 "$ES seal $W/pkg --out $W/m.json --ignore 'logs/*.tmp' --meta engagement=ACME-2026 --meta collector='Christian Cleberg'"
57 "es seal $W/pkg --out $W/m.json --ignore 'logs/*.tmp' --meta engagement=ACME-2026 --meta collector='Christian Cleberg'"
5858
5959step "2. VERIFY — intact package"
60assert_exit 0 "verify clean" "$ES verify $W/pkg --manifest $W/m.json"
60assert_exit 0 "verify clean" "es verify $W/pkg --manifest $W/m.json"
6161
6262step "3. TAMPER — modify a sealed file"
6363printf 'alice,true\nbob,flipped\n' >> "$W/pkg/iam_users.csv"
64assert_exit 1 "verify catches modification" "$ES verify $W/pkg --manifest $W/m.json"
64assert_exit 1 "verify catches modification" "es verify $W/pkg --manifest $W/m.json"
6565printf 'user,mfa_enabled\nalice,true\nbob,false\n' > "$W/pkg/iam_users.csv"
6666
6767step "4. TAMPER — added + removed files"
6868printf 'oops\n' > "$W/pkg/rogue.csv"; rm "$W/pkg/summary.txt"
69assert_exit 1 "verify catches add+remove" "$ES verify $W/pkg --manifest $W/m.json"
69assert_exit 1 "verify catches add+remove" "es verify $W/pkg --manifest $W/m.json"
7070rm "$W/pkg/rogue.csv"; printf 'GitHub Audit — acme\n' > "$W/pkg/summary.txt"
7171
7272step "5. IGNORE globs — excluded file never flags"
73assert_exit 0 "ignored file does not break verify" "$ES verify $W/pkg --manifest $W/m.json"
73assert_exit 0 "ignored file does not break verify" "es verify $W/pkg --manifest $W/m.json"
7474
7575step "6. MANIFEST TAMPER — edit a recorded hash in the manifest itself"
7676"$PY" - "$W/m.json" "$W/m_bad.json" <<'PY'
@@ -78,61 +78,61 @@ import json, sys
7878m = json.load(open(sys.argv[1])); m["files"][0]["sha256"] = "0" * 64
7979json.dump(m, open(sys.argv[2], "w"), indent=2, sort_keys=True)
8080PY
81assert_exit 1 "verify catches a doctored manifest" "$ES verify $W/pkg --manifest $W/m_bad.json"
81assert_exit 1 "verify catches a doctored manifest" "es verify $W/pkg --manifest $W/m_bad.json"
8282
8383step "7. CHAIN OF CUSTODY — three sequential seals link"
8484mkdir -p "$W/chain"
85printf 'v1\n' > "$W/pkg/state.csv"; $ES seal "$W/pkg" --out "$W/chain/jan.json" >/dev/null 2>&1
86printf 'v2\n' > "$W/pkg/state.csv"; $ES seal "$W/pkg" --out "$W/chain/feb.json" --prev "$W/chain/jan.json" >/dev/null 2>&1
87printf 'v3\n' > "$W/pkg/state.csv"; $ES seal "$W/pkg" --out "$W/chain/mar.json" --prev "$W/chain/feb.json" >/dev/null 2>&1
85printf 'v1\n' > "$W/pkg/state.csv"; es seal "$W/pkg" --out "$W/chain/jan.json" >/dev/null 2>&1
86printf 'v2\n' > "$W/pkg/state.csv"; es seal "$W/pkg" --out "$W/chain/feb.json" --prev "$W/chain/jan.json" >/dev/null 2>&1
87printf 'v3\n' > "$W/pkg/state.csv"; es seal "$W/pkg" --out "$W/chain/mar.json" --prev "$W/chain/feb.json" >/dev/null 2>&1
8888rm "$W/pkg/state.csv"
89assert_exit 0 "chain in order is intact" "$ES chain $W/chain/jan.json $W/chain/feb.json $W/chain/mar.json"
89assert_exit 0 "chain in order is intact" "es chain $W/chain/jan.json $W/chain/feb.json $W/chain/mar.json"
9090
9191step "8. CHAIN — reordered links are detected"
92assert_exit 1 "reordered chain is broken" "$ES chain $W/chain/mar.json $W/chain/jan.json $W/chain/feb.json"
92assert_exit 1 "reordered chain is broken" "es chain $W/chain/mar.json $W/chain/jan.json $W/chain/feb.json"
9393
9494step "9. CHAIN — a spliced-out link is detected"
95assert_exit 1 "missing middle seal is broken" "$ES chain $W/chain/jan.json $W/chain/mar.json"
95assert_exit 1 "missing middle seal is broken" "es chain $W/chain/jan.json $W/chain/mar.json"
9696
9797step "10. SIGNING — generate an ed25519 keypair"
98assert_exit 0 "keygen" "$ES keygen --private $W/acme.key --public $W/acme.pub"
98assert_exit 0 "keygen" "es keygen --private $W/acme.key --public $W/acme.pub"
9999
100100step "11. SIGN and VERIFY with the matching public key"
101assert_exit 0 "seal + sign" "$ES seal $W/pkg --out $W/signed.json --sign $W/acme.key"
102assert_exit 0 "verify requires correct signer" "$ES verify $W/pkg --manifest $W/signed.json --pubkey $W/acme.pub"
101assert_exit 0 "seal + sign" "es seal $W/pkg --out $W/signed.json --sign $W/acme.key"
102assert_exit 0 "verify requires correct signer" "es verify $W/pkg --manifest $W/signed.json --pubkey $W/acme.pub"
103103
104104step "12. SIGN — a wrong public key is rejected"
105$ES keygen --private "$W/other.key" --public "$W/other.pub" >/dev/null 2>&1
106assert_exit 1 "wrong signer rejected" "$ES verify $W/pkg --manifest $W/signed.json --pubkey $W/other.pub"
105es keygen --private "$W/other.key" --public "$W/other.pub" >/dev/null 2>&1
106assert_exit 1 "wrong signer rejected" "es verify $W/pkg --manifest $W/signed.json --pubkey $W/other.pub"
107107
108108step "13. TIMESTAMP — build an RFC 3161 request (.tsq)"
109assert_exit 0 "timestamp request" "$ES timestamp request $W/signed.json --out $W/req.tsq"
109assert_exit 0 "timestamp request" "es timestamp request $W/signed.json --out $W/req.tsq"
110110
111111step "14. TIMESTAMP — apply a TSA token and verify the binding"
112112MID=$("$PY" -c "import json;print(json.load(open('$W/signed.json'))['id'])")
113$TSA "$MID" "$W/tsa_ok" >/dev/null 2>&1
114assert_exit 0 "apply token" "$ES timestamp apply $W/signed.json --token $W/tsa_ok/resp.tsr --out $W/stamped.json"
115assert_exit 0 "verify timestamp binding" "$ES timestamp verify $W/stamped.json"
113tsa "$MID" "$W/tsa_ok" >/dev/null 2>&1
114assert_exit 0 "apply token" "es timestamp apply $W/signed.json --token $W/tsa_ok/resp.tsr --out $W/stamped.json"
115assert_exit 0 "verify timestamp binding" "es timestamp verify $W/stamped.json"
116116
117117step "15. TIMESTAMP — full CMS signature verification with --tsa-cert"
118assert_exit 0 "full TSA signature verify" "$ES timestamp verify $W/stamped.json --tsa-cert $W/tsa_ok/tsa.pem"
118assert_exit 0 "full TSA signature verify" "es timestamp verify $W/stamped.json --tsa-cert $W/tsa_ok/tsa.pem"
119119
120120step "16. TIMESTAMP — wrong TSA certificate is rejected"
121$TSA "$MID" "$W/tsa_wrong" >/dev/null 2>&1
122assert_exit 1 "wrong TSA cert rejected" "$ES timestamp verify $W/stamped.json --tsa-cert $W/tsa_wrong/tsa.pem"
121tsa "$MID" "$W/tsa_wrong" >/dev/null 2>&1
122assert_exit 1 "wrong TSA cert rejected" "es timestamp verify $W/stamped.json --tsa-cert $W/tsa_wrong/tsa.pem"
123123
124124step "17. TIMESTAMP — cert lacking the timeStamping EKU is rejected"
125$TSA "$MID" "$W/tsa_noeku" --no-eku >/dev/null 2>&1
126$ES timestamp apply "$W/signed.json" --token "$W/tsa_noeku/resp.tsr" --out "$W/stamped_noeku.json" >/dev/null 2>&1
127assert_exit 1 "cert without timeStamping EKU rejected" "$ES timestamp verify $W/stamped_noeku.json --tsa-cert $W/tsa_noeku/tsa.pem"
125tsa "$MID" "$W/tsa_noeku" --no-eku >/dev/null 2>&1
126es timestamp apply "$W/signed.json" --token "$W/tsa_noeku/resp.tsr" --out "$W/stamped_noeku.json" >/dev/null 2>&1
127assert_exit 1 "cert without timeStamping EKU rejected" "es timestamp verify $W/stamped_noeku.json --tsa-cert $W/tsa_noeku/tsa.pem"
128128
129129step "18. COMPOSITION — sealed + signed + timestamped, verified together"
130$ES seal "$W/pkg" --out "$W/full.json" --sign "$W/acme.key" --meta engagement=ACME-2026 >/dev/null 2>&1
130es seal "$W/pkg" --out "$W/full.json" --sign "$W/acme.key" --meta engagement=ACME-2026 >/dev/null 2>&1
131131FID=$("$PY" -c "import json;print(json.load(open('$W/full.json'))['id'])")
132$TSA "$FID" "$W/tsa_full" >/dev/null 2>&1
133$ES timestamp apply "$W/full.json" --token "$W/tsa_full/resp.tsr" >/dev/null 2>&1
132tsa "$FID" "$W/tsa_full" >/dev/null 2>&1
133es timestamp apply "$W/full.json" --token "$W/tsa_full/resp.tsr" >/dev/null 2>&1
134134assert_exit 0 "integrity + signature + timestamp all verify at once" \
135 "$ES verify $W/pkg --manifest $W/full.json --pubkey $W/acme.pub --tsa-cert $W/tsa_full/tsa.pem"
135 "es verify $W/pkg --manifest $W/full.json --pubkey $W/acme.pub --tsa-cert $W/tsa_full/tsa.pem"
136136
137137echo
138138printf '\033[1m════════════════════════════════════════════\033[0m\n'