Skip to content

Commit

Permalink
include ServerName in TLS configuration
Browse files Browse the repository at this point in the history
This is required for Go to establish a TLS connection unless
InsecureSkipVerify is set.
  • Loading branch information
mutantmonkey committed Jan 22, 2016
1 parent 505e129 commit 50366b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"net/url"

Expand Down Expand Up @@ -58,10 +59,15 @@ func getProxy(req *http.Request) (*url.URL, error) {
}

func newHTTPTransporter(baseURL, user, pass string) *httpTransporter {
u, _ := url.Parse(baseURL)
host, _, _ := net.SplitHostPort(u.Host)
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: rootCA},
Proxy: getProxy,
TLSClientConfig: &tls.Config{
RootCAs: rootCA,
ServerName: host,
},
Proxy: getProxy,
},
}

Expand Down
10 changes: 9 additions & 1 deletion websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ func newWSConn(originURL, user, pass string) (*wsConn, error) {
if err != nil {
return nil, err
}
wsConfig.TlsConfig = &tls.Config{RootCAs: rootCA}
host, _, err := net.SplitHostPort(wsConfig.Location.Host)
if err != nil {
return nil, err
}

wsConfig.TlsConfig = &tls.Config{
RootCAs: rootCA,
ServerName: host,
}

var wsc *websocket.Conn

Expand Down

0 comments on commit 50366b1

Please sign in to comment.