@@ -19,10 +19,13 @@ import (
1919 "github.com/sigstore/cosign/v2/pkg/oci"
2020 "github.com/sigstore/cosign/v2/pkg/oci/signature"
2121 sig "github.com/sigstore/cosign/v2/pkg/signature"
22+ rekor "github.com/sigstore/rekor/pkg/client"
2223 "github.com/sigstore/sigstore/pkg/cryptoutils"
2324 sigtuf "github.com/sigstore/sigstore/pkg/tuf"
2425)
2526
27+ const DEFAULT_REKOR_URL string = "https://rekor.sigstore.dev"
28+
2629type Configuration struct {
2730 ImageDigest string `json:"ImageDigest"`
2831 RootsOfTrust []RootOfTrust `json:"RootsOfTrust"`
@@ -159,6 +162,10 @@ func generateCosignSignatureObjects(sigData SignatureData) ([]oci.Signature, err
159162 return signatures , nil
160163}
161164
165+ func printWarningLine (message string ) {
166+ fmt .Printf ("\033 [33m%s\033 [0m\n " , message )
167+ }
168+
162169func verify (imgDigest v1.Hash , rootOfTrust RootOfTrust , sigs []oci.Signature , proxy Proxy ) (satisfiedVerifiers []string , err error ) {
163170 ctx := context .Background ()
164171 cosignOptions := cosign.CheckOpts {ClaimVerifier : cosign .SimpleClaimVerifier }
@@ -169,22 +176,35 @@ func verify(imgDigest v1.Hash, rootOfTrust RootOfTrust, sigs []oci.Signature, pr
169176 for _ , verifier := range rootOfTrust .Verifiers {
170177 cosignOptions .SigVerifier = nil
171178 cosignOptions .Identities = nil
179+
172180 fmt .Printf (">> checking verifier %s\n " , verifier .Name )
173181 err = setVerifierCosignOptions (& cosignOptions , verifier , rootOfTrust , ctx )
174182 if err != nil {
175183 fmt .Printf ("ERROR: %s\n " , err .Error ())
176- } else {
177- for i , signature := range sigs {
178- fmt .Printf ("verifying signature %d\n " , i )
179- _ , err := cosign .VerifyImageSignature (ctx , signature , imgDigest , & cosignOptions )
180- if err != nil {
181- // the image is not signed by this verifier
182- fmt .Printf ("signature not verified: %s\n " , err .Error ())
183- } else {
184- fmt .Printf ("signature %d satisfies verifier %s\n " , i , verifier .Name )
185- satisfiedVerifiers = append (satisfiedVerifiers , fmt .Sprintf ("%s/%s" , rootOfTrust .Name , verifier .Name ))
186- break
187- }
184+ fmt .Println ("could not create valid cosign options for verifier, skipping verifier" )
185+ continue
186+ }
187+
188+ for i , signature := range sigs {
189+ bundle , err := signature .Bundle ()
190+ if err != nil {
191+ fmt .Printf ("error when retrieving bundle for signature, skipping signature: %s\n " , err .Error ())
192+ continue
193+ }
194+ if bundle == nil {
195+ printWarningLine ("no bundle found, any tlog verification must happen through network" )
196+ } else {
197+ fmt .Printf ("signature bundle: %s\n " , bundle .Payload .LogID )
198+ }
199+ fmt .Printf ("verifying signature %d\n " , i )
200+ _ , err = cosign .VerifyImageSignature (ctx , signature , imgDigest , & cosignOptions )
201+ if err != nil {
202+ // the image is not signed by this verifier
203+ fmt .Printf ("signature not verified: %s\n " , err .Error ())
204+ } else {
205+ fmt .Printf ("signature %d satisfies verifier %s\n " , i , verifier .Name )
206+ satisfiedVerifiers = append (satisfiedVerifiers , fmt .Sprintf ("%s/%s" , rootOfTrust .Name , verifier .Name ))
207+ break
188208 }
189209 }
190210 }
@@ -319,6 +339,12 @@ func setVerifierCosignOptions(cosignOptions *cosign.CheckOpts, verifier Verifier
319339 if rootOfTrust .SCTPublicKey == "" {
320340 cosignOptions .IgnoreSCT = true
321341 }
342+ } else {
343+ rekorClient , err := rekor .GetRekorClient (DEFAULT_REKOR_URL )
344+ if err != nil {
345+ return fmt .Errorf ("could not get rekor client for online tlog validation: %s" , err .Error ())
346+ }
347+ cosignOptions .RekorClient = rekorClient
322348 }
323349 if rootOfTrust .RootlessKeypairsOnly {
324350 cosignOptions .IgnoreSCT = true
0 commit comments