Skip to content

Commit da29364

Browse files
aaronlew02jku
andauthored
Support DSSE signing conformance test (#1682)
Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com> Co-authored-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent d3ffb80 commit da29364

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

test/integration/sigstore-python-conformance

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import json
88
import os
99
import sys
1010
from contextlib import suppress
11+
from pathlib import Path
1112
from tempfile import NamedTemporaryFile
1213

1314
# The signing config in this trust_config is not used: it's just here
@@ -97,6 +98,52 @@ with NamedTemporaryFile(mode="wt") as temp_file:
9798
# `sigstore` requires `verify identity` for identity based verifications.
9899
subcommand, *fixed_args = fixed_args
99100
if subcommand == "sign":
101+
if "--in-toto" in fixed_args:
102+
# Handle DSSE signing via library call
103+
fixed_args.remove("--in-toto")
104+
105+
from sigstore.dsse import Statement
106+
from sigstore.models import ClientTrustConfig
107+
from sigstore.oidc import IdentityToken
108+
from sigstore.sign import SigningContext
109+
110+
identity_token = None
111+
bundle_path = None
112+
try:
113+
i = fixed_args.index("--identity-token")
114+
identity_token = fixed_args[i + 1]
115+
i = fixed_args.index("--bundle")
116+
bundle_path = fixed_args[i + 1]
117+
except (ValueError, IndexError):
118+
raise ValueError("Missing required arguments for DSSE signing")
119+
120+
# The statement is always the last argument in the protocol
121+
input_file = fixed_args[-1]
122+
123+
# Direct library call
124+
with open(input_file, "rb") as f:
125+
statement_bytes = f.read()
126+
127+
statement = Statement(statement_bytes)
128+
129+
if trusted_root_path is not None:
130+
trust_config_obj = ClientTrustConfig.from_json(Path(temp_file.name).read_text())
131+
else:
132+
trust_config_obj = ClientTrustConfig.production()
133+
if "--staging" in sys.argv:
134+
trust_config_obj = ClientTrustConfig.staging()
135+
136+
context = SigningContext.from_trust_config(trust_config_obj)
137+
token = IdentityToken(identity_token)
138+
139+
with context.signer(token) as signer:
140+
bundle = signer.sign_dsse(statement)
141+
142+
with open(bundle_path, "w") as f:
143+
f.write(bundle.to_json())
144+
145+
# Exit successfully after handling DSSE
146+
sys.exit(0)
100147
command.append("sign")
101148
elif subcommand == "verify":
102149
command.extend(["verify", "identity"])

0 commit comments

Comments
 (0)