Skip to content

Small changes to Rekov2 client PR #1434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ All versions prior to 0.9.0 are untracked.


* Added a `RekorV2Client` for posting new entries to a Rekor V2 instance.
[#1400](https://github.com/sigstore/sigstore-python/pull/1400)
[#1400](https://github.com/sigstore/sigstore-python/pull/1422)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"rfc8785 ~= 0.1.2",
"rfc3161-client >= 1.0.2,< 1.1.0",
# NOTE(ww): Both under active development, so strictly pinned.
"sigstore-protobuf-specs == 0.4.2",
"sigstore-protobuf-specs @ git+https://github.com/sigstore/protobuf-specs.git@main#subdirectory=gen/pb-python",
"sigstore-rekor-types == 0.0.18",
"tuf ~= 6.0",
"platformdirs ~= 4.2",
Expand Down
13 changes: 7 additions & 6 deletions sigstore/_internal/rekor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"_hashedrekord_from_parts",
]

EntryRequest = NewType("EntryRequest", dict[str, Any])
EntryRequestBody = NewType("EntryRequestBody", dict[str, Any])


class RekorClientError(Exception):
Expand All @@ -60,15 +60,16 @@ def __init__(self, http_error: requests.HTTPError):


class RekorLogSubmitter(ABC):
"""Abstract class to represent a Rekor log entry submitter.
"""
Abstract class to represent a Rekor log entry submitter.

Intended to be implemented by RekorClient and RekorV2Client
Intended to be implemented by RekorClient and RekorV2Client.
"""

@abstractmethod
def create_entry(
self,
request: EntryRequest,
request: EntryRequestBody,
) -> LogEntry:
"""
Submit the request to Rekor.
Expand All @@ -79,7 +80,7 @@ def create_entry(
@abstractmethod
def _build_hashed_rekord_request(
self, hashed_input: Hashed, signature: bytes, certificate: Certificate
) -> EntryRequest:
) -> EntryRequestBody:
"""
Construct a hashed rekord request to submit to Rekor.
"""
Expand All @@ -89,7 +90,7 @@ def _build_hashed_rekord_request(
@abstractmethod
def _build_dsse_request(
self, envelope: Envelope, certificate: Certificate
) -> EntryRequest:
) -> EntryRequestBody:
"""
Construct a dsse request to submit to Rekor.
"""
Expand Down
14 changes: 7 additions & 7 deletions sigstore/_internal/rekor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from sigstore._internal import USER_AGENT
from sigstore._internal.rekor import (
EntryRequest,
EntryRequestBody,
RekorClientError,
RekorLogSubmitter,
)
Expand Down Expand Up @@ -134,7 +134,7 @@ def get(

def post(
self,
payload: EntryRequest,
payload: EntryRequestBody,
) -> LogEntry:
"""
Submit a new entry for inclusion in the Rekor log.
Expand Down Expand Up @@ -250,15 +250,15 @@ def log(self) -> RekorLog:
"""
return RekorLog(f"{self.url}/log", session=self.session)

def create_entry(self, request: EntryRequest) -> LogEntry:
def create_entry(self, request: EntryRequestBody) -> LogEntry:
"""
Submit the request to Rekor.
"""
return self.log.entries.post(request)

def _build_hashed_rekord_request( # type: ignore[override]
self, hashed_input: Hashed, signature: bytes, certificate: Certificate
) -> EntryRequest:
) -> EntryRequestBody:
"""
Construct a hashed rekord payload to submit to Rekor.
"""
Expand All @@ -282,11 +282,11 @@ def _build_hashed_rekord_request( # type: ignore[override]
),
),
)
return EntryRequest(rekord.model_dump(mode="json", by_alias=True))
return EntryRequestBody(rekord.model_dump(mode="json", by_alias=True))

def _build_dsse_request( # type: ignore[override]
self, envelope: Envelope, certificate: Certificate
) -> EntryRequest:
) -> EntryRequestBody:
"""
Construct a dsse request to submit to Rekor.
"""
Expand All @@ -308,4 +308,4 @@ def _build_dsse_request( # type: ignore[override]
),
),
)
return EntryRequest(dsse.model_dump(mode="json", by_alias=True))
return EntryRequestBody(dsse.model_dump(mode="json", by_alias=True))
25 changes: 16 additions & 9 deletions sigstore/_internal/rekor/client_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
from sigstore_protobuf_specs.io import intoto

from sigstore._internal import USER_AGENT
from sigstore._internal.rekor import EntryRequest, RekorClientError, RekorLogSubmitter
from sigstore._internal.rekor import (
EntryRequestBody,
RekorClientError,
RekorLogSubmitter,
)
from sigstore.dsse import Envelope
from sigstore.hashes import Hashed
from sigstore.models import LogEntry
Expand All @@ -40,7 +44,8 @@


class RekorV2Client(RekorLogSubmitter):
"""The internal Rekor client for the v2 API
"""
The internal Rekor client for the v2 API.

See https://github.com/sigstore/rekor-tiles/blob/main/CLIENTS.md
"""
Expand All @@ -65,7 +70,7 @@ def __del__(self) -> None:
"""
self.session.close()

def create_entry(self, payload: EntryRequest) -> LogEntry:
def create_entry(self, payload: EntryRequestBody) -> LogEntry:
"""
Submit a new entry for inclusion in the Rekor log.

Expand All @@ -90,9 +95,11 @@ def create_entry(self, payload: EntryRequest) -> LogEntry:

@staticmethod
def _get_key_details(certificate: Certificate) -> common_v1.PublicKeyDetails:
"""Determine PublicKeyDetails from a certificate
"""
Determine PublicKeyDetails from a certificate

We know that sign.Signer only uses secp256r1 so do not support anything else"""
We know that sign.Signer only uses secp256r1, so do not support anything else.
"""
public_key = certificate.public_key()
if isinstance(public_key, EllipticCurvePublicKey):
if public_key.curve.name == "secp256r1":
Expand All @@ -109,7 +116,7 @@ def _build_hashed_rekord_request(
hashed_input: Hashed,
signature: bytes,
certificate: Certificate,
) -> EntryRequest:
) -> EntryRequestBody:
"""
Construct a hashed rekord request to submit to Rekor.
"""
Expand All @@ -129,12 +136,12 @@ def _build_hashed_rekord_request(
),
)
)
return EntryRequest(req.to_dict())
return EntryRequestBody(req.to_dict())

@classmethod
def _build_dsse_request(
cls, envelope: Envelope, certificate: Certificate
) -> EntryRequest:
) -> EntryRequestBody:
"""
Construct a dsse request to submit to Rekor.
"""
Expand Down Expand Up @@ -163,4 +170,4 @@ def _build_dsse_request(
],
)
)
return EntryRequest(req.to_dict())
return EntryRequestBody(req.to_dict())
4 changes: 2 additions & 2 deletions sigstore/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
ExpiredCertificate,
FulcioClient,
)
from sigstore._internal.rekor import EntryRequest, RekorLogSubmitter
from sigstore._internal.rekor import EntryRequestBody, RekorLogSubmitter
from sigstore._internal.sct import verify_sct
from sigstore._internal.timestamp import TimestampAuthorityClient, TimestampError
from sigstore._internal.trust import ClientTrustConfig, KeyringPurpose, TrustedRoot
Expand Down Expand Up @@ -174,7 +174,7 @@ def _finalize_sign(
self,
cert: x509.Certificate,
content: MessageSignature | dsse.Envelope,
proposed_entry: EntryRequest,
proposed_entry: EntryRequestBody,
) -> Bundle:
"""
Perform the common "finalizing" steps in a Sigstore signing flow.
Expand Down