Skip to content

Commit fd8ac04

Browse files
feat: Support delegated targets roles in repo writer (#175)
* Support delegated targets roles in repo writer * Add back return err in writeTopLevelTargetWithExpires * Remove space * Move hash bin impl to pkg/targets * Fix build after rebase * Make AddTargetsWithDigest support delegated targets * Remove unused GetPublicKeys * Revert "Remove unused GetPublicKeys" This reverts commit 3daaeeb. * Fix typo * Easier hash bin usage when setting up delegations * Remove comment that ChangePassphrase doesn't support delegated roles * Update comments * Add API to reset delegations * clean up verifySignatures * Fix tests for ChangePassphrase * Fix comments * Deduplicate key IDs when setting up hash bins * Revert "Revert "Remove unused GetPublicKeys"" This reverts commit dbe6a4d. * Add warning about GetSigners. TODO: fix usage * Clean up some usage of setMetawithSigners * Remove setMetaWithSigners since it's easy to misuse * cleanup * cleanup * Cleanup usage of delegatorDBs * Simplify AddTargetsWithExpiresToPreferredRole * Remove debugging * Remove targetsMetaWithSigners * Fix comment * Turn FIXME into an issue * Fix comment position * Remove out-of-place comment * Add missing hyphen * Test delegations construction more rigorously * Support removing delegated targets files * Fix tests * Add more tests for delegation * Fix unchecked error * Clarify comment * Better naming * Support delegated targets in Sign and AddOrUpdateSignature * Add test for ResetTargetsDelegationsWithExpires * Improve naming of delegation methods * Update tests for int64 version numbers * Add tests for Sign and AddOrUpdateSignature with delegations * Remove unused functions in errors.go * Remove commented out test code * Add test to verify that adding a delegation to an existing role doesn't change signed targets * Fix SignMessage usage in test with new canonicalization pattern Co-authored-by: Ethan Lowman <[email protected]>
1 parent e2fb0ae commit fd8ac04

File tree

6 files changed

+1327
-188
lines changed

6 files changed

+1327
-188
lines changed

client/errors.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package client
33
import (
44
"errors"
55
"fmt"
6-
7-
"github.com/theupdateframework/go-tuf/verify"
86
)
97

108
var (
@@ -49,20 +47,6 @@ func (e ErrMaxDelegations) Error() string {
4947
return fmt.Sprintf("tuf: max delegation of %d reached searching for %s with snapshot version %d", e.MaxDelegations, e.Target, e.SnapshotVersion)
5048
}
5149

52-
//lint:ignore U1000 unused
53-
func isDecodeFailedWithErrRoleThreshold(err error) bool {
54-
e, ok := err.(ErrDecodeFailed)
55-
if !ok {
56-
return false
57-
}
58-
return isErrRoleThreshold(e.Err)
59-
}
60-
61-
func isErrRoleThreshold(err error) bool {
62-
_, ok := err.(verify.ErrRoleThreshold)
63-
return ok
64-
}
65-
6650
type ErrNotFound struct {
6751
File string
6852
}

errors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@ type ErrPassphraseRequired struct {
8888
func (e ErrPassphraseRequired) Error() string {
8989
return fmt.Sprintf("tuf: a passphrase is required to access the encrypted %s keys file", e.Role)
9090
}
91+
92+
type ErrNoDelegatedTarget struct {
93+
Path string
94+
}
95+
96+
func (e ErrNoDelegatedTarget) Error() string {
97+
return fmt.Sprintf("tuf: no delegated target for path %s", e.Path)
98+
}

local_store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/theupdateframework/go-tuf/data"
1616
"github.com/theupdateframework/go-tuf/encrypted"
17-
"github.com/theupdateframework/go-tuf/internal/roles"
1817
"github.com/theupdateframework/go-tuf/internal/sets"
1918
"github.com/theupdateframework/go-tuf/pkg/keys"
2019
"github.com/theupdateframework/go-tuf/util"
@@ -43,6 +42,8 @@ type LocalStore interface {
4342
Commit(bool, map[string]int64, map[string]data.Hashes) error
4443

4544
// GetSigners return a list of signers for a role.
45+
// This may include revoked keys, so the signers should not
46+
// be used without filtering.
4647
GetSigners(role string) ([]keys.Signer, error)
4748

4849
// SaveSigner adds a signer to a role.
@@ -222,8 +223,7 @@ func (f *fileSystemStore) stagedDir() string {
222223
}
223224

224225
func isMetaFile(e os.DirEntry) (bool, error) {
225-
name := e.Name()
226-
if e.IsDir() || !(filepath.Ext(name) == ".json" && roles.IsTopLevelManifest(name)) {
226+
if e.IsDir() || filepath.Ext(e.Name()) != ".json" {
227227
return false, nil
228228
}
229229

0 commit comments

Comments
 (0)