Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add-signature to read from stdin #534

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ Typically, `path` will be a file containing the output of `tuf payload`.

See also `tuf add-signatures`.

#### `tuf add-signatures --signatures <sig_file> <metadata>`

#### `tuf add-signatures [--signatures <sig_file>] [--format=<format>] [--key-id=<key-id>] <metadata>`

Adds signatures (the output of `tuf sign-payload`) to the given role metadata file.

If the signature does not verify, it will not be added.
If the signature does not verify, it will not be added. Signature can be a json file
or json passed in via `stdin`.

#### `tuf status --valid-at <date> <role>`

Expand Down
21 changes: 16 additions & 5 deletions cmd/tuf/add_signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (

func init() {
register("add-signatures", cmdAddSignature, `
usage: tuf add-signatures --signatures=<sig_file> [--format=<format>] [--key-id=<key-id>] <metadata>
usage: tuf add-signatures [--signatures <sig_file>] [--format=<format>] [--key-id=<key-id>] <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.

Options:
--signatures=<sig_file> the path to the file containing the signature(s)
--signatures=<sig_file> The path to the file containing the signatures to add. If not present, the contents are read from stdin
--format=<format> One of 'json', 'hex', or 'base64'. Defaults to 'json'
--key-id=<key-id> The key-id of the signature being added. Only required if the format is not 'json'
`)
Expand All @@ -30,9 +30,20 @@ func cmdAddSignature(args *docopt.Args, repo *tuf.Repo) error {
roleFilename := args.String["<metadata>"]

f := args.String["--signatures"]
sigBytes, err := os.ReadFile(f)
if err != nil {
return err
var sigBytes []byte
var err error
if f != "" {
sigBytes, err = os.ReadFile(f)
mnm678 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
} else {
var input string
_, err := fmt.Scan(&input)
rdimitrov marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
sigBytes = []byte(input)
}
sigs := []data.Signature{}
switch args.String["--format"] {
Expand Down
Loading