Skip to content

Commit 70116aa

Browse files
authored
perf: improve GetDefaultTUFOptions logic (#108)
Note: this little change allow to use 'root.json' if the file is available in the cache. This strategy allows fix the behavior where the `root.json` included is tuf package has higher precedence over the version downloaded from the remote. In some circumstance the content embedded in tuf package is outdated and should not been taken in account.
1 parent 6355e60 commit 70116aa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/transparency/utils/verifier/verifier.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ func GetDefaultTUFOptions(optionalClient ...utils.HTTPClient) *tuf.Options {
7373
// Store TUF cache in a directory owned by tpmtb for better isolation
7474
opts.CachePath = filepath.Join(cache.CacheDir(), ".sigstore", "root")
7575

76+
// Attempt to load the trusted root from the local cache if it exists
77+
// Note: it can happen that the `root.json` included in `tuf` package is outdated
78+
rootPath := filepath.Join(opts.CachePath, tuf.URLToPath("https://tuf-repo-cdn.sigstore.dev"), "root.json")
79+
if utils.FileExists(rootPath) {
80+
if b, err := utils.ReadFile(rootPath); err == nil {
81+
opts.Root = b
82+
}
83+
}
84+
7685
// Rely on cache to avoid unnecessary network calls
7786
// the package will automatically refresh the cache once key material expires
7887
opts.ForceCache = true

0 commit comments

Comments
 (0)