| |
| """Re-check every record in the corpus with certkit. |
| |
| This is the script that makes the corpus an artifact rather than a claim. It |
| imports `certkit` -- which contains no solver, no search, and no code from the |
| pipeline that produced these certificates -- and re-derives each obligation from |
| the published spec before replaying the multipliers against it. |
| |
| A record passes only if, for every safety conjunct, the system |
| |
| domain AND guard AND NOT safety[i] |
| |
| is refuted by the supplied nonnegative multipliers. Since the certificate is not |
| permitted to supply its own atoms, a certificate proving some easier unrelated |
| system cannot pass. |
| |
| pip install certkit |
| python verify.py |
| |
| Exit codes: |
| |
| 0 every record verified |
| 1 at least one record failed |
| 2 usage error |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import sys |
| from pathlib import Path |
| from typing import Any |
|
|
|
|
| def main(argv: Any = None) -> int: |
| ap = argparse.ArgumentParser(description="Verify the CVE proof corpus with certkit.") |
| |
| |
| ap.add_argument( |
| "--data", |
| type=Path, |
| default=Path(__file__).resolve().parent / "cve-proof-corpus.jsonl", |
| ) |
| ap.add_argument("--quiet", action="store_true") |
| args = ap.parse_args(argv) |
|
|
| try: |
| from certkit import check_certificate |
| except ImportError: |
| print("error: certkit is required -- pip install certkit", file=sys.stderr) |
| return 2 |
|
|
| if not args.data.is_file(): |
| print(f"error: {args.data} not found; run export.py first", file=sys.stderr) |
| return 2 |
|
|
| rows = [json.loads(line) for line in args.data.read_text(encoding="utf-8").splitlines() if line] |
|
|
| ok_count = 0 |
| failures: list[str] = [] |
|
|
| for rec in rows: |
| report = check_certificate(rec["spec"], rec["certificate"]) |
| status = "VERIFIED" if report.ok else "FAILED" |
| if report.ok: |
| ok_count += 1 |
| else: |
| failures.append(rec["id"]) |
|
|
| if not args.quiet: |
| n = rec["n_safety_conjuncts"] |
| print(f" {status:9s} {rec['id']:24s} {rec['cve']:16s} {n} obligation(s)") |
| if not report.ok: |
| for ob in report.obligations: |
| if not ob["ok"]: |
| print(f" obligation {ob['index']}: {ob['reason']}") |
|
|
| print() |
| print(f"{ok_count} of {len(rows)} records verified by certkit") |
|
|
| if failures: |
| print(f"FAILED: {', '.join(failures)}", file=sys.stderr) |
| return 1 |
|
|
| print("Every published certificate re-checks against its published spec.") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|