Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure a cert passed in via --cert matches the bundle cert #2652

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/cosign/cli/verify/verify_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,19 @@ 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)
if err != nil {
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))
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/cosign/cli/verify/verify_blob_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,21 @@ 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)
if err != nil {
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)
Expand Down