Skip to content

Commit

Permalink
add leaf hash verification (sigstore#1688)
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa authored and mlieberman85 committed May 6, 2022
1 parent 5d85a94 commit 3fdb767
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/cosign/tlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package cosign

import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/sha256"
Expand Down Expand Up @@ -297,6 +298,16 @@ func verifyTLogEntry(ctx context.Context, rekorClient *client.Rekor, uuid string
rootHash, _ := hex.DecodeString(*e.Verification.InclusionProof.RootHash)
leafHash, _ := hex.DecodeString(params.EntryUUID)

// Verify leaf hash matches hash of the entry body.
entryBytes, err := base64.StdEncoding.DecodeString(e.Body.(string))
if err != nil {
return nil, err
}
if !bytes.Equal(rfc6962.DefaultHasher.HashLeaf(entryBytes), leafHash) {
return nil, fmt.Errorf("computed leaf hash did not match entry UUID")
}

// Verify the inclusion proof.
v := logverifier.New(rfc6962.DefaultHasher)
if err := v.VerifyInclusionProof(*e.Verification.InclusionProof.LogIndex, *e.Verification.InclusionProof.TreeSize, hashes, rootHash, leafHash); err != nil {
return nil, errors.Wrap(err, "verifying inclusion proof")
Expand Down

0 comments on commit 3fdb767

Please sign in to comment.