32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import json
|
|
from idea199_replicasurety_economic_surety.models import PoeticCert, ReplayBundle, TraceEvent
|
|
from idea199_replicasurety_economic_surety import crypto
|
|
from datetime import datetime
|
|
|
|
|
|
def test_poeticcert_roundtrip_and_signature():
|
|
priv, pub = crypto.generate_rsa_keypair()
|
|
cert = PoeticCert(
|
|
invariants=["no-privilege-escalation"],
|
|
replica_intent_hash="deadbeef",
|
|
)
|
|
# sign canonical bytes (here simple JSON)
|
|
b = cert.json().encode()
|
|
sig = crypto.sign_bytes(priv, b)
|
|
cert.attester_signatures["test-signer"] = sig.hex()
|
|
|
|
# verify
|
|
sig2 = bytes.fromhex(cert.attester_signatures["test-signer"])
|
|
assert crypto.verify_bytes(pub, sig2, b)
|
|
|
|
|
|
def test_replaybundle_structure_and_verifier_input():
|
|
trace = [
|
|
TraceEvent(seq=0, timestamp=datetime.utcnow(), message="start"),
|
|
TraceEvent(seq=1, timestamp=datetime.utcnow(), message="do work"),
|
|
]
|
|
rb = ReplayBundle(trace=trace, monitors={"m1": "sig"}, evidence_root="roothash")
|
|
s = rb.json()
|
|
parsed = ReplayBundle.parse_raw(s)
|
|
assert parsed.evidence_root == "roothash"
|