|
27 | 27 | from cryptography.exceptions import InvalidSignature
|
28 | 28 | from cryptography.hazmat.primitives import serialization
|
29 | 29 | from cryptography.hazmat.primitives.asymmetric import ec
|
30 |
| -from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePublicKey |
31 | 30 | from cryptography.x509 import Certificate, ExtendedKeyUsage, KeyUsage
|
32 | 31 | from cryptography.x509.oid import ExtendedKeyUsageOID
|
33 | 32 | from OpenSSL.crypto import (
|
@@ -621,26 +620,32 @@ def _validate_hashedrekord_v002_entry_body(bundle: Bundle) -> None:
|
621 | 620 |
|
622 | 621 |
|
623 | 622 | def _v2_verifier_from_certificate(certificate: Certificate) -> v2.Verifier:
|
| 623 | + """ |
| 624 | + Return a Rekor v2 protobuf Verifier for the signing certificate. |
| 625 | +
|
| 626 | + This method decides which signature algorithms are supported for verification |
| 627 | + (in a rekor v2 entry), see |
| 628 | + https://github.com/sigstore/architecture-docs/blob/main/algorithm-registry.md. |
| 629 | + Note that actual signature verification happens in verify_artifact() and |
| 630 | + verify_dsse(): New keytypes need to be added here and in those methods. |
| 631 | + """ |
624 | 632 | public_key = certificate.public_key()
|
625 |
| - key_details = None |
626 | 633 |
|
627 |
| - if isinstance(public_key, EllipticCurvePublicKey): |
628 |
| - if public_key.curve.name == "secp256r1": |
629 |
| - key_details = cast( |
630 |
| - v1.PublicKeyDetails, |
631 |
| - v1.PublicKeyDetails.PKIX_ECDSA_P256_SHA_256, |
632 |
| - ) |
| 634 | + if isinstance(public_key, ec.EllipticCurvePublicKey): |
| 635 | + if isinstance(public_key.curve, ec.SECP256R1): |
| 636 | + key_details = v1.PublicKeyDetails.PKIX_ECDSA_P256_SHA_256 |
| 637 | + elif isinstance(public_key.curve, ec.SECP384R1): |
| 638 | + key_details = v1.PublicKeyDetails.PKIX_ECDSA_P384_SHA_384 |
| 639 | + elif isinstance(public_key.curve, ec.SECP521R1): |
| 640 | + key_details = v1.PublicKeyDetails.PKIX_ECDSA_P521_SHA_512 |
633 | 641 | else:
|
634 | 642 | raise ValueError(f"Unsupported EC curve: {public_key.curve.name}")
|
635 |
| - |
636 |
| - # TODO support other keys |
637 |
| - |
638 |
| - if key_details is None: |
| 643 | + else: |
639 | 644 | raise ValueError(f"Unsupported public key type: {type(public_key)}")
|
640 | 645 |
|
641 | 646 | return v2.Verifier(
|
642 | 647 | x509_certificate=v1.X509Certificate(
|
643 | 648 | certificate.public_bytes(encoding=serialization.Encoding.DER)
|
644 | 649 | ),
|
645 |
| - key_details=key_details, |
| 650 | + key_details=cast(v1.PublicKeyDetails, key_details), |
646 | 651 | )
|
0 commit comments