Skip to content

Commit 6e1d194

Browse files
BaptisteFoyrdimitrov
authored andcommitted
fix(localMeta): Ignore deleted delegated targets
Signed-off-by: Baptiste Foy <[email protected]>
1 parent 582126a commit 6e1d194

File tree

87 files changed

+3119
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3119
-1
lines changed

client/client.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/hex"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io"
910

@@ -493,10 +494,25 @@ func (c *Client) getDelegationPathFromRaw(snapshot *data.Snapshot, delegatedTarg
493494
return nil, err
494495
}
495496
for targetPath := range targets.Targets {
497+
// Gets target file from remote store
496498
_, resp, err := c.getTargetFileMetaDelegationPath(targetPath, snapshot)
497499
// We only need to test one targets file:
498500
// - If it is valid, it means the delegated targets has been validated
499501
// - If it is not, the delegated targets isn't valid
502+
if errors.As(err, &ErrMissingRemoteMetadata{}) {
503+
// As this function is used to fill the local store cache, the targets
504+
// will be downloaded from the remote store as the local store cache is
505+
// empty, meaning that the delegated targets may not exist anymore. In
506+
// that case, we can't get the delegation path. Ignore the delegated targets.
507+
return nil, nil
508+
}
509+
if errors.As(err, &ErrUnknownTarget{}) {
510+
// As this function is used to fill the local store cache, the target file
511+
// will be downloaded from the remote store as the local store cache is
512+
// empty, meaning that the target file may not exist anymore. In
513+
// that case, ignore the file and try another.
514+
continue
515+
}
500516
return resp, err
501517
}
502518
return nil, nil

client/delegations_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,30 @@ func TestPersistedMeta(t *testing.T) {
251251
}
252252
}
253253

