From 2f8ec7b36f6f7c89ffd0998b0acfa042b27dbc3c Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Mon, 28 Oct 2019 14:46:13 +0100 Subject: [PATCH] Only try startTls if the connection is not secure --- session.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/session.go b/session.go index 04678b7..22d76b2 100644 --- a/session.go +++ b/session.go @@ -29,12 +29,14 @@ func NewSession(transport Transport, o Config, state SMState) (*Session, error) s.SMState = state s.init(o) - s.startTlsIfSupported(o) - if s.err != nil { return nil, NewConnError(s.err, true) } + if !transport.IsSecure() { + s.startTlsIfSupported(o) + } + if !transport.IsSecure() && !o.Insecure { err := fmt.Errorf("failed to negotiate TLS session : %s", s.err) return nil, NewConnError(err, true)