Jan Dittberner
47d5b2afff
- implement a dedicated setup mode for creating CA certificates that is triggered by the '-setup' command line flag - switch to YAML configuration for comment support and more human readable syntax. Format documentation is in docs/config.sample.yaml - move HSM related code to pkg/hsm - improve consistency checks in pkg/config
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
|
|
"git.cacert.org/cacert-gosigner/pkg/config"
|
|
"git.cacert.org/cacert-gosigner/pkg/hsm"
|
|
)
|
|
|
|
var (
|
|
commit string
|
|
date string
|
|
version string
|
|
)
|
|
|
|
const (
|
|
defaultSignerConfigFile = "config.yaml"
|
|
)
|
|
|
|
func main() {
|
|
var (
|
|
showVersion bool
|
|
signerConfigFile string
|
|
setupMode bool
|
|
)
|
|
|
|
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile | log.LUTC)
|
|
|
|
log.Printf("cacert-gosigner %s (%s) - built %s\n", version, commit, date)
|
|
|
|
flag.StringVar(&signerConfigFile, "caconfig", defaultSignerConfigFile, "signer configuration file")
|
|
flag.BoolVar(&showVersion, "version", false, "show version")
|
|
flag.BoolVar(&setupMode, "setup", false, "setup mode")
|
|
|
|
flag.Parse()
|
|
|
|
if showVersion {
|
|
return
|
|
}
|
|
|
|
configFile, err := os.Open(signerConfigFile)
|
|
if err != nil {
|
|
log.Fatalf("could not open singer configuration file %s: %v", signerConfigFile, err)
|
|
}
|
|
|
|
caConfig, err := config.LoadConfiguration(configFile)
|
|
if err != nil {
|
|
log.Fatalf("could not load CA hierarchy: %v", err)
|
|
}
|
|
|
|
if setupMode {
|
|
log.Print("running in setup mode")
|
|
}
|
|
|
|
ctx := hsm.SetupContext(caConfig, setupMode)
|
|
|
|
err = hsm.EnsureCAKeysAndCertificates(ctx)
|
|
if err != nil {
|
|
log.Fatalf("could not ensure CA keys and certificates exist: %v", err)
|
|
}
|
|
|
|
if setupMode {
|
|
return
|
|
}
|
|
|
|
log.Print("setup complete, starting signer operation")
|
|
}
|