Skip to content

Commit a46f297

Browse files
nsmith5dmitris
authored andcommitted
Support keyless verification without Fulcio roots
Fixes sigstore#2630 Signed-off-by: Nathan Smith <nathan@nfsmith.ca>
1 parent 771e323 commit a46f297

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

cmd/cosign/cli/verify/verify.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,30 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
171171
}
172172
}
173173
if keylessVerification(c.KeyRef, c.Sk) {
174-
// This performs an online fetch of the Fulcio roots. This is needed
175-
// for verifying keyless certificates (both online and offline).
176-
co.RootCerts, err = fulcio.GetRoots()
177-
if err != nil {
178-
return fmt.Errorf("getting Fulcio roots: %w", err)
179-
}
180-
co.IntermediateCerts, err = fulcio.GetIntermediates()
181-
if err != nil {
182-
return fmt.Errorf("getting Fulcio intermediates: %w", err)
174+
if c.CertChain != "" {
175+
chain, err := loadCertChainFromFileOrURL(c.CertChain)
176+
if err != nil {
177+
return err
178+
}
179+
co.RootCerts = x509.NewCertPool()
180+
co.RootCerts.AddCert(chain[len(chain)-1])
181+
if len(chain) > 1 {
182+
co.IntermediateCerts = x509.NewCertPool()
183+
for _, cert := range chain[:len(chain)-1] {
184+
co.IntermediateCerts.AddCert(cert)
185+
}
186+
}
187+
} else {
188+
// This performs an online fetch of the Fulcio roots. This is needed
189+
// for verifying keyless certificates (both online and offline).
190+
co.RootCerts, err = fulcio.GetRoots()
191+
if err != nil {
192+
return fmt.Errorf("getting Fulcio roots: %w", err)
193+
}
194+
co.IntermediateCerts, err = fulcio.GetIntermediates()
195+
if err != nil {
196+
return fmt.Errorf("getting Fulcio intermediates: %w", err)
197+
}
183198
}
184199
}
185200
keyRef := c.KeyRef

0 commit comments

Comments
 (0)