From 947bb4ccba242135696e246e2f0991dd929eff2b Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Tue, 21 Jan 2020 07:21:56 -0600 Subject: [PATCH] Adjusting SMTP TLS config to use just the hostname instead of the hostname+port when validating certificates. Fixes #1709 --- models/smtp.go | 5 +++-- models/smtp_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/models/smtp.go b/models/smtp.go index b2e45459..8ca8485b 100644 --- a/models/smtp.go +++ b/models/smtp.go @@ -101,6 +101,7 @@ func (s *SMTP) GetDialer() (mailer.Dialer, error) { if len(hp) < 2 { hp = append(hp, "25") } + host := hp[0] // Any issues should have been caught in validation, but we'll // double check here. port, err := strconv.Atoi(hp[1]) @@ -108,9 +109,9 @@ func (s *SMTP) GetDialer() (mailer.Dialer, error) { log.Error(err) return nil, err } - d := gomail.NewDialer(hp[0], port, s.Username, s.Password) + d := gomail.NewDialer(host, port, s.Username, s.Password) d.TLSConfig = &tls.Config{ - ServerName: s.Host, + ServerName: host, InsecureSkipVerify: s.IgnoreCertErrors, } hostname, err := os.Hostname() diff --git a/models/smtp_test.go b/models/smtp_test.go index e6552a9e..7ffbaadf 100644 --- a/models/smtp_test.go +++ b/models/smtp_test.go @@ -73,7 +73,7 @@ func (s *ModelsSuite) TestSMTPGetDialer(ch *check.C) { dialer := d.(*Dialer).Dialer ch.Assert(dialer.Host, check.Equals, host) ch.Assert(dialer.Port, check.Equals, port) - ch.Assert(dialer.TLSConfig.ServerName, check.Equals, smtp.Host) + ch.Assert(dialer.TLSConfig.ServerName, check.Equals, host) ch.Assert(dialer.TLSConfig.InsecureSkipVerify, check.Equals, smtp.IgnoreCertErrors) }