Skip to content

Commit

Permalink
improve error messages around bundle != payload hash (#3146)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh authored Jul 31, 2023
1 parent af555d5 commit b8c5997
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,16 @@ func VerifyBundle(sig oci.Signature, co *CheckOpts) (bool, error) {
}

alg, bundlehash, err := bundleHash(bundle.Payload.Body.(string), signature)
if err != nil {
return false, fmt.Errorf("computing bundle hash: %w", err)
}
h := sha256.Sum256(payload)
payloadHash := hex.EncodeToString(h[:])

if alg != "sha256" || bundlehash != payloadHash {
return false, fmt.Errorf("matching bundle to payload: %w", err)
if alg != "sha256" {
return false, fmt.Errorf("unexpected algorithm: %q", alg)
} else if bundlehash != payloadHash {
return false, fmt.Errorf("matching bundle to payload: bundle=%q, payload=%q", bundlehash, payloadHash)
}
return true, nil
}
Expand Down

0 comments on commit b8c5997

Please sign in to comment.