|
32 | 32 | SubjectAlternativeName,
|
33 | 33 | UniformResourceIdentifier,
|
34 | 34 | )
|
| 35 | +from pyasn1.codec.der.decoder import decode as der_decode |
| 36 | +from pyasn1.type.char import UTF8String |
35 | 37 |
|
36 | 38 | from sigstore.errors import VerificationError
|
37 | 39 |
|
|
45 | 47 | _OIDC_GITHUB_WORKFLOW_REPOSITORY_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.5")
|
46 | 48 | _OIDC_GITHUB_WORKFLOW_REF_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.6")
|
47 | 49 | _OTHERNAME_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.7")
|
| 50 | +_OIDC_ISSUER_V2_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.8") |
| 51 | +_OIDC_BUILD_SIGNER_URI_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.9") |
| 52 | +_OIDC_BUILD_SIGNER_DIGEST_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.10") |
| 53 | +_OIDC_RUNNER_ENVIRONMENT_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.11") |
| 54 | +_OIDC_SOURCE_REPOSITORY_URI_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.12") |
| 55 | +_OIDC_SOURCE_REPOSITORY_DIGEST_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.13") |
| 56 | +_OIDC_SOURCE_REPOSITORY_REF_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.14") |
| 57 | +_OIDC_SOURCE_REPOSITORY_IDENTIFIER_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.15") |
| 58 | +_OIDC_SOURCE_REPOSITORY_OWNER_URI_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.16") |
| 59 | +_OIDC_SOURCE_REPOSITORY_OWNER_IDENTIFIER_OID = ObjectIdentifier( |
| 60 | + "1.3.6.1.4.1.57264.1.17" |
| 61 | +) |
| 62 | +_OIDC_BUILD_CONFIG_URI_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.18") |
| 63 | +_OIDC_BUILD_CONFIG_DIGEST_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.19") |
| 64 | +_OIDC_BUILD_TRIGGER_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.20") |
| 65 | +_OIDC_RUN_INVOCATION_URI_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.21") |
| 66 | +_OIDC_SOURCE_REPOSITORY_VISIBILITY_OID = ObjectIdentifier("1.3.6.1.4.1.57264.1.22") |
48 | 67 |
|
49 | 68 |
|
50 | 69 | class _SingleX509ExtPolicy(ABC):
|
@@ -93,6 +112,53 @@ def verify(self, cert: Certificate) -> None:
|
93 | 112 | )
|
94 | 113 |
|
95 | 114 |
|
| 115 | +class _SingleX509ExtPolicyDer(ABC): |
| 116 | + """ |
| 117 | + An ABC for verification policies that boil down to checking a single |
| 118 | + X.509 extension's value, where the value is formatted as a DER-encoded string, |
| 119 | + the ASN.1 tag is UTF8String (0x0C) and the tag class is universal. |
| 120 | + """ |
| 121 | + |
| 122 | + oid: ObjectIdentifier |
| 123 | + """ |
| 124 | + The OID of the extension being checked. |
| 125 | + """ |
| 126 | + |
| 127 | + def __init__(self, value: str) -> None: |
| 128 | + """ |
| 129 | + Creates the new policy, with `value` as the expected value during |
| 130 | + verification. |
| 131 | + """ |
| 132 | + self._value = value |
| 133 | + |
| 134 | + def verify(self, cert: Certificate) -> None: |
| 135 | + """ |
| 136 | + Verify this policy against `cert`. |
| 137 | +
|
| 138 | + Raises `VerificationError` on failure. |
| 139 | + """ |
| 140 | + try: |
| 141 | + ext = cert.extensions.get_extension_for_oid(self.oid).value |
| 142 | + except ExtensionNotFound: |
| 143 | + raise VerificationError( |
| 144 | + ( |
| 145 | + f"Certificate does not contain {self.__class__.__name__} " |
| 146 | + f"({self.oid.dotted_string}) extension" |
| 147 | + ) |
| 148 | + ) |
| 149 | + |
| 150 | + # NOTE(ww): mypy is confused by the `Extension[ExtensionType]` returned |
| 151 | + # by `get_extension_for_oid` above. |
| 152 | + ext_value = der_decode(ext.value, UTF8String)[0].decode() # type: ignore[attr-defined] |
| 153 | + if ext_value != self._value: |
| 154 | + raise VerificationError( |
| 155 | + ( |
| 156 | + f"Certificate's {self.__class__.__name__} does not match " |
| 157 | + f"(got {ext_value}, expected {self._value})" |
| 158 | + ) |
| 159 | + ) |
| 160 | + |
| 161 | + |
96 | 162 | class OIDCIssuer(_SingleX509ExtPolicy):
|
97 | 163 | """
|
98 | 164 | Verifies the certificate's OIDC issuer, identified by
|
@@ -147,6 +213,145 @@ class GitHubWorkflowRef(_SingleX509ExtPolicy):
|
147 | 213 | oid = _OIDC_GITHUB_WORKFLOW_REF_OID
|
148 | 214 |
|
149 | 215 |
|
| 216 | +class OIDCIssuerV2(_SingleX509ExtPolicyDer): |
| 217 | + """ |
| 218 | + Verifies the certificate's OIDC issuer, identified by |
| 219 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.8`. |
| 220 | + The difference with `OIDCIssuer` is that the value for |
| 221 | + this extension is formatted to the RFC 5280 specification |
| 222 | + as a DER-encoded string. |
| 223 | + """ |
| 224 | + |
| 225 | + oid = _OIDC_ISSUER_V2_OID |
| 226 | + |
| 227 | + |
| 228 | +class OIDCBuildSignerURI(_SingleX509ExtPolicyDer): |
| 229 | + """ |
| 230 | + Verifies the certificate's OIDC Build Signer URI, identified by |
| 231 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.9`. |
| 232 | + """ |
| 233 | + |
| 234 | + oid = _OIDC_BUILD_SIGNER_URI_OID |
| 235 | + |
| 236 | + |
| 237 | +class OIDCBuildSignerDigest(_SingleX509ExtPolicyDer): |
| 238 | + """ |
| 239 | + Verifies the certificate's OIDC Build Signer Digest, identified by |
| 240 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.10`. |
| 241 | + """ |
| 242 | + |
| 243 | + oid = _OIDC_BUILD_SIGNER_DIGEST_OID |
| 244 | + |
| 245 | + |
| 246 | +class OIDCRunnerEnvironment(_SingleX509ExtPolicyDer): |
| 247 | + """ |
| 248 | + Verifies the certificate's OIDC Runner Environment, identified by |
| 249 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.11`. |
| 250 | + """ |
| 251 | + |
| 252 | + oid = _OIDC_RUNNER_ENVIRONMENT_OID |
| 253 | + |
| 254 | + |
| 255 | +class OIDCSourceRepositoryURI(_SingleX509ExtPolicyDer): |
| 256 | + """ |
| 257 | + Verifies the certificate's OIDC Source Repository URI, identified by |
| 258 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.12`. |
| 259 | + """ |
| 260 | + |
| 261 | + oid = _OIDC_SOURCE_REPOSITORY_URI_OID |
| 262 | + |
| 263 | + |
| 264 | +class OIDCSourceRepositoryDigest(_SingleX509ExtPolicyDer): |
| 265 | + """ |
| 266 | + Verifies the certificate's OIDC Source Repository Digest, identified by |
| 267 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.13`. |
| 268 | + """ |
| 269 | + |
| 270 | + oid = _OIDC_SOURCE_REPOSITORY_DIGEST_OID |
| 271 | + |
| 272 | + |
| 273 | +class OIDCSourceRepositoryRef(_SingleX509ExtPolicyDer): |
| 274 | + """ |
| 275 | + Verifies the certificate's OIDC Source Repository Ref, identified by |
| 276 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.14`. |
| 277 | + """ |
| 278 | + |
| 279 | + oid = _OIDC_SOURCE_REPOSITORY_REF_OID |
| 280 | + |
| 281 | + |
| 282 | +class OIDCSourceRepositoryIdentifier(_SingleX509ExtPolicyDer): |
| 283 | + """ |
| 284 | + Verifies the certificate's OIDC Source Repository Identifier, identified by |
| 285 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.15`. |
| 286 | + """ |
| 287 | + |
| 288 | + oid = _OIDC_SOURCE_REPOSITORY_IDENTIFIER_OID |
| 289 | + |
| 290 | + |
| 291 | +class OIDCSourceRepositoryOwnerURI(_SingleX509ExtPolicyDer): |
| 292 | + """ |
| 293 | + Verifies the certificate's OIDC Source Repository Owner URI, identified by |
| 294 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.16`. |
| 295 | + """ |
| 296 | + |
| 297 | + oid = _OIDC_SOURCE_REPOSITORY_OWNER_URI_OID |
| 298 | + |
| 299 | + |
| 300 | +class OIDCSourceRepositoryOwnerIdentifier(_SingleX509ExtPolicyDer): |
| 301 | + """ |
| 302 | + Verifies the certificate's OIDC Source Repository Owner Identifier, identified by |
| 303 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.17`. |
| 304 | + """ |
| 305 | + |
| 306 | + oid = _OIDC_SOURCE_REPOSITORY_OWNER_IDENTIFIER_OID |
| 307 | + |
| 308 | + |
| 309 | +class OIDCBuildConfigURI(_SingleX509ExtPolicyDer): |
| 310 | + """ |
| 311 | + Verifies the certificate's OIDC Build Config URI, identified by |
| 312 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.18`. |
| 313 | + """ |
| 314 | + |
| 315 | + oid = _OIDC_BUILD_CONFIG_URI_OID |
| 316 | + |
| 317 | + |
| 318 | +class OIDCBuildConfigDigest(_SingleX509ExtPolicyDer): |
| 319 | + """ |
| 320 | + Verifies the certificate's OIDC Build Config Digest, identified by |
| 321 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.19`. |
| 322 | + """ |
| 323 | + |
| 324 | + oid = _OIDC_BUILD_CONFIG_DIGEST_OID |
| 325 | + |
| 326 | + |
| 327 | +class OIDCBuildTrigger(_SingleX509ExtPolicyDer): |
| 328 | + """ |
| 329 | + Verifies the certificate's OIDC Build Trigger, identified by |
| 330 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.20`. |
| 331 | + """ |
| 332 | + |
| 333 | + oid = _OIDC_BUILD_TRIGGER_OID |
| 334 | + |
| 335 | + |
| 336 | +class OIDCRunInvocationURI(_SingleX509ExtPolicyDer): |
| 337 | + """ |
| 338 | + Verifies the certificate's OIDC Run Invocation URI, identified by |
| 339 | + an X.509v3 extension tagged with `1.3.6.1.4.1.57264.1.21`. |
| 340 | + """ |
| 341 | + |
| 342 | + oid = _OIDC_RUN_INVOCATION_URI_OID |
| 343 | + |
| 344 | + |
| 345 | +class OIDCSourceRepositoryVisibility(_SingleX509ExtPolicyDer): |
| 346 | + """ |
| 347 | + Verifies the certificate's OIDC Source Repository Visibility |
| 348 | + At Signing, identified by an X.509v3 extension tagged with |
| 349 | + `1.3.6.1.4.1.57264.1.22`. |
| 350 | + """ |
| 351 | + |
| 352 | + oid = _OIDC_SOURCE_REPOSITORY_VISIBILITY_OID |
| 353 | + |
| 354 | + |
150 | 355 | class VerificationPolicy(Protocol):
|
151 | 356 | """
|
152 | 357 | A protocol type describing the interface that all verification policies
|
|
0 commit comments