|
28 | 28 | bundle_path = Path(sys.argv[1]) |
29 | 29 | signer_identity = sys.argv[2] |
30 | 30 |
|
31 | | -for line in bundle_path.read_bytes().splitlines(): |
32 | | - dsse_envelope_payload = json.loads(line)['dsseEnvelope']['payload'] |
33 | | - subjects = json.loads(b64decode(dsse_envelope_payload))['subject'] |
34 | | - for subject in subjects: |
35 | | - filename = subject['name'] |
36 | | - assert (DIST / filename).is_file() |
37 | | - |
38 | | - # Convert attestation from Sigstore to PEP 740 |
39 | | - print(f'Converting attestation for {filename}') |
40 | | - sigstore_bundle = Bundle.from_json(line) |
41 | | - attestation = Attestation.from_bundle(sigstore_bundle) |
42 | | - attestation_path = DIST / f'{filename}.publish.attestation' |
43 | | - attestation_path.write_text(attestation.model_dump_json()) |
44 | | - print(f'Attestation for {filename} written to {attestation_path}') |
45 | | - print() |
46 | | - |
47 | | - # Validate attestation |
48 | | - dist = Distribution.from_file(DIST / filename) |
49 | | - attestation = Attestation.model_validate_json(attestation_path.read_bytes()) |
50 | | - identity = Identity(identity=signer_identity) |
51 | | - attestation.verify(identity=identity, dist=dist) |
52 | | - print(f'Verified {attestation_path}') |
| 31 | +bundle_content = bundle_path.read_bytes() |
| 32 | +dsse_envelope_payload = json.loads(bundle_content)['dsseEnvelope']['payload'] |
| 33 | +subjects = json.loads(b64decode(dsse_envelope_payload))['subject'] |
| 34 | +for subject in subjects: |
| 35 | + filename = subject['name'] |
| 36 | + assert (DIST / filename).is_file() |
| 37 | + |
| 38 | + # Convert attestation from Sigstore to PEP 740 |
| 39 | + print(f'Converting attestation for {filename}') |
| 40 | + sigstore_bundle = Bundle.from_json(bundle_content) |
| 41 | + attestation = Attestation.from_bundle(sigstore_bundle) |
| 42 | + attestation_path = DIST / f'{filename}.publish.attestation' |
| 43 | + attestation_path.write_text(attestation.model_dump_json()) |
| 44 | + print(f'Attestation for {filename} written to {attestation_path}') |
| 45 | + print() |
| 46 | + |
| 47 | + # Validate attestation |
| 48 | + dist = Distribution.from_file(DIST / filename) |
| 49 | + attestation = Attestation.model_validate_json(attestation_path.read_bytes()) |
| 50 | + identity = Identity(identity=signer_identity) |
| 51 | + attestation.verify(identity=identity, dist=dist) |
| 52 | + print(f'Verified {attestation_path}') |
0 commit comments