"""Consumer offline verifier: python verify_incident_export.py export.json trusted-jwks.json. Fetch JWKS yourself from https://autonet.work/health/v1/evidence/keys over verified TLS. Never follow a key URL supplied by the export. Signature proves the artifact, not health. Requires cryptography. Does not renew or validate embedded diagnostic tokens. """ import base64,hashlib,hmac,json,sys from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey def decode(s):return base64.urlsafe_b64decode(s+'='*(-len(s)%4)) def strict(raw): def pairs(items): out={} for k,v in items: if k in out:raise ValueError('Duplicate JSON key') out[k]=v return out return json.loads(raw,object_pairs_hook=pairs,parse_constant=lambda s:(_ for _ in ()).throw(ValueError('Nonfinite JSON'))) def verify(bundle,jwks): integrity=bundle['integrity'];signature=integrity['signature'] if integrity['signed'] is not True:raise ValueError('Unsigned bundle') token=signature['attestation'];a,b,c=token.split('.');header=strict(decode(a));claims=strict(decode(b)) if header.get('alg')!='EdDSA' or header.get('typ')!='autonet-incident-export+jwt':raise ValueError('Wrong signature purpose') if claims.get('iss')!='https://autonet.work' or claims.get('aud')!='autonet-incident-export' or claims.get('schema_version')!='autonet-signed-export-v1':raise ValueError('Wrong issuer, audience or schema') keys=[k for k in jwks['keys'] if k.get('kid')==header.get('kid') and k.get('kty')=='OKP' and k.get('crv')=='Ed25519' and k.get('alg')=='EdDSA'] if len(keys)!=1:raise ValueError('Unknown or ambiguous trusted key') Ed25519PublicKey.from_public_bytes(decode(keys[0]['x'])).verify(decode(c),(a+'.'+b).encode('ascii')) raw=json.dumps(bundle['evidence'],sort_keys=True,separators=(',',':'),ensure_ascii=True,allow_nan=False).encode('ascii') digest=hashlib.sha256(raw).hexdigest() if not hmac.compare_digest(digest,claims['payload_sha256']) or not hmac.compare_digest(digest,integrity['digest']):raise ValueError('Evidence digest mismatch') return claims if __name__=='__main__': with open(sys.argv[1]) as f:bundle=strict(f.read(10*1024*1024)) with open(sys.argv[2]) as f:keys=strict(f.read(1024*1024)) verify(bundle,keys) print('Artifact signature and evidence digest verified. Review coverage/truncation and original token validity separately; no current-health claim.')