diff options
author | Steve Manuel <nilslice@gmail.com> | 2018-01-13 12:33:59 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2018-01-13 12:33:59 -0700 |
commit | 18e51f8c9a70688560e65f99638d500e60df8264 (patch) | |
tree | 51031603b6d4a1d1ef89c3fca2e5945a85c83303 /system/tls/enable.go | |
parent | b4f50559630d9d236254e81551f3fad456955c9b (diff) |
[core] system/tls: implement handler for "http-01" challenge
Diffstat (limited to 'system/tls/enable.go')
-rw-r--r-- | system/tls/enable.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/system/tls/enable.go b/system/tls/enable.go index a90f2d1..9fc95f9 100644 --- a/system/tls/enable.go +++ b/system/tls/enable.go @@ -16,10 +16,9 @@ import ( "golang.org/x/crypto/acme/autocert" ) -var m autocert.Manager - -// setup attempts to locate or create the cert cache directory and the certs for TLS encryption -func setup() { +// newManager attempts to locate or create the cert cache directory and the +// certs for TLS encryption and returns an autocert.Manager +func newManager() autocert.Manager { pwd, err := os.Getwd() if err != nil { log.Fatalln("Couldn't find working directory to locate or save certificates.") @@ -57,25 +56,27 @@ func setup() { } fmt.Println("Using", string(email), "as contact email for certificate...") - m = autocert.Manager{ + return autocert.Manager{ Prompt: autocert.AcceptTOS, Cache: cache, HostPolicy: autocert.HostWhitelist(string(host)), RenewBefore: time.Hour * 24 * 30, Email: string(email), } - } // Enable runs the setup for creating or locating production certificates and // starts the TLS server func Enable() { - setup() + m := newManager() server := &http.Server{ Addr: fmt.Sprintf(":%s", db.ConfigCache("https_port").(string)), TLSConfig: &tls.Config{GetCertificate: m.GetCertificate}, } + // launch http listener for "http-01" ACME challenge + go http.ListenAndServe(":http", m.HTTPHandler(nil)) + log.Fatalln(server.ListenAndServeTLS("", "")) } |