examples/continuous_loop_demo.py
1.6 KB · 64 lines · python Raw
1 """ContinuousAttester demo.
2
3 Runs the attestation loop for a few seconds and prints a one-line summary
4 per produced report. Production deployments would hook this into a systemd
5 timer or a sidecar daemon and stream reports to a remote verifier.
6 """
7
8 from __future__ import annotations
9
10 from quantumshield.identity.agent import AgentIdentity
11
12 from pqc_hypervisor_attestation import (
13 AttestationReport,
14 Attester,
15 ContinuousAttester,
16 InMemoryBackend,
17 MemoryRegion,
18 RegionSnapshot,
19 )
20
21 WORKLOAD_ID = "model-serving-1"
22
23
24 def main() -> None:
25 identity = AgentIdentity.create(
26 name="continuous-attester",
27 capabilities=["attest"],
28 )
29 attester = Attester(identity)
30
31 backend = InMemoryBackend()
32 weights = MemoryRegion(
33 region_id="model-weights-0",
34 description="Llama weight shard 0",
35 address=0x1000,
36 size=64,
37 protection="RO",
38 )
39 content = b"\xaa" * 64
40 backend.register(WORKLOAD_ID, weights, content)
41
42 loop = ContinuousAttester(
43 attester=attester,
44 backend=backend,
45 workload_id=WORKLOAD_ID,
46 expected_hashes={weights.region_id: RegionSnapshot.hash_bytes(content)},
47 )
48
49 def on_report(report: AttestationReport) -> None:
50 claim = report.claims[0]
51 print(
52 f"issued={report.issued_at} "
53 f"region={claim.region.region_id} "
54 f"hash={claim.snapshot.content_hash[:12]}... "
55 f"claims={len(report.claims)}"
56 )
57
58 reports = loop.run_for(seconds=3, interval=1.0, on_report=on_report)
59 print(f"\ntotal reports produced: {len(reports)}")
60
61
62 if __name__ == "__main__":
63 main()
64