Simplify EKU logic
With -client, you get clientAuth. With a non-email SAN, you also get serverAuth. With an email SAN, you also get emailProtection.
This commit is contained in:
parent
9f583c670f
commit
e28ee7df01
13
cert.go
13
cert.go
@ -68,11 +68,9 @@ func (m *mkcert) makeCert(hosts []string) {
|
||||
OrganizationalUnit: []string{userAndHostname},
|
||||
},
|
||||
|
||||
NotAfter: expiration,
|
||||
NotBefore: time.Now(),
|
||||
NotBefore: time.Now(), NotAfter: expiration,
|
||||
|
||||
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
|
||||
BasicConstraintsValid: true,
|
||||
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
|
||||
}
|
||||
|
||||
for _, h := range hosts {
|
||||
@ -88,9 +86,10 @@ func (m *mkcert) makeCert(hosts []string) {
|
||||
}
|
||||
|
||||
if m.client {
|
||||
tpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}
|
||||
} else if len(tpl.IPAddresses) > 0 || len(tpl.DNSNames) > 0 {
|
||||
tpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
|
||||
tpl.ExtKeyUsage = append(tpl.ExtKeyUsage, x509.ExtKeyUsageClientAuth)
|
||||
}
|
||||
if len(tpl.IPAddresses) > 0 || len(tpl.DNSNames) > 0 || len(tpl.URIs) > 0 {
|
||||
tpl.ExtKeyUsage = append(tpl.ExtKeyUsage, x509.ExtKeyUsageServerAuth)
|
||||
}
|
||||
if len(tpl.EmailAddresses) > 0 {
|
||||
tpl.ExtKeyUsage = append(tpl.ExtKeyUsage, x509.ExtKeyUsageEmailProtection)
|
||||
|
Loading…
Reference in New Issue
Block a user