38
38
39
39
from __future__ import annotations
40
40
41
- import base64
42
41
import logging
43
42
from collections .abc import Iterator
44
43
from contextlib import contextmanager
47
46
48
47
import cryptography .x509 as x509
49
48
import rekor_types
50
- from cryptography .hazmat .primitives import hashes , serialization
49
+ from cryptography .hazmat .primitives import hashes
51
50
from cryptography .hazmat .primitives .asymmetric import ec
52
51
from cryptography .x509 .oid import NameOID
53
52
from sigstore_protobuf_specs .dev .sigstore .common .v1 import (
@@ -182,7 +181,7 @@ def _finalize_sign(
182
181
Perform the common "finalizing" steps in a Sigstore signing flow.
183
182
"""
184
183
# Submit the proposed entry to the transparency log
185
- entry = self ._signing_ctx ._rekor .log . entries . post (proposed_entry )
184
+ entry = self ._signing_ctx ._rekor .create_entry (proposed_entry )
186
185
187
186
_logger .debug (f"Transparency log entry created with index: { entry .log_index } " )
188
187
@@ -211,26 +210,12 @@ def sign_dsse(
211
210
"""
212
211
cert = self ._signing_cert ()
213
212
214
- # Prepare inputs
215
- b64_cert = base64 .b64encode (
216
- cert .public_bytes (encoding = serialization .Encoding .PEM )
217
- )
218
-
219
213
# Sign the statement, producing a DSSE envelope
220
214
content = dsse ._sign (self ._private_key , input_ )
221
215
222
216
# Create the proposed DSSE log entry
223
- proposed_entry = rekor_types .Dsse (
224
- spec = rekor_types .dsse .DsseSchema (
225
- # NOTE: mypy can't see that this kwarg is correct due to two interacting
226
- # behaviors/bugs (one pydantic, one datamodel-codegen):
227
- # See: <https://github.com/pydantic/pydantic/discussions/7418#discussioncomment-9024927>
228
- # See: <https://github.com/koxudaxi/datamodel-code-generator/issues/1903>
229
- proposed_content = rekor_types .dsse .ProposedContent ( # type: ignore[call-arg]
230
- envelope = content .to_json (),
231
- verifiers = [b64_cert .decode ()],
232
- ),
233
- ),
217
+ proposed_entry = self ._signing_ctx ._rekor ._build_dsse_request (
218
+ envelope = content , certificate = cert
234
219
)
235
220
236
221
return self ._finalize_sign (cert , content , proposed_entry )
@@ -255,11 +240,6 @@ def sign_artifact(
255
240
256
241
cert = self ._signing_cert ()
257
242
258
- # Prepare inputs
259
- b64_cert = base64 .b64encode (
260
- cert .public_bytes (encoding = serialization .Encoding .PEM )
261
- )
262
-
263
243
# Sign artifact
264
244
hashed_input = sha256_digest (input_ )
265
245
@@ -276,21 +256,8 @@ def sign_artifact(
276
256
)
277
257
278
258
# Create the proposed hashedrekord entry
279
- proposed_entry = rekor_types .Hashedrekord (
280
- spec = rekor_types .hashedrekord .HashedrekordV001Schema (
281
- signature = rekor_types .hashedrekord .Signature (
282
- content = base64 .b64encode (artifact_signature ).decode (),
283
- public_key = rekor_types .hashedrekord .PublicKey (
284
- content = b64_cert .decode ()
285
- ),
286
- ),
287
- data = rekor_types .hashedrekord .Data (
288
- hash = rekor_types .hashedrekord .Hash (
289
- algorithm = hashed_input ._as_hashedrekord_algorithm (),
290
- value = hashed_input .digest .hex (),
291
- )
292
- ),
293
- ),
259
+ proposed_entry = self ._signing_ctx ._rekor ._build_hashed_rekord_request (
260
+ hashed_input = hashed_input , signature = artifact_signature , certificate = cert
294
261
)
295
262
296
263
return self ._finalize_sign (cert , content , proposed_entry )
0 commit comments