|
38 | 38 | from sigstore.verify.policy import VerificationPolicy
|
39 | 39 |
|
40 | 40 |
|
| 41 | +# List the claims OID supported |
| 42 | +# Source: https://github.com/sigstore/fulcio/blob/main/docs/oid-info.md |
| 43 | +# We only support the extensions from 1.3.6.1.4.1.57264.1.8 to .22. |
| 44 | +# In particular, `1.3.6.1.4.1.57264.1.7 | OtherName SAN` is not supported |
| 45 | +# because we believe this is not used in-the-wild. |
| 46 | +_FULCIO_CLAIMS_OIDS = [ |
| 47 | + # 1.3.6.1.4.1.57264.1.8 | Issuer (V2) |
| 48 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.8"), |
| 49 | + # 1.3.6.1.4.1.57264.1.9 | Build Signer URI |
| 50 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.9"), |
| 51 | + # 1.3.6.1.4.1.57264.1.10 | Build Signer Digest |
| 52 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.10"), |
| 53 | + # 1.3.6.1.4.1.57264.1.11 | Runner Environment |
| 54 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.11"), |
| 55 | + # 1.3.6.1.4.1.57264.1.12 | Source Repository URI |
| 56 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.12"), |
| 57 | + # 1.3.6.1.4.1.57264.1.13 | Source Repository Digest |
| 58 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.13"), |
| 59 | + # 1.3.6.1.4.1.57264.1.14 | Source Repository Ref |
| 60 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.14"), |
| 61 | + # 1.3.6.1.4.1.57264.1.15 | Source Repository Identifier |
| 62 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.15"), |
| 63 | + # 1.3.6.1.4.1.57264.1.16 | Source Repository Owner URI |
| 64 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.16"), |
| 65 | + # 1.3.6.1.4.1.57264.1.17 | Source Repository Owner Identifier |
| 66 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.17"), |
| 67 | + # 1.3.6.1.4.1.57264.1.18 | Build Config URI |
| 68 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.18"), |
| 69 | + # 1.3.6.1.4.1.57264.1.19 | Build Config Digest |
| 70 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.19"), |
| 71 | + # 1.3.6.1.4.1.57264.1.20 | Build Trigger |
| 72 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.20"), |
| 73 | + # 1.3.6.1.4.1.57264.1.21 | Run Invocation URI |
| 74 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.21"), |
| 75 | + # 1.3.6.1.4.1.57264.1.22 | Source Repository Visibility At Signing |
| 76 | + x509.ObjectIdentifier("1.3.6.1.4.1.57264.1.22"), |
| 77 | +] |
| 78 | + |
| 79 | + |
41 | 80 | class Distribution(BaseModel):
|
42 | 81 | """Represents a Python package distribution.
|
43 | 82 |
|
@@ -167,6 +206,24 @@ def sign(cls, signer: Signer, dist: Distribution) -> Attestation:
|
167 | 206 | except ConversionError as e:
|
168 | 207 | raise AttestationError(str(e))
|
169 | 208 |
|
| 209 | + @property |
| 210 | + def certificate_claims(self) -> dict[str, str]: |
| 211 | + """Return the claims present in the certificate. |
| 212 | +
|
| 213 | + We only return claims present in `_FULCIO_CLAIMS_OIDS`. |
| 214 | + Values are decoded and returned as strings. |
| 215 | + """ |
| 216 | + certificate = x509.load_der_x509_certificate(self.verification_material.certificate) |
| 217 | + claims = {} |
| 218 | + for extension in certificate.extensions: |
| 219 | + if extension.oid in _FULCIO_CLAIMS_OIDS: |
| 220 | + # 1.3.6.1.4.1.57264.1.8 through 1.3.6.1.4.1.57264.1.22 are formatted as DER-encoded |
| 221 | + # strings; the ASN.1 tag is UTF8String (0x0C) and the tag class is universal. |
| 222 | + value = extension.value.value |
| 223 | + claims[extension.oid.dotted_string] = _der_decode_utf8string(value) |
| 224 | + |
| 225 | + return claims |
| 226 | + |
170 | 227 | def verify(
|
171 | 228 | self,
|
172 | 229 | identity: VerificationPolicy | Publisher,
|
|
0 commit comments