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
|
// Package main provides a utility named ct-sans.
//
// Install:
//
// go install gitlab.torproject.org/rgdd/ct/cmd/ct-sans@latest
//
// Usage:
//
// $ ct-sans -h
package main
import (
"flag"
"fmt"
"os"
"git.cs.kau.se/rasmoste/ct-sans/internal/ctflag"
)
const usage = `ct-sans collects SANs in CT-logged certificates
Usage:
ct-sans snapshot [-d DIRECTORY]
Refresh log lists, signed tree heads, and timestamps
ct-sans collect [-d DIRECTORY]
Collect SANs with regards to the current snapshot
ct-sans assemble [-d DIRECTORY]
Assemble a dataset manifest and print a command that combines,
sorts, and removes duplicate SANs that were collected.
Help:
ct-sans [-h] [--help]
Options:
-d, --directory: The ct-sans working directory (Default: "ct-sans")
`
type options struct {
Directory string
logDirectory string
metadataFile string
metadataSignatureFile string
metadataTimestampFile string
sthFile string
stateFile string
sansFile string
workersPerLog uint64
batchSize uint64
persistSize uint64
}
func main() {
if ctflag.WantHelp(os.Args, 1) {
fmt.Fprintf(os.Stderr, usage)
os.Exit(1)
}
// Define command-line options
fs := ctflag.NewFlagSet()
opts := options{}
ctflag.String(&fs, &opts.Directory, "directory", "d", "ct-sans")
// Parse command-line options and hardcode default values
if err := ctflag.Parse(fs, os.Args[2:]); err != nil {
if err == flag.ErrHelp {
fmt.Fprintf(os.Stderr, usage)
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "error: %v\n\n", err)
os.Exit(2)
}
opts.logDirectory = opts.Directory + "/" + "logs"
opts.metadataFile = "metadata.json"
opts.metadataSignatureFile = "metadata.sig"
opts.metadataTimestampFile = "metadata.sig"
opts.sthFile = "sth.json"
opts.stateFile = "th.json"
opts.sansFile = "sans.lst"
opts.workersPerLog = 10
opts.batchSize = 16384
opts.persistSize = 256
// Hand-over to the respective subcommands
var err error
switch cmd := os.Args[1]; cmd {
case "snapshot":
err = snapshot(opts)
case "collect":
err = collect(opts)
case "assemble":
err = assemble(opts)
default:
fmt.Fprintf(os.Stderr, "ct-sans: unknown command %q\n\n", cmd)
os.Exit(3)
}
if err != nil {
fmt.Fprintf(os.Stderr, "ct-sans %s: error: %v\n", os.Args[1], err)
os.Exit(4)
}
}
|