Skip to content

Commit 9c52bb0

Browse files
authored
fix: make client shard aware when verifying entries on inactive shards (#278)
Signed-off-by: Asra Ali <[email protected]> Signed-off-by: Asra Ali <[email protected]>
1 parent 76a59d8 commit 9c52bb0

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

main_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func Test_runVerify(t *testing.T) {
309309
name: "rekor upload bypassed",
310310
artifact: "binary-linux-amd64-no-tlog-upload",
311311
source: "github.com/slsa-framework/example-package",
312-
err: pkg.ErrorRekorSearch,
312+
err: pkg.ErrorNoValidRekorEntries,
313313
noversion: true,
314314
},
315315
{
@@ -323,7 +323,7 @@ func Test_runVerify(t *testing.T) {
323323
name: "malicious: invalid signature expired certificate",
324324
artifact: "binary-linux-amd64-expired-cert",
325325
source: "github.com/slsa-framework/example-package",
326-
err: pkg.ErrorRekorSearch,
326+
err: pkg.ErrorNoValidRekorEntries,
327327
noversion: true,
328328
},
329329
}

pkg/provenance.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/sigstore/rekor/pkg/generated/client/index"
3737
"github.com/sigstore/rekor/pkg/generated/client/tlog"
3838
"github.com/sigstore/rekor/pkg/generated/models"
39+
"github.com/sigstore/rekor/pkg/sharding"
3940
"github.com/sigstore/rekor/pkg/types"
4041
intotod "github.com/sigstore/rekor/pkg/types/intoto/v0.0.1"
4142
"github.com/sigstore/rekor/pkg/util"
@@ -188,7 +189,10 @@ func GetRekorEntriesWithCert(rClient *client.Rekor, artifactHash string, provena
188189
return env, certs[0], nil
189190
}
190191

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)
192196
infoParams := tlog.NewGetLogInfoParamsWithContext(ctx)
193197
result, err := rekorClient.Tlog.GetLogInfo(infoParams)
194198
if err != nil {
@@ -201,6 +205,13 @@ func verifyRootHash(ctx context.Context, rekorClient *client.Rekor, proof *model
201205
if err := sth.UnmarshalText([]byte(*logInfo.SignedTreeHead)); err != nil {
202206
return err
203207
}
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+
}
204215

205216
verifier, err := signature.LoadVerifier(pub, crypto.SHA256)
206217
if err != nil {
@@ -263,11 +274,20 @@ func verifyTlogEntryByUUID(ctx context.Context, rekorClient *client.Rekor, uuid
263274
return verifyTlogEntry(ctx, rekorClient, params.EntryUUID, e)
264275
}
265276

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) {
267278
if e.Verification == nil || e.Verification.InclusionProof == nil {
268279
return nil, errors.New("inclusion proof not provided")
269280
}
270281

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+
271291
hashes := [][]byte{}
272292
for _, h := range e.Verification.InclusionProof.Hashes {
273293
hb, err := hex.DecodeString(h)
@@ -295,7 +315,8 @@ func verifyTlogEntry(ctx context.Context, rekorClient *client.Rekor, uuid string
295315
var entryVerError error
296316
for _, pubKey := range pubs {
297317
// 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)
299320
if entryVerError == nil {
300321
break
301322
}

0 commit comments

Comments
 (0)