The 2026-11-02 identity was never registered. The founder chose to create a new one inside custody at platform/recovery/mas/age-identity before T04. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assistant: claude-code Assistant-Model: opus Assistant-Process: 4541@bnt-lap001 Assistant-Session: 2099b3aa-d7d9-49a9-ab4e-fa8b7d0e39e8
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
"""Age escrow: generated in memory, written CAS=0, read back and proven. Real age, fake OpenBao."""
|
|
|
|
import importlib.util
|
|
import json
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.skipif(not shutil.which("age-keygen"), reason="age required")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
spec = importlib.util.spec_from_file_location("escrow", ROOT / "scripts/mas_evidence_age_escrow.py")
|
|
esc = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(esc)
|
|
|
|
|
|
class FakeBao:
|
|
def __init__(self, existing=False, corrupt=False):
|
|
self.store = {"x": 1} if existing else None
|
|
self.corrupt = corrupt
|
|
self.writes = []
|
|
|
|
def call(self, method, path, body=None):
|
|
if path == "platform/metadata/recovery/mas/age-identity":
|
|
return (200, {}) if self.store else (404, {})
|
|
if method == "POST":
|
|
assert body["options"] == {"cas": 0}
|
|
self.writes.append(sorted(body["data"]))
|
|
self.store = dict(body["data"])
|
|
return 200, {"data": {"version": 1}}
|
|
if method == "GET":
|
|
data = dict(self.store)
|
|
if self.corrupt:
|
|
data["AGE_RECIPIENT"] = "age1other"
|
|
return 200, {"data": {"data": data}}
|
|
raise AssertionError(path)
|
|
|
|
|
|
def test_escrow_writes_once_and_proves_from_custody():
|
|
bao = FakeBao()
|
|
receipt = esc.escrow(bao)
|
|
assert receipt["status"] == "escrowed" and receipt["recipient"].startswith("age1")
|
|
assert bao.writes == [["AGE_PRIVATE_KEY", "AGE_RECIPIENT"]]
|
|
assert esc.derive(bao.store["AGE_PRIVATE_KEY"]) == receipt["recipient"]
|
|
assert "AGE-SECRET-KEY" not in json.dumps(receipt)
|
|
|
|
|
|
def test_existing_identity_is_never_replaced():
|
|
bao = FakeBao(existing=True)
|
|
with pytest.raises(esc.EscrowError) as caught:
|
|
esc.escrow(bao)
|
|
assert caught.value.code == "existing_identity_requires_rotation_review" and bao.writes == []
|
|
|
|
|
|
def test_readback_mismatch_fails():
|
|
with pytest.raises(esc.EscrowError) as caught:
|
|
esc.escrow(FakeBao(corrupt=True))
|
|
assert caught.value.code == "escrow_readback_mismatch"
|
|
|
|
|
|
def test_round_trip_rejects_a_foreign_key():
|
|
key, _ = esc.generate()
|
|
_, other = esc.generate()
|
|
with pytest.raises(esc.EscrowError):
|
|
esc.round_trip(key, other)
|