@@ -245,25 +245,21 @@ func (c *Client) updateRoots() error {
245
245
// Prepare for 5.3.11: If the timestamp and / or snapshot keys have been rotated,
246
246
// then delete the trusted timestamp and snapshot metadata files.
247
247
getKeyInfo := func (role string ) KeyInfo {
248
- //keyIDs := make([]string, 0, len(c.db.GetRole(role).KeyIDs))
249
248
keyIDs := make (map [string ]bool )
250
249
for k := range c .db .GetRole (role ).KeyIDs {
251
- //keyIDs = append(keyIDs, k)
252
250
keyIDs [k ] = true
253
251
}
254
- //sort.Strings(keyIDs)
255
252
return KeyInfo {keyIDs , c .db .GetRole (role ).Threshold }
256
253
}
257
254
258
- // The manifest looks like this:
255
+ // The nonRootKeyInfo looks like this:
259
256
// {
260
- // "timestamp": [ "KEYID1", "KEYID2"] ,
261
- // "snapshot": [ "KEYID3"] ,
262
- // "targets": [ "KEYID4", "KEYID5", "KEYID6"]
257
+ // "timestamp": {KeyIDs={ "KEYID1": true , "KEYID2": true}, Threshold=2} ,
258
+ // "snapshot": {KeyIDs={ "KEYID3": true}, Threshold=1} ,
259
+ // "targets": {KeyIDs={ "KEYID4": true , "KEYID5": true , "KEYID6": true}, Threshold=1}
263
260
// }
264
261
265
262
nonRootKeyInfo := map [string ]KeyInfo {"timestamp" : {}, "snapshot" : {}, "targets" : {}}
266
- //nonRootThreshold := map[string]int{"timestamp": 1, "snapshot": 1, "targets": 1}
267
263
for k := range nonRootKeyInfo {
268
264
nonRootKeyInfo [k ] = getKeyInfo (k )
269
265
}
@@ -299,9 +295,8 @@ func (c *Client) updateRoots() error {
299
295
if _ , ok := err .(ErrMissingRemoteMetadata ); ok {
300
296
// stop when the next root can't be downloaded
301
297
break
302
- } else {
303
- return err
304
298
}
299
+ return err
305
300
}
306
301
307
302
// 5.3.4 Check for an arbitrary software attack.
@@ -369,7 +364,11 @@ func (c *Client) updateRoots() error {
369
364
// timestamp -> delete timestamp.json
370
365
// snapshot -> delete timestamp.json and snapshot.json
371
366
// targets -> delete snapshot.json and targets.json
367
+ //
368
+ // nonRootKeyInfo contains the keys and thresholds from root.json
369
+ // that were on disk before the root update process begins.
372
370
for topLevelRolename := range nonRootKeyInfo {
371
+ // ki contains the keys and thresholds from the latest downloaded root.json.
373
372
ki := getKeyInfo (topLevelRolename )
374
373
if countDeleted (nonRootKeyInfo [topLevelRolename ].KeyIDs , ki .KeyIDs ) >= nonRootKeyInfo [topLevelRolename ].Threshold {
375
374
deleteMeta := map [string ][]string {
@@ -479,6 +478,7 @@ func (c *Client) loadAndVerifyLocalRootMeta() error {
479
478
return err
480
479
}
481
480
c .consistentSnapshot = root .ConsistentSnapshot
481
+ c .rootVer = root .Version
482
482
c .db = ndb
483
483
return nil
484
484
}
0 commit comments