From cb293024a2efb95fb03418fe1e5e7a2d41cdd05f Mon Sep 17 00:00:00 2001 From: Diego Alvarez Date: Thu, 7 May 2020 11:55:19 -0700 Subject: [PATCH] Creates conf.Net.TLS.Config if not provided --- broker.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/broker.go b/broker.go index 3c39300c7..cda5da8f7 100644 --- a/broker.go +++ b/broker.go @@ -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)