-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttps_server.go
34 lines (31 loc) · 984 Bytes
/
https_server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package controller
import (
"crypto/tls"
"fmt"
"net/http"
"github.com/blackstorm/ingress-go/pkg/controller/matcher"
"k8s.io/klog"
)
func listenAndServeTLSHttp(port uint,
handler http.Handler,
tlsMatcher *matcher.TLSMatcher, defaultCert DefaultCertificate) error {
tlsServer := http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: handler,
}
tlsServer.TLSConfig = &tls.Config{
// CipherSuites
// if not set CipherSuites. will use initDefaultCipherSuites for defualt sets
GetCertificate: func(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
// klog.Infof("ssl handshake hello server %s", hello.ServerName)
cert := tlsMatcher.Match(hello.ServerName, false)
if cert == nil {
klog.Warningf("server %s certificate no found", hello.ServerName)
return nil, fmt.Errorf("no found %s certificate", hello.ServerName)
} else {
return cert, nil
}
},
}
return tlsServer.ListenAndServeTLS(defaultCert.certFile, defaultCert.keyFile)
}