Skip to content

Commit 441c416

Browse files
committed
verify: Handle more ECDSA keys in signing cert
This change affects the signing certificate verification in rekor v2 entries: * Support all ECDSA keys listed in https://github.com/sigstore/architecture-docs/blob/main/algorithm-registry.md * Don't support other algorithms yet since the actual signature verification does not support them currently Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent e47e555 commit 441c416

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

sigstore/verify/verifier.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from cryptography.exceptions import InvalidSignature
2828
from cryptography.hazmat.primitives import serialization
2929
from cryptography.hazmat.primitives.asymmetric import ec
30-
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePublicKey
3130
from cryptography.x509 import Certificate, ExtendedKeyUsage, KeyUsage
3231
from cryptography.x509.oid import ExtendedKeyUsageOID
3332
from OpenSSL.crypto import (
@@ -621,26 +620,32 @@ def _validate_hashedrekord_v002_entry_body(bundle: Bundle) -> None:
621620

622621

623622
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+
"""
624632
public_key = certificate.public_key()
625-
key_details = None
626633

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
633641
else:
634642
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:
639644
raise ValueError(f"Unsupported public key type: {type(public_key)}")
640645

641646
return v2.Verifier(
642647
x509_certificate=v1.X509Certificate(
643648
certificate.public_bytes(encoding=serialization.Encoding.DER)
644649
),
645-
key_details=key_details,
650+
key_details=cast(v1.PublicKeyDetails, key_details),
646651
)

0 commit comments

Comments
 (0)