Skip to content

Commit

Permalink
Use config scheme as default
Browse files Browse the repository at this point in the history
  • Loading branch information
taybart committed Aug 17, 2020
1 parent 2363808 commit 11ccc30
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 10 additions & 4 deletions certool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion cmd/certool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -73,6 +73,9 @@ func run() error {
if err != nil {
return err
}
if sch == "" {
sch = certool.GetDefaultScheme()
}

if edit {
return certool.EditConfig()
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11ccc30

Please sign in to comment.