@@ -471,6 +471,61 @@ func (s *ClientSuite) TestUpdateRoots(c *C) {
471
471
}
472
472
}
473
473
474
+ func (s * ClientSuite ) TestFastForwardAttackRecovery (c * C ) {
475
+ var tests = []struct {
476
+ fixturePath string
477
+ expectMetaDeleted map [string ]bool
478
+ }{
479
+ // No non-root-metadata recovery if root keys are revoked only.
480
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_2_threshold_4_root" ,
481
+ map [string ]bool {"root.json" : false , "timestamp.json" : false , "snapshot.json" : false , "targets.json" : false }},
482
+ // No non-root-metadata recovery if root keys are revoked only even threshold number of root keys are revoked.
483
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_4_threshold_4_root" ,
484
+ map [string ]bool {"root.json" : false , "timestamp.json" : false , "snapshot.json" : false , "targets.json" : false }},
485
+ // No snapshot metadata recovery less than threashold keys changed.
486
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_2_threshold_4_snapshot" ,
487
+ map [string ]bool {"root.json" : false , "timestamp.json" : false , "snapshot.json" : false , "targets.json" : false }},
488
+ // Delete snapshot and timestamp metadata if threashold number of keys changed.
489
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_4_threshold_4_snapshot" ,
490
+ map [string ]bool {"root.json" : false , "timestamp.json" : true , "snapshot.json" : true , "targets.json" : false }},
491
+ // No targets metadata recovery less than threashold keys changed.
492
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_2_threshold_4_targets" ,
493
+ map [string ]bool {"root.json" : false , "timestamp.json" : false , "snapshot.json" : false , "targets.json" : false }},
494
+ // Delete targets and snapshot metadata if threashold number of keys changed.
495
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_4_threshold_4_targets" ,
496
+ map [string ]bool {"root.json" : false , "timestamp.json" : false , "snapshot.json" : true , "targets.json" : true }},
497
+ // No timestamp metadata recovery less than threashold keys changed.
498
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_2_threshold_4_timestamp" ,
499
+ map [string ]bool {"root.json" : false , "timestamp.json" : false , "snapshot.json" : false , "targets.json" : false }},
500
+ // Delete timestamp metadata if threashold number of keys changed.
501
+ {"testdata/PublishedTwiceMultiKeysadd_9_revoke_4_threshold_4_timestamp" ,
502
+ map [string ]bool {"root.json" : false , "timestamp.json" : true , "snapshot.json" : false , "targets.json" : false }},
503
+ }
504
+ for _ , test := range tests {
505
+ e := verify .IsExpired
506
+ verify .IsExpired = func (t time.Time ) bool { return false }
507
+ tufClient , closer := initRootTest (c , test .fixturePath , true )
508
+ c .Assert (tufClient .updateRoots (), IsNil )
509
+ m , err := tufClient .local .GetMeta ()
510
+ c .Assert (err , IsNil )
511
+ for md , deleted := range test .expectMetaDeleted {
512
+ if deleted {
513
+ if _ , ok := m [md ]; ok {
514
+ c .Fatalf ("Metadata %s is not deleted!" , md )
515
+ }
516
+ } else {
517
+ if _ , ok := m [md ]; ! ok {
518
+ c .Fatalf ("Metadata %s deleted!" , md )
519
+ }
520
+ }
521
+ }
522
+ closer ()
523
+ verify .IsExpired = e
524
+
525
+ }
526
+
527
+ }
528
+
474
529
func (s * ClientSuite ) TestNewTargets (c * C ) {
475
530
client := s .newClient (c )
476
531
files , err := client .Update ()
0 commit comments