diff --git a/cmd/cosign/cli/verify/verify_blob.go b/cmd/cosign/cli/verify/verify_blob.go index 7dc81bc5b39..678eed398e7 100644 --- a/cmd/cosign/cli/verify/verify_blob.go +++ b/cmd/cosign/cli/verify/verify_blob.go @@ -214,7 +214,7 @@ func (c *VerifyBlobCmd) Exec(ctx context.Context, blobRef string) error { if isb64(certBytes) { certBytes, _ = base64.StdEncoding.DecodeString(b.Cert) } - cert, err = loadCertFromPEM(certBytes) + bundleCert, err := loadCertFromPEM(certBytes) if err != nil { // check if cert is actually a public key co.SigVerifier, err = sigs.LoadPublicKeyRaw(certBytes, crypto.SHA256) @@ -222,6 +222,11 @@ func (c *VerifyBlobCmd) Exec(ctx context.Context, blobRef string) error { return fmt.Errorf("loading verifier from bundle: %w", err) } } + // if a cert was passed in, make sure it matches the cert in the bundle + if cert != nil && !cert.Equal(bundleCert) { + return fmt.Errorf("the cert passed in does not match the cert in the provided bundle") + } + cert = bundleCert } opts = append(opts, static.WithBundle(b.Bundle)) } diff --git a/cmd/cosign/cli/verify/verify_blob_attestation.go b/cmd/cosign/cli/verify/verify_blob_attestation.go index 38491a47bbd..da04d2010cf 100644 --- a/cmd/cosign/cli/verify/verify_blob_attestation.go +++ b/cmd/cosign/cli/verify/verify_blob_attestation.go @@ -251,7 +251,7 @@ func (c *VerifyBlobAttestationCommand) Exec(ctx context.Context, artifactPath st if isb64(certBytes) { certBytes, _ = base64.StdEncoding.DecodeString(b.Cert) } - cert, err = loadCertFromPEM(certBytes) + bundleCert, err := loadCertFromPEM(certBytes) if err != nil { // check if cert is actually a public key co.SigVerifier, err = sigs.LoadPublicKeyRaw(certBytes, crypto.SHA256) @@ -259,7 +259,13 @@ func (c *VerifyBlobAttestationCommand) Exec(ctx context.Context, artifactPath st return fmt.Errorf("loading verifier from bundle: %w", err) } } + // if a cert was passed in, make sure it matches the cert in the bundle + if cert != nil && !cert.Equal(bundleCert) { + return fmt.Errorf("the cert passed in does not match the cert in the provided bundle") + } + cert = bundleCert } + encodedSig, err = base64.StdEncoding.DecodeString(b.Base64Signature) if err != nil { return fmt.Errorf("decoding signature: %w", err)