#!/usr/bin/env python3 """Standalone verifier for a CAIN-42 live failover drill report. Imports no CAIN code. Needs Python 3.8+ and `cryptography`. python3 verify_drill_report.py live-primary-failover.json python3 verify_drill_report.py https://clawx.click/evidence/cluster-drills/live-primary-failover-2026-11-16.json Checks, from the file only: * the report hash and Ed25519 signature under the published evidence key; * every replica started in one view and ended in one view; * all replicas ended with the same view and the same application state hash; * the commit certificate taken during the failover verified with >= 3 signers; * the drill's own verdict fields say ok / converged / SAFE. It does not prove the machines were independent, and it is not a third-party audit. It proves the file was not altered after the run and that the recorded facts are internally consistent. """ from __future__ import annotations import base64 import hashlib import json import sys try: import urllib.request except ImportError: # pragma: no cover urllib = None SIG_FIELDS = ("report_sha256", "signature_b64", "signer_public_key_b64", "signature_domain") def main() -> int: if len(sys.argv) != 2: print(__doc__) return 2 src = sys.argv[1] raw = urllib.request.urlopen(src, timeout=30).read() if src.startswith(("http://", "https://")) \ else open(src, "rb").read() r = json.loads(raw) checks = [] def check(name, ok, detail=""): checks.append((name, bool(ok), detail)) sig = r.pop("signature_b64", None) pub_b64 = r.pop("signer_public_key_b64", None) stated = r.pop("report_sha256", None) r.pop("signature_domain", None) canon = json.dumps(r, sort_keys=True, separators=(",", ":")).encode() digest = hashlib.sha256(canon).hexdigest() check("report_sha256_matches", digest == stated, f"{digest[:16]}… vs {str(stated)[:16]}…") if sig and pub_b64: from cryptography.exceptions import InvalidSignature from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey try: Ed25519PublicKey.from_public_bytes(base64.b64decode(pub_b64)).verify( base64.b64decode(sig), digest.encode()) check("ed25519_signature_valid", True) except InvalidSignature: check("ed25519_signature_valid", False, "invalid signature") else: check("ed25519_signature_present", False, "unsigned report") after = r.get("after", {}) views = {v.get("view") for v in after.values()} hashes = {v.get("application_state_hash") for v in after.values()} check("all_replicas_end_in_one_view", len(views) == 1, str(sorted(views))) check("all_replicas_end_with_same_state", len(hashes) == 1, str(sorted(hashes))) start = r.get("start", {}) start_views = {v.get("view") for v in start.values()} check("all_replicas_start_in_one_view", len(start_views) == 1, str(sorted(start_views))) qc = r.get("commit_qc") or {} check("failover_commit_qc_verified", qc.get("verified") is True, f"sequence {qc.get('sequence')} signers {qc.get('signers')}") check("quorum_signers_at_least_3", len(qc.get("signers") or []) >= 3, str(len(qc.get("signers") or []))) check("report_verdict_ok", r.get("ok") is True and r.get("converged") is True and r.get("health_verdict") == "SAFE", str(r.get("health_verdict"))) for name, ok, detail in checks: print(f"{'PASS' if ok else 'FAIL'} {name}" + (f" ({detail})" if detail else "")) ok = all(c[1] for c in checks) print(f"\n{'ALL_CHECKS_PASSED' if ok else 'FAILED'}: {sum(c[1] for c in checks)}/{len(checks)}") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())