Skip to content

Commit 6f09245

Browse files
authored
Merge pull request #224 from adityasaky/add-verify-flag
Add --verify to sign subcommand
2 parents 0e8e784 + 939fbff commit 6f09245

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

cmd/sign.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
var (
1111
outputPath string
12+
verifyFile bool
1213
)
1314

1415
var signCmd = &cobra.Command{
@@ -26,7 +27,7 @@ func init() {
2627
"output",
2728
"o",
2829
"",
29-
`Path to store metadata file to be signed`,
30+
`Path to store metadata file after signing`,
3031
)
3132

3233
signCmd.Flags().StringVarP(
@@ -47,9 +48,15 @@ root layout's signature(s). Passing exactly one key using
4748
'--key' is required.`,
4849
)
4950

51+
signCmd.Flags().BoolVar(
52+
&verifyFile,
53+
"verify",
54+
false,
55+
"Verify signature of signed file",
56+
)
57+
5058
signCmd.MarkFlagRequired("file")
5159
signCmd.MarkFlagRequired("key")
52-
signCmd.MarkFlagRequired("output")
5360
}
5461

5562
func sign(cmd *cobra.Command, args []string) error {
@@ -64,6 +71,16 @@ func sign(cmd *cobra.Command, args []string) error {
6471
return fmt.Errorf("invalid key at %s: %w", keyPath, err)
6572
}
6673

74+
if verifyFile {
75+
if err := layoutMb.VerifySignature(key); err != nil {
76+
return fmt.Errorf("signature verification failed: %w", err)
77+
}
78+
return nil
79+
}
80+
81+
if len(outputPath) == 0 {
82+
outputPath = layoutPath
83+
}
6784
layoutMb.Sign(key)
6885
layoutMb.Dump(outputPath)
6986

doc/in-toto_sign.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ in-toto sign [flags]
1818
-k, --key string Path to PEM formatted private key used to sign the passed
1919
root layout's signature(s). Passing exactly one key using
2020
'--key' is required.
21-
-o, --output string Path to store metadata file to be signed
21+
-o, --output string Path to store metadata file after signing
22+
--verify Verify signature of signed file
2223
```
2324

2425
### SEE ALSO

0 commit comments

Comments
 (0)