-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add `payload` and `add-signature` commands. Fixes #205. * docs: Clarify `payload` and `add-signature` args. Specifically, they expect a metadata file name, *not* a role name. Added a test for each. * feat: Add `sign-payload` command. This completes the offline flow: ```shell tuf payload root.json > /tmp/root.json.payload tuf sign-payload --role=root /tmp/root.json.payload > /tmp/root.json.sigs tuf add-signatures --signatures /tmp/root.json.sigs root.json ``` Additional changes: - rename `add-signature` to `add-signatures` - `add-signatures` expects JSON (from `sign-payload`) rather than hex bytes * docs: Beef up documentation for offline signature flow. - move CLI commands to matching file names - add examples to README.md - more details for `repo.SignPayload` docs * docs: Point out where keys are stored in `sign-payload` docs * fix: ensure that output is canonicalized * style: rename ErrInsufficientKeys to ErrNoKeys * doc: minor `tuf sign-payload` clarifiation * test: add client test for offline flow * test: fix tests after rebase
- Loading branch information
Showing
9 changed files
with
306 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/flynn/go-docopt" | ||
"github.com/theupdateframework/go-tuf" | ||
"github.com/theupdateframework/go-tuf/data" | ||
) | ||
|
||
func init() { | ||
register("add-signatures", cmdAddSignature, ` | ||
usage: tuf add-signatures --signatures <sig_file> <metadata> | ||
Adds signatures (the output of "sign-payload") to the given role metadata file. | ||
If the signature does not verify, it will not be added. | ||
`) | ||
} | ||
|
||
func cmdAddSignature(args *docopt.Args, repo *tuf.Repo) error { | ||
roleFilename := args.String["<metadata>"] | ||
|
||
f := args.String["<sig_file>"] | ||
sigBytes, err := os.ReadFile(f) | ||
if err != nil { | ||
return err | ||
} | ||
sigs := []data.Signature{} | ||
if err = json.Unmarshal(sigBytes, &sigs); err != nil { | ||
return err | ||
} | ||
for _, sig := range sigs { | ||
if err = repo.AddOrUpdateSignature(roleFilename, sig); err != nil { | ||
return err | ||
} | ||
} | ||
fmt.Fprintln(os.Stderr, "tuf: added", len(sigs), "new signature(s)") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/flynn/go-docopt" | ||
"github.com/theupdateframework/go-tuf" | ||
) | ||
|
||
func init() { | ||
register("payload", cmdPayload, ` | ||
usage: tuf payload <metadata> | ||
Outputs the metadata file for a role in a ready-to-sign (canonicalized) format. | ||
`) | ||
} | ||
|
||
func cmdPayload(args *docopt.Args, repo *tuf.Repo) error { | ||
p, err := repo.Payload(args.String["<metadata>"]) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(string(p)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/flynn/go-docopt" | ||
tuf "github.com/theupdateframework/go-tuf" | ||
tufdata "github.com/theupdateframework/go-tuf/data" | ||
) | ||
|
||
func init() { | ||
register("sign-payload", cmdSignPayload, ` | ||
usage: tuf sign-payload --role=<role> <path> | ||
Sign a file (outside of the TUF repo) using keys for the given role (from the TUF repo). | ||
Typically, path will be the output of "tuf payload". | ||
`) | ||
} | ||
|
||
func cmdSignPayload(args *docopt.Args, repo *tuf.Repo) error { | ||
payload, err := os.ReadFile(args.String["<path>"]) | ||
if err != nil { | ||
return err | ||
} | ||
signed := tufdata.Signed{Signed: payload, Signatures: make([]tufdata.Signature, 0)} | ||
|
||
numKeys, err := repo.SignPayload(args.String["--role"], &signed) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bytes, err := json.Marshal(signed.Signatures) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(string(bytes)) | ||
|
||
fmt.Fprintln(os.Stderr, "tuf: signed with", numKeys, "key(s)") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.