diff --git a/certool.go b/certool.go index bba6721..aa1e8ac 100644 --- a/certool.go +++ b/certool.go @@ -52,12 +52,12 @@ SerialNumber: {{ .C.SerialNumber }} Certificate is a CA {{ end }} Subject: {{ .C.Subject.CommonName }} - {{ if ne (len .C.Subject.Organization) 0 }}{{ index .C.Subject.Organization 0 }}{{end}} {{ if ne (len .C.Subject.OrganizationalUnit) 0 }}{{ index .C.Subject.OrganizationalUnit 0 }}{{ end }} - {{ if ne (len .C.Subject.StreetAddress) 0 }}{{ index .C.Subject.StreetAddress 0 }}, {{end}}{{ if ne (len .C.Subject.Locality) 0 }}{{ index .C.Subject.Locality 0 }}{{end}}{{ if ne (len .C.Subject.Province) 0 }} {{ index .C.Subject.Province 0 }}{{end}} + {{ if notempty .C.Subject.Organization }}{{ index .C.Subject.Organization 0 }}{{end}} {{ if notempty .C.Subject.OrganizationalUnit }}{{ index .C.Subject.OrganizationalUnit 0 }}{{ end }} + {{ if notempty .C.Subject.StreetAddress }}{{ index .C.Subject.StreetAddress 0 }} {{end}}{{ if notempty .C.Subject.Locality }}{{ index .C.Subject.Locality 0 }}, {{end}}{{ if notempty .C.Subject.Province }}{{ index .C.Subject.Province 0 }}{{end}}{{ if notempty .C.Issuer.Country }}, {{ index .C.Issuer.Country 0 }}{{end}} Issuer: {{ .C.Issuer.CommonName }} - {{ if ne (len .C.Issuer.Organization) 0 }}{{ index .C.Issuer.Organization 0 }}{{end}} {{ if ne (len .C.Issuer.OrganizationalUnit) 0 }}{{ index .C.Issuer.OrganizationalUnit 0 }}{{ end }} - {{ if ne (len .C.Issuer.StreetAddress) 0 }}{{ index .C.Issuer.StreetAddress 0 }}, {{end}}{{ if ne (len .C.Issuer.Locality) 0 }}{{ index .C.Issuer.Locality 0 }}{{end}}{{ if ne (len .C.Issuer.Province) 0 }} {{ index .C.Issuer.Province 0 }}{{end}} + {{ if notempty .C.Issuer.Organization }}{{ index .C.Issuer.Organization 0 }}{{end}} {{ if notempty .C.Issuer.OrganizationalUnit }}{{ index .C.Issuer.OrganizationalUnit 0 }}{{ end }} + {{ if notempty .C.Issuer.StreetAddress }}{{ index .C.Issuer.StreetAddress 0 }} {{end}}{{ if notempty .C.Issuer.Locality }}{{ index .C.Issuer.Locality 0 }}, {{end}}{{ if notempty .C.Issuer.Province }}{{ index .C.Issuer.Province 0 }}{{end}}{{ if notempty .C.Issuer.Country }}, {{ index .C.Issuer.Country 0 }}{{end}} KeyUsage: {{ .KeyUsages }} ExtKeyUsage: {{ .ExtKeyUsages }} @@ -72,6 +72,12 @@ OCSPServer: {{ .C.OCSPServer }} {{- end -}} ` funcMap := template.FuncMap{ + "notempty": func(arr []string) bool { + if len(arr) == 1 { + return arr[0] != "" + } + return len(arr) != 0 + }, "indent": func(spaces int, v string) string { pad := strings.Repeat(" ", spaces) return pad + strings.Replace(v, "\n", "\n"+pad, -1) diff --git a/cmd/certool/main.go b/cmd/certool/main.go index d67504f..384ab84 100644 --- a/cmd/certool/main.go +++ b/cmd/certool/main.go @@ -40,7 +40,7 @@ var ( func init() { flag.StringVar(&configLocation, "c", certool.DefaultConfig.Dir, "Config file location") - flag.StringVar(&sch, "scheme", "ed25519", "Cryptographic scheme for certs [ed25519, ecdsa{256, 384, 512}, rsa{2048, 4096}]") + flag.StringVar(&sch, "scheme", "", "Cryptographic scheme for certs [ed25519, ecdsa{256, 384, 512}, rsa{2048, 4096}]") flag.StringVar(&verify, "verify", "", "Check cert validity") flag.BoolVar(&systemCA, "system", false, "Validate using certool CA") @@ -73,6 +73,9 @@ func run() error { if err != nil { return err } + if sch == "" { + sch = certool.GetDefaultScheme() + } if edit { return certool.EditConfig() diff --git a/config.go b/config.go index 5eb6f86..646f6fd 100644 --- a/config.go +++ b/config.go @@ -143,6 +143,10 @@ func LoadConfigFromFile(location string) (err error) { return } +func GetDefaultScheme() string { + return config.CA.Scheme + +} func (c *Config) GetCAPassword() string { fmt.Printf("Enter CA Password -> ") tty, err := os.Open("/dev/tty") // Use tty just in case stdin is pipe