@@ -36,6 +36,7 @@ import (
36
36
"github.com/sigstore/rekor/pkg/generated/client/index"
37
37
"github.com/sigstore/rekor/pkg/generated/client/tlog"
38
38
"github.com/sigstore/rekor/pkg/generated/models"
39
+ "github.com/sigstore/rekor/pkg/sharding"
39
40
"github.com/sigstore/rekor/pkg/types"
40
41
intotod "github.com/sigstore/rekor/pkg/types/intoto/v0.0.1"
41
42
"github.com/sigstore/rekor/pkg/util"
@@ -188,7 +189,10 @@ func GetRekorEntriesWithCert(rClient *client.Rekor, artifactHash string, provena
188
189
return env , certs [0 ], nil
189
190
}
190
191
191
- func verifyRootHash (ctx context.Context , rekorClient * client.Rekor , proof * models.InclusionProof , pub * ecdsa.PublicKey ) error {
192
+ func verifyRootHash (ctx context.Context , rekorClient * client.Rekor ,
193
+ treeID int64 ,
194
+ proof * models.InclusionProof , pub * ecdsa.PublicKey ) error {
195
+ treeIDString := fmt .Sprintf ("%d" , treeID )
192
196
infoParams := tlog .NewGetLogInfoParamsWithContext (ctx )
193
197
result , err := rekorClient .Tlog .GetLogInfo (infoParams )
194
198
if err != nil {
@@ -201,6 +205,13 @@ func verifyRootHash(ctx context.Context, rekorClient *client.Rekor, proof *model
201
205
if err := sth .UnmarshalText ([]byte (* logInfo .SignedTreeHead )); err != nil {
202
206
return err
203
207
}
208
+ for _ , inactiveShard := range logInfo .InactiveShards {
209
+ if * inactiveShard .TreeID == treeIDString {
210
+ if err := sth .UnmarshalText ([]byte (* inactiveShard .SignedTreeHead )); err != nil {
211
+ return err
212
+ }
213
+ }
214
+ }
204
215
205
216
verifier , err := signature .LoadVerifier (pub , crypto .SHA256 )
206
217
if err != nil {
@@ -263,11 +274,20 @@ func verifyTlogEntryByUUID(ctx context.Context, rekorClient *client.Rekor, uuid
263
274
return verifyTlogEntry (ctx , rekorClient , params .EntryUUID , e )
264
275
}
265
276
266
- func verifyTlogEntry (ctx context.Context , rekorClient * client.Rekor , uuid string , e models.LogEntryAnon ) (* models.LogEntryAnon , error ) {
277
+ func verifyTlogEntry (ctx context.Context , rekorClient * client.Rekor , entryUUID string , e models.LogEntryAnon ) (* models.LogEntryAnon , error ) {
267
278
if e .Verification == nil || e .Verification .InclusionProof == nil {
268
279
return nil , errors .New ("inclusion proof not provided" )
269
280
}
270
281
282
+ uuid , err := sharding .GetUUIDFromIDString (entryUUID )
283
+ if err != nil {
284
+ return nil , fmt .Errorf ("%w: retrieving uuid from entry uuid" , err )
285
+ }
286
+ treeID , err := sharding .TreeID (entryUUID )
287
+ if err != nil {
288
+ return nil , fmt .Errorf ("%w: retrieving tree ID" , err )
289
+ }
290
+
271
291
hashes := [][]byte {}
272
292
for _ , h := range e .Verification .InclusionProof .Hashes {
273
293
hb , err := hex .DecodeString (h )
@@ -295,7 +315,8 @@ func verifyTlogEntry(ctx context.Context, rekorClient *client.Rekor, uuid string
295
315
var entryVerError error
296
316
for _ , pubKey := range pubs {
297
317
// Verify inclusion against the signed tree head
298
- entryVerError = verifyRootHash (ctx , rekorClient , e .Verification .InclusionProof , pubKey .PubKey )
318
+ entryVerError = verifyRootHash (ctx , rekorClient , treeID ,
319
+ e .Verification .InclusionProof , pubKey .PubKey )
299
320
if entryVerError == nil {
300
321
break
301
322
}
0 commit comments