2021-05-03 21:04:48 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
|
|
|
|
2021-07-20 09:03:09 +00:00
|
|
|
"github.com/pires/go-proxyproto"
|
2021-05-03 21:04:48 +00:00
|
|
|
"goauthentik.io/internal/config"
|
|
|
|
"goauthentik.io/internal/crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ServeHTTPS constructs a net.Listener and starts handling HTTPS requests
|
|
|
|
func (ws *WebServer) listenTLS() {
|
|
|
|
cert, err := crypto.GenerateSelfSignedCert()
|
|
|
|
if err != nil {
|
|
|
|
ws.log.WithError(err).Error("failed to generate default cert")
|
|
|
|
}
|
|
|
|
tlsConfig := &tls.Config{
|
|
|
|
MinVersion: tls.VersionTLS12,
|
|
|
|
MaxVersion: tls.VersionTLS12,
|
|
|
|
Certificates: []tls.Certificate{cert},
|
|
|
|
}
|
|
|
|
|
|
|
|
ln, err := net.Listen("tcp", config.G.Web.ListenTLS)
|
|
|
|
if err != nil {
|
|
|
|
ws.log.WithError(err).Fatalf("failed to listen")
|
2021-07-18 14:12:57 +00:00
|
|
|
return
|
2021-05-03 21:04:48 +00:00
|
|
|
}
|
2021-11-19 09:37:13 +00:00
|
|
|
ws.log.WithField("listen", config.G.Web.ListenTLS).Info("Listening (TLS)")
|
2021-05-03 21:04:48 +00:00
|
|
|
|
2021-07-20 09:03:09 +00:00
|
|
|
proxyListener := &proxyproto.Listener{Listener: tcpKeepAliveListener{ln.(*net.TCPListener)}}
|
|
|
|
defer proxyListener.Close()
|
|
|
|
|
|
|
|
tlsListener := tls.NewListener(proxyListener, tlsConfig)
|
2021-05-03 21:04:48 +00:00
|
|
|
ws.serve(tlsListener)
|
|
|
|
ws.log.Printf("closing %s", tlsListener.Addr())
|
|
|
|
}
|