Avoid copying tls.Config lock

Fixes #90
This commit is contained in:
Mickael Remond 2019-07-15 18:40:20 +02:00
parent 9577036327
commit d36428fb2f
No known key found for this signature in database
GPG key ID: E6F6045D79965AA3
2 changed files with 7 additions and 3 deletions

View file

@ -14,7 +14,9 @@ type Config struct {
StreamLogger *os.File // Used for debugging
Lang string // TODO: should default to 'en'
ConnectTimeout int // Client timeout in seconds. Default to 15
TLSConfig tls.Config
// tls.Config must not be modified after having been passed to NewClient. The
// Client connect method may override the tls.Config.ServerName if it was not set.
TLSConfig *tls.Config
// Insecure can be set to true to allow to open a session without TLS. If TLS
// is supported on the server, we will still try to use it.
Insecure bool

View file

@ -117,8 +117,10 @@ func (s *Session) startTlsIfSupported(conn net.Conn, domain string, o Config) ne
return conn
}
if o.TLSConfig.ServerName == "" {
o.TLSConfig.ServerName = domain
tlsConn := tls.Client(conn, &o.TLSConfig)
}
tlsConn := tls.Client(conn, o.TLSConfig)
// We convert existing connection to TLS
if s.err = tlsConn.Handshake(); s.err != nil {
return tlsConn