Skip to content

Commit 6394de6

Browse files
authored
Fix idempotency error when signing (#350)
Updates validation logic when fetching existing tlog entry to ensure we're comparing meaningful values with each other. Matches change done upstream in cosign: sigstore/cosign#3371
1 parent fee031c commit 6394de6

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

pkg/private/secant/tlog/tlog.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func getTlogEntry(ctx context.Context, rekorClient *client.Rekor, entryUUID stri
6464
return nil, err
6565
}
6666
for k, e := range resp.Payload {
67-
// Validate that request EntryUUID matches the response UUID and response Tree ID
68-
if err := isExpectedResponseUUID(entryUUID, k, *e.LogID); err != nil {
67+
// Validate that request EntryUUID matches the response UUID and response shard ID
68+
if err := isExpectedResponseUUID(entryUUID, k); err != nil {
6969
return nil, fmt.Errorf("unexpected entry returned from rekor server: %w", err)
7070
}
7171
// Check that body hash matches UUID
@@ -209,8 +209,8 @@ func GetTransparencyLogID(pub crypto.PublicKey) (string, error) {
209209
return hex.EncodeToString(digest[:]), nil
210210
}
211211

212-
// Validates UUID and also TreeID if present.
213-
func isExpectedResponseUUID(requestEntryUUID string, responseEntryUUID string, treeid string) error {
212+
// Validates UUID and also shard if present.
213+
func isExpectedResponseUUID(requestEntryUUID string, responseEntryUUID string) error {
214214
// Comparare UUIDs
215215
requestUUID, err := getUUID(requestEntryUUID)
216216
if err != nil {
@@ -223,19 +223,21 @@ func isExpectedResponseUUID(requestEntryUUID string, responseEntryUUID string, t
223223
if requestUUID != responseUUID {
224224
return fmt.Errorf("expected EntryUUID %s got UUID %s", requestEntryUUID, responseEntryUUID)
225225
}
226-
// Compare tree ID if it is in the request.
227-
requestTreeID, err := getTreeUUID(requestEntryUUID)
226+
// Compare shards if present in both request and response
227+
requestShardID, err := getTreeUUID(requestEntryUUID)
228228
if err != nil {
229229
return err
230230
}
231-
if requestTreeID != "" {
232-
tid, err := getTreeUUID(treeid)
233-
if err != nil {
234-
return err
235-
}
236-
if requestTreeID != tid {
237-
return fmt.Errorf("expected EntryUUID %s got UUID %s from Tree %s", requestEntryUUID, responseEntryUUID, treeid)
238-
}
231+
responseShardID, err := getTreeUUID(responseEntryUUID)
232+
if err != nil {
233+
return err
234+
}
235+
if requestShardID == "" || responseShardID == "" {
236+
return nil
237+
}
238+
239+
if requestShardID != responseShardID {
240+
return fmt.Errorf("expected UUID %s from shard %s: got UUID %s from shard %s", requestEntryUUID, responseEntryUUID, requestShardID, responseShardID)
239241
}
240242
return nil
241243
}

0 commit comments

Comments
 (0)