#!/usr/bin/env python3 """escrow_ceremony.py — the recovery-code ceremony on Tester 1 through the wizard's own calls (operator yes, 2026-10-25): login → GET /api/escrow/preflight → POST /api/escrow/start (password re-auth) → poll /api/escrow/status → POST /api/escrow/claim (the ONE-SHOT code) → POST /api/escrow/confirm (the two words the agent names). The code is NEVER printed or logged: it goes only into the 0600 file named by argv[1] (the caller hands it to `sec put`, which shreds it). Run through `sec run TESTER1_PASSWORD -- python3 escrow_ceremony.py `.""" import json, os, re, subprocess, sys, time PW = os.environ["TESTER1_PASSWORD"] SSH = ["ssh", "-o", "BatchMode=yes", "-o", "ConnectTimeout=20", "root@192.168.0.154"] HOST = "Host: felhom.enkicsifelhom.hu" def run(args, inp=None): return subprocess.run(args, input=inp, capture_output=True, text=True, timeout=300) def base(): r = run(SSH + ["pct exec 9201 -- ip -4 -o addr show eth0"]) return "https://" + re.search(r"inet (\d+\.\d+\.\d+\.\d+)/", r.stdout).group(1) def say(*a): print(time.strftime("%H:%M:%SZ", time.gmtime()), *a, flush=True) B = base() h = run(["curl", "-sk", "-D", "-", "-o", "/dev/null", "-H", HOST, "-X", "POST", "--data-urlencode", "password@-", f"{B}/login"], inp=PW).stdout sess = re.search(r"felhom_session=[A-Za-z0-9._-]+", h).group(0) page = run(["curl", "-sk", "-L", "-H", HOST, "-H", f"Cookie: {sess}", f"{B}/backup/escrow"]).stdout csrf = re.search(r'