Skip to content

Commit

Permalink
Merge pull request #224 from adityasaky/add-verify-flag
Browse files Browse the repository at this point in the history
Add --verify to sign subcommand
  • Loading branch information
adityasaky committed Apr 25, 2023
2 parents 0e8e784 + 939fbff commit 6f09245
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

var (
outputPath string
verifyFile bool
)

var signCmd = &cobra.Command{
Expand All @@ -26,7 +27,7 @@ func init() {
"output",
"o",
"",
`Path to store metadata file to be signed`,
`Path to store metadata file after signing`,
)

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

signCmd.Flags().BoolVar(
&verifyFile,
"verify",
false,
"Verify signature of signed file",
)

signCmd.MarkFlagRequired("file")
signCmd.MarkFlagRequired("key")
signCmd.MarkFlagRequired("output")
}

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

if verifyFile {
if err := layoutMb.VerifySignature(key); err != nil {
return fmt.Errorf("signature verification failed: %w", err)
}
return nil
}

if len(outputPath) == 0 {
outputPath = layoutPath
}
layoutMb.Sign(key)
layoutMb.Dump(outputPath)

Expand Down
3 changes: 2 additions & 1 deletion doc/in-toto_sign.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ in-toto sign [flags]
-k, --key string Path to PEM formatted private key used to sign the passed
root layout's signature(s). Passing exactly one key using
'--key' is required.
-o, --output string Path to store metadata file to be signed
-o, --output string Path to store metadata file after signing
--verify Verify signature of signed file
```

### SEE ALSO
Expand Down

0 comments on commit 6f09245

Please sign in to comment.