From 88f2375435ad536ced2883e407ed46f7f16a578e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 28 Jan 2016 22:55:59 +0100 Subject: LisenAndServeSNI draft --- solve_tls.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'solve_tls.go') diff --git a/solve_tls.go b/solve_tls.go index 2017cd7..6062948 100644 --- a/solve_tls.go +++ b/solve_tls.go @@ -10,6 +10,7 @@ import ( "encoding/hex" "log" "math/big" + "net" "net/http" "time" ) @@ -83,3 +84,27 @@ func (s *tlsSolver) Solve(_, keyAuth string) error { func (s *tlsSolver) Solved() error { return nil } + +func ListenAndServeSNI(srv *http.Server, certs []tls.Certificate) error { + addr := srv.Addr + if addr == "" { + addr = ":https" + } + config := &tls.Config{} + if srv.TLSConfig != nil { + *config = *srv.TLSConfig + } + if config.NextProtos == nil { + config.NextProtos = []string{"http/1.1"} + } + if config.Certificates == nil { + config.Certificates = certs + } + config.BuildNameToCertificate() + conn, err := net.Listen("tcp", addr) + if err != nil { + return err + } + tlsListener := tls.NewListener(conn, config) + return srv.Serve(tlsListener) +} -- cgit v1.2.3