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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// package main provides a tool named sigsum-debug.
//
// Build as follows:
//
// $ go build -ldflags="-X 'main.someVersion=git commit $(git rev-list -1 HEAD)'"
// $ mv sigsum-debug $GOPATH/bin/
//
// Usage:
//
// $ sigsum-debug help
//
package main
import (
"flag"
"fmt"
"log"
"os"
"git.sigsum.org/sigsum-tools-go/cmd/sigsum-debug/genkey"
"git.sigsum.org/sigsum-tools-go/cmd/sigsum-debug/hashkey"
"git.sigsum.org/sigsum-tools-go/cmd/sigsum-debug/hashleaf"
"git.sigsum.org/sigsum-tools-go/cmd/sigsum-debug/pubkey"
"git.sigsum.org/sigsum-tools-go/cmd/sigsum-debug/sign"
"git.sigsum.org/sigsum-tools-go/internal/options"
)
const usage = `sigsum-debug version %s
Usage:
sigsum-debug help
Outputs a usage message.
sigsum-debug genkey
Outputs a new private key.
sigsum-debug pubkey
Reads a private key from stdin and output its public key.
sigsum-debug hashkey
Reads a public key from stdin and output its key hash.
sigsum-debug hashleaf -k PRIVATE_KEY [-s SHARD_HINT]
Reads data from STDIN and outputs a leaf hash.
-k, --private-key Private key to sign with
-s, --shard-hint Shard hint to use (Default: 0)
sigsum-debug sign -k PRIVATE_KEY [-s SHARD_HINT]
Reads data from STDIN and outputs a signature.
-k, --private-key Private key to sign with
-s, --shard-hint Shard hint to use (Default: 0)
sigsum-debug cosign -w WIT_PRIV -l LOG_PUB
Reads an ASCII signed tree head from STDIN and outputs a cosignature.
-w, --witness-priv Witness private key to sign with
-l, --log-pub Log public key to verify signed tree head
`
var (
optPriv string
optPub string
optShardHint uint64
someVersion = "devel"
)
func main() {
log.SetFlags(0)
var err error
cmd := options.Parse(printUsage, setOptions)
switch cmd.Name() {
case "help":
cmd.Usage()
case "genkey":
err = genkey.Main(cmd.Args())
case "pubkey":
err = pubkey.Main(cmd.Args())
case "hashkey":
err = hashkey.Main(cmd.Args())
case "hashleaf":
err = hashleaf.Main(cmd.Args(), optPriv, optShardHint)
case "sign":
err = sign.Main(cmd.Args(), optPriv, optShardHint)
case "cosign":
err = fmt.Errorf("TODO")
default:
err = fmt.Errorf("invalid command %q, try %q", cmd.Name(), "sigsum help")
}
if err != nil {
log.Printf("%s", err)
os.Exit(1)
}
}
func printUsage() {
log.Printf(usage, someVersion)
}
func setOptions(fs *flag.FlagSet) {
switch cmd := fs.Name(); cmd {
case "hashleaf":
options.AddString(fs, &optPriv, "k", "key", "")
options.AddUint64(fs, &optShardHint, "s", "shard-hint", 0)
case "sign":
options.AddString(fs, &optPriv, "k", "key", "")
options.AddUint64(fs, &optShardHint, "s", "shard-hint", 0)
case "cosign":
options.AddString(fs, &optPriv, "w", "--witness-priv", "")
options.AddString(fs, &optPub, "l", "--log-pub", "")
}
}
|