@@ -27,6 +27,7 @@ import (
2727 coptions "github.com/sigstore/cosign/v3/cmd/cosign/cli/options"
2828 "github.com/sigstore/cosign/v3/cmd/cosign/cli/rekor"
2929 "github.com/sigstore/cosign/v3/pkg/cosign"
30+ "github.com/sigstore/cosign/v3/pkg/oci"
3031
3132 ociremote "github.com/sigstore/cosign/v3/pkg/oci/remote"
3233 "github.com/sigstore/sigstore/pkg/cryptoutils"
@@ -81,6 +82,7 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e
8182 }
8283
8384 checkOpts := & cosign.CheckOpts {}
85+ checkOpts .NewBundleFormat = true
8486
8587 ro := coptions.RegistryOptions {}
8688 co , err := ro .ClientOpts (ctx )
@@ -147,10 +149,25 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e
147149}
148150
149151// Verify verifies the authenticity of the given ref OCI image.
152+ // Both cosign v2 signatures and cosign v3 bundles are supported by
153+ // attempting to discover bundles before verification.
154+ // Bundles can be located either via the OCI 1.1 referrer API or an
155+ // OCI 1.0 referrer tag.
150156// It returns a boolean indicating if the verification was successful.
151157// It returns an error if the verification fails, nil otherwise.
152158func (v * CosignVerifier ) Verify (ctx context.Context , ref name.Reference ) (soci.VerificationResult , error ) {
153- signatures , _ , err := cosign .VerifyImageSignatures (ctx , ref , v .opts )
159+ var signatures []oci.Signature
160+ // copy options since we'll need to change them based on bundle discovery on the ref
161+ opts := * v .opts
162+ newBundles , _ , err := cosign .GetBundles (ctx , ref , opts .RegistryClientOpts )
163+ if len (newBundles ) == 0 || err != nil {
164+ opts .NewBundleFormat = false
165+ signatures , _ , err = cosign .VerifyImageSignatures (ctx , ref , & opts )
166+ } else {
167+ opts .NewBundleFormat = true
168+ signatures , _ , err = cosign .VerifyImageAttestations (ctx , ref , & opts )
169+ }
170+ fmt .Println (opts .NewBundleFormat , v .opts .NewBundleFormat )
154171 if err != nil {
155172 return soci .VerificationResultFailed , err
156173 }
0 commit comments