aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assemble.go7
-rw-r--r--go.mod2
-rw-r--r--main.go102
3 files changed, 111 insertions, 0 deletions
diff --git a/assemble.go b/assemble.go
new file mode 100644
index 0000000..246ba6e
--- /dev/null
+++ b/assemble.go
@@ -0,0 +1,7 @@
+package main
+
+import "fmt"
+
+func assemble(opts options) error {
+ return fmt.Errorf("TODO")
+}
diff --git a/go.mod b/go.mod
index 9622183..400b49a 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
module git.cs.kau.se/rasmoste/ct-sans
go 1.19
+
+require gitlab.torproject.org/rgdd/ct v0.0.0-20230115071200-fa4d0bcd1cab // indirect
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..3e71076
--- /dev/null
+++ b/main.go
@@ -0,0 +1,102 @@
+// 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
+}
+
+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"
+
+ // 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)
+ }
+}