| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/json" |
| 5 |
"fmt" |
| 6 |
"os" |
| 7 |
|
| 8 |
"github.com/flynn/go-docopt" |
| 9 |
tuf "github.com/theupdateframework/go-tuf" |
| 10 |
) |
| 11 |
|
| 12 |
func init() { |
| 13 |
register("sign-payload", cmdSignPayload, ` |
| 14 |
usage: tuf sign-payload --role=<role> <path> |
| 15 |
|
| 16 |
Sign a file (outside of the TUF repo) using keys for the given role (from the TUF repo). |
| 17 |
|
| 18 |
Typically, path will be the output of "tuf payload". |
| 19 |
`) |
| 20 |
} |
| 21 |
|
| 22 |
func cmdSignPayload(args *docopt.Args, repo *tuf.Repo) error { |
| 23 |
payload, err := os.ReadFile(args.String["<path>"]) |
| 24 |
if err != nil { |
| 25 |
return err |
| 26 |
} |
| 27 |
|
| 28 |
signatures, err := repo.SignRaw(args.String["--role"], payload) |
| 29 |
if err != nil { |
| 30 |
return err |
| 31 |
} |
| 32 |
fmt.Fprintln(os.Stderr, "tuf: signed") |
| 33 |
|
| 34 |
bytes, err := json.Marshal(signatures) |
| 35 |
if err != nil { |
| 36 |
return err |
| 37 |
} |
| 38 |
fmt.Fprint(os.Stdout, string(bytes)) |
| 39 |
|
| 40 |
return nil |
| 41 |
} |