Skip to content

Commit 852f51b

Browse files
committed
include ServerName in TLS configuration
This is required for Go to establish a TLS connection unless InsecureSkipVerify is set.
1 parent f60b7ea commit 852f51b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

transport.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto/tls"
99
"fmt"
1010
"io"
11+
"net"
1112
"net/http"
1213
"net/url"
1314

@@ -58,10 +59,19 @@ func getProxy(req *http.Request) (*url.URL, error) {
5859
}
5960

6061
func newHTTPTransporter(baseURL, user, pass string) *httpTransporter {
62+
u, _ := url.Parse(baseURL)
63+
host, _, err := net.SplitHostPort(u.Host)
64+
if err != nil {
65+
host = u.Host
66+
}
67+
6168
client := &http.Client{
6269
Transport: &http.Transport{
63-
TLSClientConfig: &tls.Config{RootCAs: rootCA},
64-
Proxy: getProxy,
70+
TLSClientConfig: &tls.Config{
71+
RootCAs: rootCA,
72+
ServerName: host,
73+
},
74+
Proxy: getProxy,
6575
},
6676
}
6777

websocket.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ func newWSConn(originURL, user, pass string) (*wsConn, error) {
6464
if err != nil {
6565
return nil, err
6666
}
67-
wsConfig.TlsConfig = &tls.Config{RootCAs: rootCA}
67+
host, _, err := net.SplitHostPort(wsConfig.Location.Host)
68+
if err != nil {
69+
host = wsConfig.Location.Host
70+
}
71+
72+
wsConfig.TlsConfig = &tls.Config{
73+
RootCAs: rootCA,
74+
ServerName: host,
75+
}
6876

6977
var wsc *websocket.Conn
7078

0 commit comments

Comments
 (0)