From c2b30c48f1d7e4cb2ec547e6e5305eb8548d0af7 Mon Sep 17 00:00:00 2001 From: Robert Panzer Date: Fri, 5 Jul 2019 06:16:19 +0200 Subject: [PATCH] Add support for URL SANs (#166) --- cert.go | 3 +++ main.go | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cert.go b/cert.go index aa5960a..6558ab9 100644 --- a/cert.go +++ b/cert.go @@ -20,6 +20,7 @@ import ( "math/big" "net" "net/mail" + "net/url" "os" "os/user" "path/filepath" @@ -74,6 +75,8 @@ func (m *mkcert) makeCert(hosts []string) { 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 if uriName, err := url.Parse(h); err == nil && uriName.Scheme != "" && uriName.Host != "" { + tpl.URIs = append(tpl.URIs, uriName) } else { tpl.DNSNames = append(tpl.DNSNames, h) } diff --git a/main.go b/main.go index a1266e8..bddecce 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "log" "net" "net/mail" + "net/url" "os" "os/exec" "path/filepath" @@ -195,13 +196,16 @@ func (m *mkcert) Run(args []string) { if email, err := mail.ParseAddress(name); err == nil && email.Address == name { continue } + if uriName, err := url.Parse(name); err == nil && uriName.Scheme != "" && uriName.Host != "" { + continue + } punycode, err := idna.ToASCII(name) 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 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) } }