Skip to content

Commit

Permalink
feat: Support delegated targets roles in repo writer (#175)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mnm678 and ethan-lowman-dd authored Apr 19, 2022
1 parent e2fb0ae commit fd8ac04
Show file tree
Hide file tree
Showing 6 changed files with 1,327 additions and 188 deletions.
16 changes: 0 additions & 16 deletions client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"errors"
"fmt"

"github.com/theupdateframework/go-tuf/verify"
)

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

//lint:ignore U1000 unused
func isDecodeFailedWithErrRoleThreshold(err error) bool {
e, ok := err.(ErrDecodeFailed)
if !ok {
return false
}
return isErrRoleThreshold(e.Err)
}

func isErrRoleThreshold(err error) bool {
_, ok := err.(verify.ErrRoleThreshold)
return ok
}

type ErrNotFound struct {
File string
}
Expand Down
8 changes: 8 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ type ErrPassphraseRequired struct {
func (e ErrPassphraseRequired) Error() string {
return fmt.Sprintf("tuf: a passphrase is required to access the encrypted %s keys file", e.Role)
}

type ErrNoDelegatedTarget struct {
Path string
}

func (e ErrNoDelegatedTarget) Error() string {
return fmt.Sprintf("tuf: no delegated target for path %s", e.Path)
}
6 changes: 3 additions & 3 deletions local_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/theupdateframework/go-tuf/data"
"github.com/theupdateframework/go-tuf/encrypted"
"github.com/theupdateframework/go-tuf/internal/roles"
"github.com/theupdateframework/go-tuf/internal/sets"
"github.com/theupdateframework/go-tuf/pkg/keys"
"github.com/theupdateframework/go-tuf/util"
Expand Down Expand Up @@ -43,6 +42,8 @@ type LocalStore interface {
Commit(bool, map[string]int64, map[string]data.Hashes) error

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

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

func isMetaFile(e os.DirEntry) (bool, error) {
name := e.Name()
if e.IsDir() || !(filepath.Ext(name) == ".json" && roles.IsTopLevelManifest(name)) {
if e.IsDir() || filepath.Ext(e.Name()) != ".json" {
return false, nil
}

Expand Down
Loading

0 comments on commit fd8ac04

Please sign in to comment.