Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow email SANs for S/MIME certificates #152

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"log"
"math/big"
"net"
"net/mail"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -61,18 +62,26 @@ func (m *mkcert) makeCert(hosts []string) {
NotBefore: time.Now(),

KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}

for _, h := range hosts {
if ip := net.ParseIP(h); ip != nil {
tpl.IPAddresses = append(tpl.IPAddresses, ip)
} else if email, err := mail.ParseAddress(h); err == nil && email.Address == h {
tpl.EmailAddresses = append(tpl.EmailAddresses, h)
} else {
tpl.DNSNames = append(tpl.DNSNames, h)
}
}

if m.client {
tpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}
} else if len(tpl.IPAddresses) > 0 || len(tpl.DNSNames) > 0 {
tpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
}
if len(tpl.EmailAddresses) > 0 {
tpl.ExtKeyUsage = append(tpl.ExtKeyUsage, x509.ExtKeyUsageCodeSigning, x509.ExtKeyUsageEmailProtection)
}

// IIS (the main target of PKCS #12 files), only shows the deprecated
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"log"
"net"
"net/mail"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -190,13 +191,16 @@ func (m *mkcert) Run(args []string) {
if ip := net.ParseIP(name); ip != nil {
continue
}
if email, err := mail.ParseAddress(name); err == nil && email.Address == name {
continue
}
punycode, err := idna.ToASCII(name)
if err != nil {
log.Fatalf("ERROR: %q is not a valid hostname or IP: %s", name, err)
log.Fatalf("ERROR: %q is not a valid hostname, IP, or email: %s", name, err)
}
args[i] = punycode
if !hostnameRegexp.MatchString(punycode) {
log.Fatalf("ERROR: %q is not a valid hostname or IP", name)
log.Fatalf("ERROR: %q is not a valid hostname, IP, or email", name)
}
}

Expand Down