Skip to content

Commit 49ab4e7

Browse files
authored
fix: make client shard aware when verifying (#280)
Signed-off-by: Asra Ali <[email protected]> Signed-off-by: Asra Ali <[email protected]>
1 parent 5bb13ef commit 49ab4e7

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

verifiers/internal/gha/rekor.go

+31-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ const (
4545
defaultRekorAddr = "https://rekor.sigstore.dev"
4646
)
4747

48-
func verifyRootHash(ctx context.Context, rekorClient *client.Rekor, eproof *models.InclusionProof, pub *ecdsa.PublicKey) error {
48+
func verifyRootHash(ctx context.Context, rekorClient *client.Rekor,
49+
treeID int64, eproof *models.InclusionProof, pub *ecdsa.PublicKey) error {
50+
treeIDString := fmt.Sprintf("%d", treeID)
4951
infoParams := tlog.NewGetLogInfoParamsWithContext(ctx)
5052
result, err := rekorClient.Tlog.GetLogInfo(infoParams)
5153
if err != nil {
@@ -58,6 +60,13 @@ func verifyRootHash(ctx context.Context, rekorClient *client.Rekor, eproof *mode
5860
if err := sth.UnmarshalText([]byte(*logInfo.SignedTreeHead)); err != nil {
5961
return err
6062
}
63+
for _, inactiveShard := range logInfo.InactiveShards {
64+
if *inactiveShard.TreeID == treeIDString {
65+
if err := sth.UnmarshalText([]byte(*inactiveShard.SignedTreeHead)); err != nil {
66+
return err
67+
}
68+
}
69+
}
6170

6271
verifier, err := signature.LoadVerifier(pub, crypto.SHA256)
6372
if err != nil {
@@ -122,22 +131,36 @@ func verifyTlogEntryByUUID(ctx context.Context, rekorClient *client.Rekor, entry
122131
return nil, err
123132
}
124133

125-
var e models.LogEntryAnon
126134
for k, entry := range lep.Payload {
127-
if k != uuid {
135+
returnUUID, err := sharding.GetUUIDFromIDString(k)
136+
if err != nil {
137+
return nil, err
138+
}
139+
// Validate that the request matches the response
140+
if returnUUID != uuid {
128141
return nil, errors.New("expected matching UUID")
129142
}
130-
e = entry
143+
return verifyTlogEntry(ctx, rekorClient, k, entry)
131144
}
132145

133-
return verifyTlogEntry(ctx, rekorClient, uuid, e)
146+
return nil, serrors.ErrorRekorSearch
134147
}
135148

136-
func verifyTlogEntry(ctx context.Context, rekorClient *client.Rekor, uuid string, e models.LogEntryAnon) (*models.LogEntryAnon, error) {
149+
func verifyTlogEntry(ctx context.Context, rekorClient *client.Rekor,
150+
entryUUID string, e models.LogEntryAnon) (*models.LogEntryAnon, error) {
137151
if e.Verification == nil || e.Verification.InclusionProof == nil {
138152
return nil, errors.New("inclusion proof not provided")
139153
}
140154

155+
uuid, err := sharding.GetUUIDFromIDString(entryUUID)
156+
if err != nil {
157+
return nil, fmt.Errorf("%w: retrieving uuid from entry uuid", err)
158+
}
159+
treeID, err := sharding.TreeID(entryUUID)
160+
if err != nil {
161+
return nil, fmt.Errorf("%w: retrieving tree ID", err)
162+
}
163+
141164
var hashes [][]byte
142165
for _, h := range e.Verification.InclusionProof.Hashes {
143166
hb, err := hex.DecodeString(h)
@@ -165,7 +188,8 @@ func verifyTlogEntry(ctx context.Context, rekorClient *client.Rekor, uuid string
165188
var entryVerError error
166189
for _, pubKey := range pubs {
167190
// Verify inclusion against the signed tree head
168-
entryVerError = verifyRootHash(ctx, rekorClient, e.Verification.InclusionProof, pubKey.PubKey)
191+
entryVerError = verifyRootHash(ctx, rekorClient, treeID,
192+
e.Verification.InclusionProof, pubKey.PubKey)
169193
if entryVerError == nil {
170194
break
171195
}

0 commit comments

Comments
 (0)