aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-28 22:55:59 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-28 22:55:59 +0100
commit88f2375435ad536ced2883e407ed46f7f16a578e (patch)
tree8d4134a008de38a6d19a2097f57bcf6af3d639cb
parent2c1ed954c80e701dc2f7b9de2912638a439243ff (diff)
LisenAndServeSNI draft
-rw-r--r--solve_tls.go25
1 files changed, 25 insertions, 0 deletions
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)
+}