forked from in-toto/in-toto-golang
-
Notifications
You must be signed in to change notification settings - Fork 5
/
sign.go
59 lines (45 loc) · 1.35 KB
/
sign.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"fmt"
"os"
intoto "github.com/boxboat/in-toto-golang/in_toto"
"github.com/spf13/cobra"
)
var outputPath string
var signCmd = &cobra.Command{
Use: "sign",
Short: "Provides command line interface to sign in-toto link or layout metadata",
Long: `Provides command line interface to sign in-toto link or layout metadata`,
Run: func(cmd *cobra.Command, args []string) {
var block intoto.Metablock
if err := block.Load(layoutPath); err != nil {
fmt.Println(err.Error())
}
//Load Keys
var layoutKey intoto.Key
if err := layoutKey.LoadKey(keyPath, "rsassa-pss-sha256", []string{"sha256", "sha512"}); err != nil {
fmt.Println("Invalid Key Error:", err.Error())
os.Exit(1)
}
//Sign
block.Sign(layoutKey)
block.Dump(outputPath)
},
}
func init() {
rootCmd.AddCommand(signCmd)
signCmd.Flags().StringVarP(&outputPath,
"output", "o", "",
`Path to store metadata file to be signed`)
signCmd.Flags().StringVarP(&layoutPath,
"file", "f", "",
`Path to link or layout file to be signed or verified.`)
signCmd.Flags().StringVarP(&keyPath,
"key", "k", "",
`Path to PEM formatted private key used to sign the passed
root layout's signature(s). Passing exactly one key using
'--layout-key' is required.`)
signCmd.MarkFlagRequired("file")
signCmd.MarkFlagRequired("key")
signCmd.MarkFlagRequired("output")
}