Skip to content

Commit

Permalink
Set ServerName using tls.DialWithDialer approach
Browse files Browse the repository at this point in the history
  • Loading branch information
d1egoaz committed May 7, 2020
1 parent 8fe9db2 commit ab525ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 11 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ func (b *Broker) Open(conf *Config) error {

if conf.Net.TLS.Enable {
Logger.Printf("Using tls")

// If no ServerName is set, infer the ServerName
// from the hostname we're connecting to.
if conf.Net.TLS.Config.ServerName == "" {
colonPos := strings.LastIndex(b.addr, ":")
if colonPos == -1 {
colonPos = len(b.addr)
}
hostname := b.addr[:colonPos]
conf.Net.TLS.Config.ServerName = hostname
}
b.conn = tls.Client(b.conn, conf.Net.TLS.Config)
}

Expand Down
3 changes: 1 addition & 2 deletions client_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func TestTLS(t *testing.T) {
Succeed: true,
Server: serverTLSConfig,
Client: &tls.Config{
RootCAs: pool,
ServerName: "127.0.0.1",
RootCAs: pool,
Certificates: []tls.Certificate{{
Certificate: [][]byte{clientDer},
PrivateKey: clientkey,
Expand Down

0 comments on commit ab525ed

Please sign in to comment.