4
4
A wrapper to convert `sigstore-conformance` CLI protocol invocations to match `sigstore-python`.
5
5
"""
6
6
7
-
8
7
import os
9
8
import sys
9
+ from contextlib import suppress
10
+ from string import Template
11
+ from tempfile import NamedTemporaryFile
12
+
13
+ # The signing config in the template is just filler: it is not used
14
+ TRUST_CONFIG_TEMPLATE = Template ("""
15
+ {
16
+ "mediaType": "application/vnd.dev.sigstore.clienttrustconfig.v0.1+json",
17
+ "trustedRoot": ${trusted_root},
18
+ "signing_config": {
19
+ "mediaType": "application/vnd.dev.sigstore.signingconfig.v0.2+json",
20
+ "caUrls": [{ "url": "https://fulcio.example.com" }],
21
+ "oidcUrls": [],
22
+ "rekorTlogUrls": [{ "url": "https://rekor.example.com" }],
23
+ "tsaUrls": [],
24
+ "rekorTlogConfig": {"selector": "ANY"},
25
+ "tsaConfig": {"selector": "ANY"}
26
+ }
27
+ }
28
+ """ )
29
+
10
30
11
31
SUBCMD_REPLACEMENTS = {
12
32
"sign-bundle" : "sign" ,
@@ -32,17 +52,36 @@ if "--staging" in fixed_args:
32
52
command .append ("--staging" )
33
53
fixed_args .remove ("--staging" )
34
54
35
- # Fix-up the subcommand: the conformance suite uses `verify`, but
36
- # `sigstore` requires `verify identity` for identity based verifications.
37
- subcommand , * fixed_args = fixed_args
38
- if subcommand == "sign" :
39
- command .append ("sign" )
40
- elif subcommand == "verify" :
41
- command .extend (["verify" , "identity" ])
42
- else :
43
- raise ValueError (f"unsupported subcommand: { subcommand } " )
55
+ # We may get "--trusted-root" as argument but sigstore-python wants "--trust-config":
56
+ trusted_root = None
57
+ with suppress (ValueError ):
58
+ i = fixed_args .index ("--trusted-root" )
59
+ trusted_root = fixed_args [i + 1 ]
60
+ fixed_args .pop (i )
61
+ fixed_args .pop (i )
62
+
63
+ # If we did get a trustedroot, write a matching trustconfig into a temp file
64
+ with NamedTemporaryFile (mode = "wt" ) as temp_file :
65
+ if trusted_root is not None :
66
+ with open (trusted_root ) as f :
67
+ content = TRUST_CONFIG_TEMPLATE .substitute (trusted_root = f .read ())
68
+ temp_file .write (content )
69
+ command .extend (["--trust-config" , temp_file .name ])
70
+ temp_file .flush ()
71
+
72
+ # Fix-up the subcommand: the conformance suite uses `verify`, but
73
+ # `sigstore` requires `verify identity` for identity based verifications.
74
+ subcommand , * fixed_args = fixed_args
75
+ if subcommand == "sign" :
76
+ command .append ("sign" )
77
+ elif subcommand == "verify" :
78
+ command .extend (["verify" , "identity" ])
79
+ else :
80
+ raise ValueError (f"unsupported subcommand: { subcommand } " )
44
81
45
- # Replace incompatible flags.
46
- command .extend (ARG_REPLACEMENTS [arg ] if arg in ARG_REPLACEMENTS else arg for arg in fixed_args )
82
+ # Replace incompatible flags.
83
+ command .extend (
84
+ ARG_REPLACEMENTS [arg ] if arg in ARG_REPLACEMENTS else arg for arg in fixed_args
85
+ )
47
86
48
- os .execvp ("sigstore" , command )
87
+ os .execvp ("sigstore" , command )
0 commit comments