Add support for URL SANs (#166)

This commit is contained in:
Robert Panzer
2019-07-05 06:16:19 +02:00
committed by Filippo Valsorda
parent 0a679a8bcd
commit c2b30c48f1
2 changed files with 9 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ import (
"math/big" "math/big"
"net" "net"
"net/mail" "net/mail"
"net/url"
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
@@ -74,6 +75,8 @@ func (m *mkcert) makeCert(hosts []string) {
tpl.IPAddresses = append(tpl.IPAddresses, ip) tpl.IPAddresses = append(tpl.IPAddresses, ip)
} else if email, err := mail.ParseAddress(h); err == nil && email.Address == h { } else if email, err := mail.ParseAddress(h); err == nil && email.Address == h {
tpl.EmailAddresses = append(tpl.EmailAddresses, h) tpl.EmailAddresses = append(tpl.EmailAddresses, h)
} else if uriName, err := url.Parse(h); err == nil && uriName.Scheme != "" && uriName.Host != "" {
tpl.URIs = append(tpl.URIs, uriName)
} else { } else {
tpl.DNSNames = append(tpl.DNSNames, h) tpl.DNSNames = append(tpl.DNSNames, h)
} }

View File

@@ -13,6 +13,7 @@ import (
"log" "log"
"net" "net"
"net/mail" "net/mail"
"net/url"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -195,13 +196,16 @@ func (m *mkcert) Run(args []string) {
if email, err := mail.ParseAddress(name); err == nil && email.Address == name { if email, err := mail.ParseAddress(name); err == nil && email.Address == name {
continue continue
} }
if uriName, err := url.Parse(name); err == nil && uriName.Scheme != "" && uriName.Host != "" {
continue
}
punycode, err := idna.ToASCII(name) punycode, err := idna.ToASCII(name)
if err != nil { if err != nil {
log.Fatalf("ERROR: %q is not a valid hostname, IP, or email: %s", name, err) log.Fatalf("ERROR: %q is not a valid hostname, IP, URL or email: %s", name, err)
} }
args[i] = punycode args[i] = punycode
if !hostnameRegexp.MatchString(punycode) { if !hostnameRegexp.MatchString(punycode) {
log.Fatalf("ERROR: %q is not a valid hostname, IP, or email", name) log.Fatalf("ERROR: %q is not a valid hostname, IP, URL or email", name)
} }
} }