254+
func TestGetDelegationPathWithNoTargetFile(t *testing.T) {
255+
// In this test, we have created a target file c.txt for a delegation
256+
// c.json, then we remove that target file and check if c.json is loaded
257+
// in the localMeta. It shouldn't as it has no target file at all and shouldn't
258+
// be used.
259+
verify.IsExpired = func(t time.Time) bool { return false }
260+
client, closer := initTestDelegationClient(t, "testdata/php-tuf-fixtures/TUFTestFixture2LevelDelegation")
261+
defer closer()
262+
_, err := client.Update()
263+
assert.Nil(t, err)
264+
265+
err = client.getLocalMeta()
266+
assert.Nil(t, err)
267+
268+
_, ok := client.localMeta["a.json"]
269+
assert.True(t, ok)
270+
271+
_, ok = client.localMeta["b.json"]
272+
assert.True(t, ok)
273+
274+
_, ok = client.localMeta["c.json"]
275+
assert.False(t, ok)
276+
}
277+
254278
func versionOfStoredTargets(name string, store map[string]json.RawMessage) (int64, error) {
255279
rawTargets, ok := store[name]
256280
if !ok {
@@ -296,7 +320,7 @@ func initTestDelegationClient(t *testing.T, dirPrefix string) (*Client, func() e
296320
}
297321
name := f.Name()
298322
// ignoring consistent snapshot when loading initial state
299-
if len(strings.Split(name, ".")) == 1 && strings.HasSuffix(name, ".json") {
323+
if len(strings.Split(name, ".")) < 3 && strings.HasSuffix(name, ".json") {
300324
rawFile, err := os.ReadFile(initialStateDir + "/" + name)
301325
assert.Nil(t, err)
302326
assert.Nil(t, c.local.SetMeta(name, rawFile))
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"signatures": [
3+
{
4+
"keyid": "05e17c1501d627b2597322f80d33aacec6f30a507552d3326a88913422b0e30b",
5+
"sig": "72b215c194090407abc8b7c513d69fd340abbe63037d26cbc2e4dd88c095a14da8d6e4aae0561f265e97d5c658b0260be2031af73c26e157e5f062c5f4aceb00"
6+
}
7+
],
8+
"signed": {
9+
"_type": "targets",
10+
"delegations": {
11+
"keys": {
12+
"718fedad390b4d0d470b890781eb8c94e5a7e975aebe65fc0862246c945fce68": {
13+
"keyid_hash_algorithms": [
14+
"sha256",
15+
"sha512"
16+
],
17+
"keytype": "ed25519",
18+
"keyval": {
19+
"public": "82f52e4503dbb364fabe8e5567f1cf909d4175d45468a021dfe75653db9ac98c"
20+
},
21+
"scheme": "ed25519"
22+
},
23+
"9ca81f7ff17f6218246474a51b47eb035741bc472557ef5ac493e279f446b85b": {
24+
"keyid_hash_algorithms": [
25+
"sha256",
26+
"sha512"
27+
],
28+
"keytype": "ed25519",
29+
"keyval": {
30+
"public": "06e4dee0de7826c8d539a6112940b7459892b4ecaf696e67dc064aea0923f95c"
31+
},
32+
"scheme": "ed25519"
33+
}
34+
},
35+
"roles": [
36+
{
37+
"keyids": [
38+
"718fedad390b4d0d470b890781eb8c94e5a7e975aebe65fc0862246c945fce68"
39+
],
40+
"name": "b",
41+
"paths": [
42+
"*.txt"
43+
],
44+
"terminating": false,
45+
"threshold": 1
46+
},
47+
{
48+
"keyids": [
49+
"9ca81f7ff17f6218246474a51b47eb035741bc472557ef5ac493e279f446b85b"
50+
],
51+
"name": "c",
52+
"paths": [
53+
"*.txt"
54+
],
55+
"terminating": false,
56+
"threshold": 1
57+
}
58+
]
59+
},
60+
"expires": "2020-04-01T07:27:10Z",
61+
"spec_version": "1.0.0",
62+
"targets": {
63+
"a.txt": {
64+
"custom": {},
65+
"hashes": {
66+
"sha256": "3f90cedf303207851bbdc5f857e018daf93b4c0083306cef17df547b42e4e985",
67+
"sha512": "f4631ef7ea7b015d7b88e411842fafeb78a72f0181bec72ea9754604ede74ea0e491bf8411659aabc96304fc764d0131ce49ba86066ab5f7b7480dde719e0bfd"
68+
},
69+
"length": 15
70+
}
71+
},
72+
"version": 1
73+
}
74+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"signatures": [
3+
{
4+
"keyid": "718fedad390b4d0d470b890781eb8c94e5a7e975aebe65fc0862246c945fce68",
5+
"sig": "6a4f4bb63d7b6db4b6c09ce081fd229052ca087c98d25653c8d187de04dbedfc219aa9482774b939d84eb404fd51cfe383f9ea65e19a1d3cc79b642701bcff0d"
6+
}
7+
],
8+
"signed": {
9+
"_type": "targets",
10+
"delegations": {
11+
"keys": {},
12+
"roles": []
13+
},
14+
"expires": "2020-04-01T07:27:10Z",
15+
"spec_version": "1.0.0",
16+
"targets": {
17+
"b.txt": {
18+
"custom": {},
19+
"hashes": {
20+
"sha256": "949c6a4318dabe8bbd140cef99ea669ba031919ccf9bce0f5b4d0b61d1c0aa2e",
21+
"sha512": "f4cc9ce5c73b37e2a6707af7a0ea614ea5fa428bd2509e3af4528a5d330ce98a09c4dd98c859ad9b27b8aba24e1eacbf1af8393fdbfed899cecb995c87a11e3c"
22+
},
23+
"length": 15
24+
}
25+
},
26+
"version": 1
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"signatures": [
3+
{
4+
"keyid": "9ca81f7ff17f6218246474a51b47eb035741bc472557ef5ac493e279f446b85b",
5+
"sig": "9f0c5ef7e0a11012256c4a47ed757f9e90e930238f6a6e5c758a014f1b768519acb2b7d9aa9bd0456d71ba09b032598086e42d832830391e307c926c16f5b303"
6+
}
7+
],
8+
"signed": {
9+
"_type": "targets",
10+
"delegations": {
11+
"keys": {},
12+
"roles": []
13+
},
14+
"expires": "2020-04-01T07:27:10Z",
15+
"spec_version": "1.0.0",
16+
"targets": {
17+
"c.txt": {
18+
"custom": {},
19+
"hashes": {
20+
"sha256": "946e2ea9180de673891ae09ce0edfb207966bc32bd6324ebdad2c50c82075ffd",
21+
"sha512": "ddb5fb256a368d778b5fdd03d497ad79944c766245f3cccfc8b098b14c488ec424a68b86a6a2add36db4ef0f0214f15dbe0d63fbc5ca7a9619fb4c39544d78a9"
22+
},
23+
"length": 15
24+
}
25+
},
26+
"version": 1
27+
}
28+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"signatures": [
3+
{
4+
"keyid": "d4dab4b4d68b91665a6d0dac5b4e64677aa6d853fc787669168b4b4ba9822129",
5+
"sig": "d0bf76a5cfc0aee1b8a1b1bf0ed8ca646a1a6d5f205945c515e8546bfd3c1e6b5e07cc0b93836bd030dd05ba68f177aecb05f6bf90c6702fd178e53310022506"
6+
}
7+
],
8+
"signed": {
9+
"_type": "root",
10+
"consistent_snapshot": true,
11+
"expires": "2020-12-31T05:48:20Z",
12+
"keys": {
13+
"3a05831328273e4b821c3bbe1fed0c5332749d8e071675879af26a401a5c85ae": {
14+
"keyid_hash_algorithms": [
15+
"sha256",
16+
"sha512"
17+
],
18+
"keytype": "ed25519",
19+
"keyval": {
20+
"public": "6bac59b8d9e1aae02fae6fba6e7fe3fc9fe5b4a9fe98c3fca255d8c8ec3e5b35"
21+
},
22+
"scheme": "ed25519"
23+
},
24+
"77dfdca206c0fe1b8e55d67d21dd0e195a0998a9d2b56c6d3ee8f68d04c21e93": {
25+
"keyid_hash_algorithms": [
26+
"sha256",
27+
"sha512"
28+
],
29+
"keytype": "ed25519",
30+
"keyval": {
31+
"public": "6400d770c7c1bce4b3d59ce0079ed686e843b6500bbea77d869a1ae7df4565a1"
32+
},
33+
"scheme": "ed25519"
34+
},
35+
"d4dab4b4d68b91665a6d0dac5b4e64677aa6d853fc787669168b4b4ba9822129": {
36+
"keyid_hash_algorithms": [
37+
"sha256",
38+
"sha512"
39+
],
40+
"keytype": "ed25519",
41+
"keyval": {
42+
"public": "28bf74baa87ed923f8fa27e3292684f8ec4730ce0bdc65150ed58199206ce089"
43+
},
44+
"scheme": "ed25519"
45+
},
46+
"e4dae3872d28d29f7624a702bfd25f68453544d597229ee9e0a8569d1f940cf4": {
47+
"keyid_hash_algorithms": [
48+
"sha256",
49+
"sha512"
50+
],
51+
"keytype": "ed25519",
52+
"keyval": {
53+
"public": "e6ae9d3b67d7b3ce274130291dd90287f32b8fd72bfb4ac5430859ebd1c28a46"
54+
},
55+
"scheme": "ed25519"
56+
}
57+
},
58+
"roles": {
59+
"root": {
60+
"keyids": [
61+
"d4dab4b4d68b91665a6d0dac5b4e64677aa6d853fc787669168b4b4ba9822129"
62+
],
63+
"threshold": 1
64+
},
65+
"snapshot": {
66+
"keyids": [
67+
"77dfdca206c0fe1b8e55d67d21dd0e195a0998a9d2b56c6d3ee8f68d04c21e93"
68+
],
69+
"threshold": 1
70+
},
71+
"targets": {
72+
"keyids": [
73+
"e4dae3872d28d29f7624a702bfd25f68453544d597229ee9e0a8569d1f940cf4"
74+
],
75+
"threshold": 1
76+
},
77+
"timestamp": {
78+
"keyids": [
79+
"3a05831328273e4b821c3bbe1fed0c5332749d8e071675879af26a401a5c85ae"
80+
],
81+
"threshold": 1
82+
}
83+
},
84+
"spec_version": "1.0.0",
85+
"version": 1
86+
}
87+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"signatures": [
3+
{
4+
"keyid": "77dfdca206c0fe1b8e55d67d21dd0e195a0998a9d2b56c6d3ee8f68d04c21e93",
5+
"sig": "61db8765350398f7f750853337d9a55c5d6e790812d29146b5b45d5fd43d2a42c474a7a9fab263c3a50a28114a82f79dbf24ff1f99ae737a8d06f332f9f7d103"
6+
}
7+
],
8+
"signed": {
9+
"_type": "snapshot",
10+
"expires": "2020-01-08T00:00:00Z",
11+
"meta": {
12+
"targets.json": {
13+
"version": 1
14+
}
15+
},
16+
"spec_version": "1.0.0",
17+
"version": 1
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"signatures": [
3+
{
4+
"keyid": "e4dae3872d28d29f7624a702bfd25f68453544d597229ee9e0a8569d1f940cf4",
5+
"sig": "c150e8ed5d352f366a979f4c4b9d556350c414c2da7ef1279045aaed3438c60872142d0dfe5ddbb627fec2d8fb7c5d8e692e04a87230b78d74714c5db035620a"
6+
}
7+
],
8+
"signed": {
9+
"_type": "targets",
10+
"delegations": {
11+
"keys": {},
12+
"roles": []
13+
},
14+
"expires": "2020-04-01T07:27:10Z",
15+
"spec_version": "1.0.0",
16+
"targets": {},
17+
"version": 1
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"signatures": [
3+
{
4+
"keyid": "3a05831328273e4b821c3bbe1fed0c5332749d8e071675879af26a401a5c85ae",
5+
"sig": "1d668531c7a0960cf90825faa684106a8aef0799c1b47e72301bac45d87f2dd42c14f1a3ac7db862323ca5177dd4fd686573ea92aea99638f17414dde561c00b"
6+
}
7+
],
8+
"signed": {
9+
"_type": "timestamp",
10+
"expires": "2020-01-02T00:00:00Z",
11+
"meta": {
12+
"snapshot.json": {
13+
"hashes": {
14+
"sha256": "f4ca389c2c9fbc592d91d4e693c31113b8803a11bcb5ecd973581fa0e3d34ce0",
15+
"sha512": "92a0989e44c0e9f16d3e56268a3b8dd4e4416ee2ac91a4c871a405f1e426062651ec4effa0078fc4409c8b0422ccad9b1aa197db58f178406f398562b2e98195"
16+
},
17+
"length": 431,
18+
"version": 1
19+
}
20+
},
21+
"spec_version": "1.0.0",
22+
"version": 1
23+
}
24+
}

0 commit comments

Comments
 (0)