@@ -34,12 +34,21 @@ var idToken *string
34
34
var intoto * bool
35
35
var tsa * bool
36
36
var rekor * bool
37
+ var signingconfigPath string
38
+ var trustedrootPath string
37
39
38
40
func init () {
39
41
idToken = flag .String ("id-token" , "" , "OIDC token to send to Fulcio" )
40
42
intoto = flag .Bool ("in-toto" , false , "Content to sign is in-toto document" )
41
43
tsa = flag .Bool ("tsa" , false , "Include signed timestamp from timestamp authority" )
42
44
rekor = flag .Bool ("rekor" , false , "Including transparency log entry from Rekor" )
45
+
46
+ flag .StringVar (& signingconfigPath , "signing-config" , "" , "Path to signingconfig JSON file" )
47
+ flag .StringVar (& signingconfigPath , "s" , "" , "Path to signingconfig JSON file" )
48
+
49
+ flag .StringVar (& trustedrootPath , "trusted-root" , "" , "Path to trusted root JSON file" )
50
+ flag .StringVar (& trustedrootPath , "t" , "" , "Path to trusted root JSON file" )
51
+
43
52
flag .Parse ()
44
53
if flag .NArg () == 0 {
45
54
usage ()
@@ -83,79 +92,96 @@ func main() {
83
92
84
93
opts := sign.BundleOptions {}
85
94
86
- // Get trusted_root.json
87
- fetcher := fetcher.DefaultFetcher {}
88
- fetcher .SetHTTPUserAgent (util .ConstructUserAgent ())
89
-
90
- tufOptions := & tuf.Options {
91
- Root : tuf .StagingRoot (),
92
- RepositoryBaseURL : tuf .StagingMirror ,
93
- Fetcher : & fetcher ,
94
- }
95
- tufClient , err := tuf .New (tufOptions )
96
- if err != nil {
97
- log .Fatal (err )
98
- }
95
+ var signingConfig * root.SigningConfig
99
96
100
- trustedRoot , err := root .GetTrustedRoot (tufClient )
101
- if err != nil {
102
- log .Fatal (err )
97
+ // A trusted root is not required but we will load one if
98
+ // * it is given as argument or
99
+ // * we are using default signing config (as in that case we know which trusted root to use)
100
+ if trustedrootPath != "" {
101
+ opts .TrustedRoot , err = root .NewTrustedRootFromPath (trustedrootPath )
102
+ if err != nil {
103
+ log .Fatal (err )
104
+ }
105
+ } else if signingconfigPath == "" {
106
+ // Get staging trusted_root.json by default
107
+ fetcher := fetcher.DefaultFetcher {}
108
+ fetcher .SetHTTPUserAgent (util .ConstructUserAgent ())
109
+
110
+ tufOptions := & tuf.Options {
111
+ Root : tuf .StagingRoot (),
112
+ RepositoryBaseURL : tuf .StagingMirror ,
113
+ Fetcher : & fetcher ,
114
+ }
115
+ tufClient , err := tuf .New (tufOptions )
116
+ if err != nil {
117
+ log .Fatal (err )
118
+ }
119
+ opts .TrustedRoot , err = root .GetTrustedRoot (tufClient )
120
+ if err != nil {
121
+ log .Fatal (err )
122
+ }
103
123
}
104
124
105
- // TODO: Uncomment once an updated v0.2 SigningConfig is distributed
106
- // via TUF
107
- // signingConfigPGI, err := root.GetSigningConfig(tufClient)
108
-
109
- signingConfig , err := root .NewSigningConfig (
110
- root .SigningConfigMediaType02 ,
111
- // Fulcio URLs
112
- []root.Service {
113
- {
114
- URL : "https://fulcio.sigstage.dev" ,
115
- MajorAPIVersion : 1 ,
116
- ValidityPeriodStart : time .Now ().Add (- time .Hour ),
117
- ValidityPeriodEnd : time .Now ().Add (time .Hour ),
125
+ if signingconfigPath != "" {
126
+ signingConfig , err = root .NewSigningConfigFromPath (signingconfigPath )
127
+ if err != nil {
128
+ log .Fatal (err )
129
+ }
130
+ } else {
131
+ // TODO: Uncomment once an updated v0.2 SigningConfig is distributed
132
+ // via TUF
133
+ // signingConfigPGI, err := root.GetSigningConfig(tufClient)
134
+
135
+ // for now we hard code the staging services here
136
+ signingConfig , err = root .NewSigningConfig (
137
+ root .SigningConfigMediaType02 ,
138
+ // Fulcio URLs
139
+ []root.Service {
140
+ {
141
+ URL : "https://fulcio.sigstage.dev" ,
142
+ MajorAPIVersion : 1 ,
143
+ ValidityPeriodStart : time .Now ().Add (- time .Hour ),
144
+ ValidityPeriodEnd : time .Now ().Add (time .Hour ),
145
+ },
118
146
},
119
- },
120
- // OIDC Provider URLs
121
- []root. Service {
122
- {
123
- URL : "https://oauth2.sigstage.dev/auth" ,
124
- MajorAPIVersion : 1 ,
125
- ValidityPeriodStart : time .Now ().Add (- time .Hour ),
126
- ValidityPeriodEnd : time . Now (). Add ( time . Hour ) ,
147
+ // OIDC Provider URLs
148
+ []root. Service {
149
+ {
150
+ URL : "https://oauth2.sigstage.dev/auth" ,
151
+ MajorAPIVersion : 1 ,
152
+ ValidityPeriodStart : time . Now (). Add ( - time . Hour ) ,
153
+ ValidityPeriodEnd : time .Now ().Add (time .Hour ),
154
+ } ,
127
155
},
128
- },
129
- // Rekor URLs
130
- []root. Service {
131
- {
132
- URL : "https://rekor.sigstage.dev" ,
133
- MajorAPIVersion : 1 ,
134
- ValidityPeriodStart : time .Now ().Add (- time .Hour ),
135
- ValidityPeriodEnd : time . Now (). Add ( time . Hour ) ,
156
+ // Rekor URLs
157
+ []root. Service {
158
+ {
159
+ URL : "https://rekor.sigstage.dev" ,
160
+ MajorAPIVersion : 1 ,
161
+ ValidityPeriodStart : time . Now (). Add ( - time . Hour ) ,
162
+ ValidityPeriodEnd : time .Now ().Add (time .Hour ),
163
+ } ,
136
164
},
137
- },
138
- root.ServiceConfiguration {
139
- Selector : v1 .ServiceSelector_ANY ,
140
- },
141
- []root.Service {
142
- {
143
- URL : "https://timestamp.githubapp.com/api/v1/timestamp" ,
144
- MajorAPIVersion : 1 ,
145
- ValidityPeriodStart : time .Now ().Add (- time .Hour ),
146
- ValidityPeriodEnd : time .Now ().Add (time .Hour ),
165
+ root.ServiceConfiguration {
166
+ Selector : v1 .ServiceSelector_ANY ,
147
167
},
148
- },
149
- root.ServiceConfiguration {
150
- Selector : v1 .ServiceSelector_ANY ,
151
- },
152
- )
153
- if err != nil {
154
- log .Fatal (err )
168
+ []root.Service {
169
+ {
170
+ URL : "https://timestamp.sigstage.dev/api/v1/timestamp" ,
171
+ MajorAPIVersion : 1 ,
172
+ ValidityPeriodStart : time .Now ().Add (- time .Hour ),
173
+ ValidityPeriodEnd : time .Now ().Add (time .Hour ),
174
+ },
175
+ },
176
+ root.ServiceConfiguration {
177
+ Selector : v1 .ServiceSelector_ANY ,
178
+ },
179
+ )
180
+ if err != nil {
181
+ log .Fatal (err )
182
+ }
155
183
}
156
184
157
- opts .TrustedRoot = trustedRoot
158
-
159
185
if * idToken != "" {
160
186
fulcioURL , err := root .SelectService (signingConfig .FulcioCertificateAuthorityURLs (), []uint32 {1 }, time .Now ())
161
187
if err != nil {
0 commit comments