@@ -59,7 +59,7 @@ type VerifyCommand struct {
59
59
CertGithubWorkflowName string
60
60
CertGithubWorkflowRepository string
61
61
CertGithubWorkflowRef string
62
- CertBundle string
62
+ CARoots string
63
63
CertChain string
64
64
CertOidcProvider string
65
65
IgnoreSCT bool
@@ -174,29 +174,47 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
174
174
}
175
175
}
176
176
if keylessVerification (c .KeyRef , c .Sk ) {
177
- if c .CertChain != "" {
178
- chain , err := loadCertChainFromFileOrURL (c .CertChain )
179
- if err != nil {
180
- return err
181
- }
182
- co .RootCerts = x509 .NewCertPool ()
183
- co .RootCerts .AddCert (chain [len (chain )- 1 ])
184
- if len (chain ) > 1 {
185
- co .IntermediateCerts = x509 .NewCertPool ()
186
- for _ , cert := range chain [:len (chain )- 1 ] {
187
- co .IntermediateCerts .AddCert (cert )
177
+ switch {
178
+ case c .CertChain != "" :
179
+ {
180
+ chain , err := loadCertChainFromFileOrURL (c .CertChain )
181
+ if err != nil {
182
+ return err
183
+ }
184
+ co .RootCerts = x509 .NewCertPool ()
185
+ co .RootCerts .AddCert (chain [len (chain )- 1 ])
186
+ if len (chain ) > 1 {
187
+ co .IntermediateCerts = x509 .NewCertPool ()
188
+ for _ , cert := range chain [:len (chain )- 1 ] {
189
+ co .IntermediateCerts .AddCert (cert )
190
+ }
188
191
}
189
192
}
190
- } else {
191
- // This performs an online fetch of the Fulcio roots. This is needed
192
- // for verifying keyless certificates (both online and offline).
193
- co .RootCerts , err = fulcio .GetRoots ()
194
- if err != nil {
195
- return fmt .Errorf ("getting Fulcio roots: %w" , err )
193
+ case c .CARoots != "" :
194
+ {
195
+ caRoots , err := loadCertChainFromFileOrURL (c .CARoots )
196
+ if err != nil {
197
+ return err
198
+ }
199
+ co .RootCerts = x509 .NewCertPool ()
200
+ if len (caRoots ) > 0 {
201
+ for _ , cert := range caRoots {
202
+ co .RootCerts .AddCert (cert )
203
+ }
204
+ }
196
205
}
197
- co .IntermediateCerts , err = fulcio .GetIntermediates ()
198
- if err != nil {
199
- return fmt .Errorf ("getting Fulcio intermediates: %w" , err )
206
+ default :
207
+ {
208
+ // This performs an online fetch of the Fulcio roots. This is needed
209
+ // for verifying keyless certificates (both online and offline).
210
+ co .RootCerts , err = fulcio .GetRoots ()
211
+ if err != nil {
212
+ return fmt .Errorf ("getting Fulcio roots: %w" , err )
213
+ }
214
+ co .IntermediateCerts , err = fulcio .GetIntermediates ()
215
+ if err != nil {
216
+ return fmt .Errorf ("getting Fulcio intermediates: %w" , err )
217
+ }
200
218
}
201
219
}
202
220
}
@@ -238,8 +256,8 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
238
256
if err != nil {
239
257
return err
240
258
}
241
- if c .CertChain == "" {
242
- // If no certChain is passed, the Fulcio root certificate will be used
259
+ if c .CertChain == "" && c . CARoots == "" {
260
+ // If no certChain and no CARoots are passed, the Fulcio root certificate will be used
243
261
co .RootCerts , err = fulcio .GetRoots ()
244
262
if err != nil {
245
263
return fmt .Errorf ("getting Fulcio roots: %w" , err )
@@ -253,14 +271,21 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
253
271
return err
254
272
}
255
273
} else {
256
- // Verify certificate with chain
257
- chain , err := loadCertChainFromFileOrURL (c .CertChain )
258
- if err != nil {
259
- return err
260
- }
261
- pubKey , err = cosign .ValidateAndUnpackCertWithChain (cert , chain , co )
262
- if err != nil {
263
- return err
274
+ if c .CARoots == "" {
275
+ // Verify certificate with chain
276
+ chain , err := loadCertChainFromFileOrURL (c .CertChain )
277
+ if err != nil {
278
+ return err
279
+ }
280
+ pubKey , err = cosign .ValidateAndUnpackCertWithChain (cert , chain , co )
281
+ if err != nil {
282
+ return err
283
+ }
284
+ } else {
285
+ pubKey , err = cosign .ValidateAndUnpackCertWithCertPools (cert , co )
286
+ if err != nil {
287
+ return err
288
+ }
264
289
}
265
290
}
266
291
if c .SCTRef != "" {
0 commit comments