Moving to golang.org/x/crypto/acme/autocert for Let's Encrypt functionality. (#8165)

Этот коммит содержится в:
Christopher Speller
2018-01-30 10:12:42 -08:00
коммит произвёл GitHub
родитель 8ca8e71fdd
Коммит ac2e42a480

Просмотреть файл

@@ -10,13 +10,14 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
l4g "github.com/alecthomas/log4go" l4g "github.com/alecthomas/log4go"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/rsc/letsencrypt" "golang.org/x/crypto/acme/autocert"
"gopkg.in/throttled/throttled.v2" "gopkg.in/throttled/throttled.v2"
"gopkg.in/throttled/throttled.v2/store/memstore" "gopkg.in/throttled/throttled.v2/store/memstore"
@@ -161,18 +162,34 @@ func (a *App) StartServer() {
l4g.Info(utils.T("api.server.start_server.listening.info"), listener.Addr().String()) l4g.Info(utils.T("api.server.start_server.listening.info"), listener.Addr().String())
if *a.Config().ServiceSettings.Forward80To443 { // Migration from old let's encrypt library
go func() { if *a.Config().ServiceSettings.UseLetsEncrypt {
redirectListener, err := net.Listen("tcp", ":80") if stat, err := os.Stat(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile); err == nil && !stat.IsDir() {
if err != nil { os.Remove(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile)
listener.Close() }
l4g.Error("Unable to setup forwarding: " + err.Error()) }
return
}
defer redirectListener.Close()
http.Serve(redirectListener, http.HandlerFunc(redirectHTTPToHTTPS)) m := &autocert.Manager{
}() Cache: autocert.DirCache(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile),
Prompt: autocert.AcceptTOS,
}
if *a.Config().ServiceSettings.Forward80To443 {
if *a.Config().ServiceSettings.UseLetsEncrypt {
go http.ListenAndServe(":http", m.HTTPHandler(nil))
} else {
go func() {
redirectListener, err := net.Listen("tcp", ":80")
if err != nil {
listener.Close()
l4g.Error("Unable to setup forwarding: " + err.Error())
return
}
defer redirectListener.Close()
http.Serve(redirectListener, http.HandlerFunc(redirectHTTPToHTTPS))
}()
}
} }
a.Srv.didFinishListen = make(chan struct{}) a.Srv.didFinishListen = make(chan struct{})
@@ -180,8 +197,6 @@ func (a *App) StartServer() {
var err error var err error
if *a.Config().ServiceSettings.ConnectionSecurity == model.CONN_SECURITY_TLS { if *a.Config().ServiceSettings.ConnectionSecurity == model.CONN_SECURITY_TLS {
if *a.Config().ServiceSettings.UseLetsEncrypt { if *a.Config().ServiceSettings.UseLetsEncrypt {
var m letsencrypt.Manager
m.CacheFile(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile)
tlsConfig := &tls.Config{ tlsConfig := &tls.Config{
GetCertificate: m.GetCertificate, GetCertificate: m.GetCertificate,