File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,22 @@ func (b *Broker) Open(conf *Config) error {
165
165
166
166
if conf .Net .TLS .Enable {
167
167
Logger .Printf ("Using tls" )
168
- b .conn = tls .Client (b .conn , conf .Net .TLS .Config )
168
+ cfg := conf .Net .TLS .Config
169
+ if cfg == nil {
170
+ cfg = & tls.Config {}
171
+ }
172
+ // If no ServerName is set, infer the ServerName
173
+ // from the hostname we're connecting to.
174
+ // Gets the hostname as tls.DialWithDialer does it.
175
+ if cfg .ServerName == "" {
176
+ colonPos := strings .LastIndex (b .addr , ":" )
177
+ if colonPos == - 1 {
178
+ colonPos = len (b .addr )
179
+ }
180
+ hostname := b .addr [:colonPos ]
181
+ cfg .ServerName = hostname
182
+ }
183
+ b .conn = tls .Client (b .conn , cfg )
169
184
}
170
185
171
186
b .conn = newBufConn (b .conn )
Original file line number Diff line number Diff line change @@ -158,8 +158,7 @@ func TestTLS(t *testing.T) {
158
158
Succeed : true ,
159
159
Server : serverTLSConfig ,
160
160
Client : & tls.Config {
161
- RootCAs : pool ,
162
- ServerName : "127.0.0.1" ,
161
+ RootCAs : pool ,
163
162
Certificates : []tls.Certificate {{
164
163
Certificate : [][]byte {clientDer },
165
164
PrivateKey : clientkey ,
You can’t perform that action at this time.
0 commit comments