4
4
A wrapper to convert `sigstore-conformance` CLI protocol invocations to match `sigstore-python`.
5
5
"""
6
6
7
-
7
+ import json
8
8
import os
9
9
import sys
10
+ from contextlib import suppress
11
+ from string import Template
12
+ from tempfile import NamedTemporaryFile
13
+
14
+ # The signing config in this trust_config is not used: it's just here
15
+ # so the built trustconfig is complete
16
+ trust_config = {
17
+ "mediaType" : "application/vnd.dev.sigstore.clienttrustconfig.v0.1+json" ,
18
+ "SigningConfig" : {
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
+ }
10
28
11
29
SUBCMD_REPLACEMENTS = {
12
30
"sign-bundle" : "sign" ,
@@ -32,17 +50,39 @@ if "--staging" in fixed_args:
32
50
command .append ("--staging" )
33
51
fixed_args .remove ("--staging" )
34
52
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 } " )
53
+ # We may get "--trusted-root" as argument but sigstore-python wants "--trust-config":
54
+ trusted_root_path = None
55
+ with suppress (ValueError ):
56
+ i = fixed_args .index ("--trusted-root" )
57
+ trusted_root_path = fixed_args [i + 1 ]
58
+ fixed_args .pop (i )
59
+ fixed_args .pop (i )
60
+
61
+ # If we did get a trustedroot, write a matching trustconfig into a temp file
62
+ with NamedTemporaryFile (mode = "wt" ) as temp_file :
63
+ if trusted_root_path is not None :
64
+ with open (trusted_root_path ) as f :
65
+ trusted_root = json .load (f )
66
+ trust_config ["trustedRoot" ] = trusted_root
67
+
68
+ json .dump (trust_config , temp_file )
69
+ temp_file .flush ()
70
+
71
+ command .extend (["--trust-config" , temp_file .name ])
72
+
73
+ # Fix-up the subcommand: the conformance suite uses `verify`, but
74
+ # `sigstore` requires `verify identity` for identity based verifications.
75
+ subcommand , * fixed_args = fixed_args
76
+ if subcommand == "sign" :
77
+ command .append ("sign" )
78
+ elif subcommand == "verify" :
79
+ command .extend (["verify" , "identity" ])
80
+ else :
81
+ raise ValueError (f"unsupported subcommand: { subcommand } " )
44
82
45
- # Replace incompatible flags.
46
- command .extend (ARG_REPLACEMENTS [arg ] if arg in ARG_REPLACEMENTS else arg for arg in fixed_args )
83
+ # Replace incompatible flags.
84
+ command .extend (
85
+ ARG_REPLACEMENTS [arg ] if arg in ARG_REPLACEMENTS else arg for arg in fixed_args
86
+ )
47
87
48
- os .execvp ("sigstore" , command )
88
+ os .execvp ("sigstore" , command )
0 commit comments