Skip to content

Commit

Permalink
Creates conf.Net.TLS.Config if not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
d1egoaz committed May 7, 2020
1 parent ab525ed commit cb29302
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions broker.go
Expand Up @@ -165,18 +165,22 @@ func (b *Broker) Open(conf *Config) error {

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

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

b.conn = newBufConn(b.conn)
Expand Down

0 comments on commit cb29302

Please sign in to comment.