#!/usr/bin/env python3 """Verify the Quorum-QaaS x KEYSTONE evidence bundle. Python 3.8+ and `cryptography`; no CAIN code. python3 verify_bundle.py https://clawx.click/evidence/quorum-qaas-keystone-2026-10-15/ python3 verify_bundle.py ./local-copy/ Checks: MANIFEST.json is signed by the CAIN-42 evidence-root key (pass --root-key to pin it; the published key is at /.well-known/cain-publisher-key.json); every file's SHA-256 matches the manifest; every receipt verifies with verify_qaas_receipt.py against the membership hash recorded in the report (pin it yourself from /api/v1/live-cluster/membership?cluster=cain-mr-02 with --pin), for exactly the KEYSTONE record hash it lists. """ import base64, hashlib, json, os, subprocess, sys, tempfile, urllib.request from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey def get(base, name): if base.startswith("http"): with urllib.request.urlopen(base.rstrip("/") + "/" + name, timeout=30) as r: return r.read() with open(os.path.join(base, name), "rb") as f: return f.read() def main(argv): base = argv[0] pin = argv[argv.index("--pin") + 1] if "--pin" in argv else None root_key = argv[argv.index("--root-key") + 1] if "--root-key" in argv else None ok = True def check(name, good, detail=""): nonlocal ok ok &= bool(good) print(f" [{'PASS' if good else 'FAIL'}] {name}" + (f" -- {detail}" if detail and not good else "")) man_raw = get(base, "MANIFEST.json") sig = json.loads(get(base, "MANIFEST.sig.json")) digest = hashlib.sha256(man_raw).hexdigest() check("manifest digest", digest == sig["manifest_sha256"]) key = root_key or sig["evidence_root_public_key_b64"] try: Ed25519PublicKey.from_public_bytes(base64.b64decode(key)).verify(base64.b64decode(sig["signature_b64"]), digest.encode()) check("manifest signed by the evidence-root key" + ("" if root_key else " (key NOT pinned: pass --root-key)"), True) except Exception as e: check("manifest signed by the evidence-root key", False, type(e).__name__) man = json.loads(man_raw) files = {} for name, want in sorted(man["files"].items()): files[name] = get(base, name) check(f"sha256 {name}", hashlib.sha256(files[name]).hexdigest() == want) report = json.loads(files["report.json"]) pin = pin or report["configuration_hash"] with tempfile.TemporaryDirectory() as d: for v in ("verify_qaas_receipt.py", "verify_pbft_qc_bundle.py"): open(os.path.join(d, v), "wb").write(files[v + ".txt"]) for row in report["results"]: name = "receipt-keystone-%04d.json" % row["sequence_in_keystone"] open(os.path.join(d, "r.json"), "wb").write(files[name]) r = subprocess.run([sys.executable, "-I", os.path.join(d, "verify_qaas_receipt.py"), os.path.join(d, "r.json"), "--pin", pin, "--digest", row["digest"]], capture_output=True, text=True) check(f"{name}: KEYSTONE record {row['digest'][:16]}... NOTARIZED", r.returncode == 0, r.stdout.strip()[-120:]) print("VERIFIED" if ok else "NOT VERIFIED") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))