added support for wildcard certificates

This commit is contained in:
2019-02-21 17:55:37 +01:00
parent e4f9285d73
commit 827e077da5
4 changed files with 16 additions and 16 deletions
+2 -1
View File
@@ -13,4 +13,5 @@
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
letsencrypt
letsencrypt
simplecert
+1 -1
View File
@@ -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"))
}
+13 -4
View File
@@ -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
-10
View File
@@ -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