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,7 +162,22 @@ 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())
// Migration from old let's encrypt library
if *a.Config().ServiceSettings.UseLetsEncrypt {
if stat, err := os.Stat(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile); err == nil && !stat.IsDir() {
os.Remove(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile)
}
}
m := &autocert.Manager{
Cache: autocert.DirCache(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile),
Prompt: autocert.AcceptTOS,
}
if *a.Config().ServiceSettings.Forward80To443 { if *a.Config().ServiceSettings.Forward80To443 {
if *a.Config().ServiceSettings.UseLetsEncrypt {
go http.ListenAndServe(":http", m.HTTPHandler(nil))
} else {
go func() { go func() {
redirectListener, err := net.Listen("tcp", ":80") redirectListener, err := net.Listen("tcp", ":80")
if err != nil { if err != nil {
@@ -174,14 +190,13 @@ func (a *App) StartServer() {
http.Serve(redirectListener, http.HandlerFunc(redirectHTTPToHTTPS)) http.Serve(redirectListener, http.HandlerFunc(redirectHTTPToHTTPS))
}() }()
} }
}
a.Srv.didFinishListen = make(chan struct{}) a.Srv.didFinishListen = make(chan struct{})
go func() { go func() {
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,