Skip to content

Commit 324647c

Browse files
committed
rekor v2: Use the correct keytype in the entry request
We only generate secp256r1 so can skip checking all of the other types for now. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 3d9a1b8 commit 324647c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

sigstore/_internal/rekor/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
class EntryRequest(dict[str, Any]):
3939
"""Entry request payload, for either rekor v1 or v2"""
40+
4041
pass
4142

4243

sigstore/_internal/rekor/client_v2.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import rekor_types
2525
import requests
2626
from cryptography.hazmat.primitives import serialization
27+
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePublicKey
2728
from cryptography.x509 import Certificate
2829
from sigstore_protobuf_specs.dev.sigstore.common import v1 as common_v1
2930
from sigstore_protobuf_specs.dev.sigstore.rekor import v2
@@ -37,8 +38,6 @@
3738

3839
_logger = logging.getLogger(__name__)
3940

40-
DEFAULT_KEY_DETAILS = common_v1.PublicKeyDetails.PKIX_ECDSA_P384_SHA_256
41-
4241

4342
class _V2EntryRequest(EntryRequest):
4443
@classmethod
@@ -99,6 +98,18 @@ def create_entry(self, payload: EntryRequest) -> LogEntry:
9998
_logger.debug(f"integrated: {integrated_entry}")
10099
return LogEntry._from_dict_rekor(integrated_entry)
101100

101+
@staticmethod
102+
def _get_key_details(certificate: Certificate) -> common_v1.PublicKeyDetails:
103+
"""Determine PublicKeyDetails from a certificate
104+
105+
We know that sign.Signer only uses secp256r1 so do not support anything else"""
106+
public_key = certificate.public_key()
107+
if isinstance(public_key, EllipticCurvePublicKey):
108+
if public_key.curve.name == "secp256r1":
109+
return common_v1.PublicKeyDetails.PKIX_ECDSA_P256_SHA_256
110+
raise ValueError(f"Unsupported EC curve: {public_key.curve.name}")
111+
raise ValueError(f"Unsupported public key type: {type(public_key)}")
112+
102113
@classmethod
103114
def _build_hashed_rekord_request(
104115
cls,
@@ -109,6 +120,7 @@ def _build_hashed_rekord_request(
109120
"""
110121
Construct a hashed rekord request to submit to Rekor.
111122
"""
123+
112124
req = v2.HashedRekordRequestV002(
113125
digest=hashed_input.digest,
114126
signature=v2.Signature(
@@ -119,7 +131,7 @@ def _build_hashed_rekord_request(
119131
encoding=serialization.Encoding.DER
120132
)
121133
),
122-
key_details=DEFAULT_KEY_DETAILS, # type: ignore[arg-type]
134+
key_details=cls._get_key_details(certificate),
123135
),
124136
),
125137
)
@@ -151,7 +163,7 @@ def _build_dsse_request(
151163
encoding=serialization.Encoding.DER
152164
)
153165
),
154-
key_details=DEFAULT_KEY_DETAILS, # type: ignore[arg-type]
166+
key_details=cls._get_key_details(certificate),
155167
)
156168
],
157169
)

0 commit comments

Comments
 (0)