From 827e077da5bec5b965423b3e0a7e4e2b110dc0df Mon Sep 17 00:00:00 2001 From: Philipp Mieden Date: Thu, 21 Feb 2019 17:55:37 +0100 Subject: [PATCH] added support for wildcard certificates --- .gitignore | 3 ++- examples/simple/main.go | 2 +- local.go | 17 +++++++++++++---- simplecert/simplecert.log | 10 ---------- 4 files changed, 16 insertions(+), 16 deletions(-) delete mode 100755 simplecert/simplecert.log diff --git a/.gitignore b/.gitignore index 264a16d..ac2d570 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ -letsencrypt \ No newline at end of file +letsencrypt +simplecert \ No newline at end of file diff --git a/examples/simple/main.go b/examples/simple/main.go index 79ecf62..07a0517 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -14,5 +14,5 @@ func main() { w.Write([]byte("hello")) }) - log.Fatal(simplecert.ListenAndServeTLSLocal(":443", nil, "myawesomewebsite.com")) + log.Fatal(simplecert.ListenAndServeTLSLocal(":443", nil, "*.myawesomewebsite.com")) } diff --git a/local.go b/local.go index 2454cd7..51de564 100644 --- a/local.go +++ b/local.go @@ -15,6 +15,7 @@ import ( "log" "os" "strconv" + "strings" "github.com/lextoumbourou/goodhosts" ) @@ -57,13 +58,21 @@ func createLocalCert(certFilePath, keyFilePath string) { var ( newCertFile string newKeyFile string + + firstDomain = c.Domains[0] ) + + if strings.HasPrefix(firstDomain, "*") { + firstDomain = strings.TrimPrefix(firstDomain, "*") + firstDomain = "_wildcard" + firstDomain + } + if len(c.Domains) > 1 { - newCertFile = c.Domains[0] + "+" + strconv.Itoa(len(c.Domains)-1) + ".pem" - newKeyFile = c.Domains[0] + "+" + strconv.Itoa(len(c.Domains)-1) + "-key.pem" + newCertFile = firstDomain + "+" + strconv.Itoa(len(c.Domains)-1) + ".pem" + newKeyFile = firstDomain + "+" + strconv.Itoa(len(c.Domains)-1) + "-key.pem" } else { - newCertFile = c.Domains[0] + ".pem" - newKeyFile = c.Domains[0] + "-key.pem" + newCertFile = firstDomain + ".pem" + newKeyFile = firstDomain + "-key.pem" } // rename certificate file diff --git a/simplecert/simplecert.log b/simplecert/simplecert.log deleted file mode 100755 index 82913c4..0000000 --- a/simplecert/simplecert.log +++ /dev/null @@ -1,10 +0,0 @@ -2019/02/21 17:35:31 [INFO] simplecert: checking if cacheDir simplecert/local exists... -2019/02/21 17:35:31 [INFO] simplecert: cacheDir does not exist - creating it -2019/02/21 17:35:31 [INFO] no cached cert found. Creating a new one for local development... -2019/02/21 17:35:34 [INFO] renaming myawesomewebsite.com.pem to simplecert/local/cert.pem -2019/02/21 17:35:34 [INFO] renaming myawesomewebsite.com-key.pem to simplecert/local/key.pem -2019/02/21 17:35:34 starting HTTP Listener on Port 80 -2019/02/21 17:35:34 serving: https://myawesomewebsite.com -2019/02/21 17:35:45 [INFO] simplecert: checking if cacheDir simplecert/local exists... -2019/02/21 17:35:45 starting HTTP Listener on Port 80 -2019/02/21 17:35:45 serving: https://myawesomewebsite.com