mail: allow PLAIN auth over non-tls connections (#3900)

This allows mattermost to use a non-tls connection with a SMTP server that
supports PLAIN auth (but not LOGIN). The go library explicitly allows PLAIN
auth over non-tls connections - https://golang.org/src/net/smtp/auth.go#L55

Fixes #2929
Этот коммит содержится в:
Girish Ramakrishnan
2016-09-02 11:33:26 -07:00
коммит произвёл Joram Wilander
родитель f32eb525f3
Коммит 6c085594e4
4 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

@@ -11,6 +11,7 @@ import (
const ( const (
CONN_SECURITY_NONE = "" CONN_SECURITY_NONE = ""
CONN_SECURITY_PLAIN = "PLAIN"
CONN_SECURITY_TLS = "TLS" CONN_SECURITY_TLS = "TLS"
CONN_SECURITY_STARTTLS = "STARTTLS" CONN_SECURITY_STARTTLS = "STARTTLS"
@@ -964,7 +965,7 @@ func (o *Config) IsValid() *AppError {
return NewLocAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "") return NewLocAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "")
} }
if !(o.EmailSettings.ConnectionSecurity == CONN_SECURITY_NONE || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_TLS || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_STARTTLS) { if !(o.EmailSettings.ConnectionSecurity == CONN_SECURITY_NONE || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_TLS || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_STARTTLS || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_PLAIN) {
return NewLocAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "") return NewLocAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "")
} }

Просмотреть файл

@@ -52,8 +52,6 @@ func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
l4g.Error(T("utils.mail.new_client.open.error"), err) l4g.Error(T("utils.mail.new_client.open.error"), err)
return nil, model.NewLocAppError("SendMail", "utils.mail.connect_smtp.open_tls.app_error", nil, err.Error()) return nil, model.NewLocAppError("SendMail", "utils.mail.connect_smtp.open_tls.app_error", nil, err.Error())
} }
// GO does not support plain auth over a non encrypted connection.
// so if not tls then no auth
auth := smtp.PlainAuth("", config.EmailSettings.SMTPUsername, config.EmailSettings.SMTPPassword, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort) auth := smtp.PlainAuth("", config.EmailSettings.SMTPUsername, config.EmailSettings.SMTPPassword, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort)
if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_TLS { if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_TLS {
if err = c.Auth(auth); err != nil { if err = c.Auth(auth); err != nil {
@@ -68,6 +66,11 @@ func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
if err = c.Auth(auth); err != nil { if err = c.Auth(auth); err != nil {
return nil, model.NewLocAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error()) return nil, model.NewLocAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error())
} }
} else if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_PLAIN {
// note: go library only supports PLAIN auth over non-tls connections
if err = c.Auth(auth); err != nil {
return nil, model.NewLocAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error())
}
} }
return c, nil return c, nil
} }

Просмотреть файл

@@ -27,6 +27,20 @@ const CONNECTION_SECURITY_HELP_TEXT = (
/> />
</td> </td>
</tr> </tr>
<tr>
<td>
<FormattedMessage
id='admin.connectionSecurityPlain'
defaultMessage='PLAIN'
/>
</td>
<td>
<FormattedMessage
id='admin.connectionSecurityPlainDescription'
defaultMessage='Mattermost will connect and authenticate over an unsecure connection.'
/>
</td>
</tr>
<tr> <tr>
<td> <td>
<FormattedMessage <FormattedMessage
@@ -66,6 +80,7 @@ export default class ConnectionSecurityDropdownSetting extends React.Component {
id='connectionSecurity' id='connectionSecurity'
values={[ values={[
{value: '', text: Utils.localizeMessage('admin.connectionSecurityNone', 'None')}, {value: '', text: Utils.localizeMessage('admin.connectionSecurityNone', 'None')},
{value: 'PLAIN', text: Utils.localizeMessage('admin.connectionSecurityPlain')},
{value: 'TLS', text: Utils.localizeMessage('admin.connectionSecurityTls', 'TLS (Recommended)')}, {value: 'TLS', text: Utils.localizeMessage('admin.connectionSecurityTls', 'TLS (Recommended)')},
{value: 'STARTTLS', text: Utils.localizeMessage('admin.connectionSecurityStart')} {value: 'STARTTLS', text: Utils.localizeMessage('admin.connectionSecurityStart')}
]} ]}

Просмотреть файл

@@ -199,6 +199,8 @@
"admin.compliance_table.userId": "Requested By", "admin.compliance_table.userId": "Requested By",
"admin.connectionSecurityNone": "None", "admin.connectionSecurityNone": "None",
"admin.connectionSecurityNoneDescription": "Mattermost will connect over an unsecure connection.", "admin.connectionSecurityNoneDescription": "Mattermost will connect over an unsecure connection.",
"admin.connectionSecurityPlain": "PLAIN",
"admin.connectionSecurityPlainDescription": "Mattermost will connect and authenticate over an unsecure connection.",
"admin.connectionSecurityStart": "STARTTLS", "admin.connectionSecurityStart": "STARTTLS",
"admin.connectionSecurityStartDescription": "Takes an existing insecure connection and attempts to upgrade it to a secure connection using TLS.", "admin.connectionSecurityStartDescription": "Takes an existing insecure connection and attempts to upgrade it to a secure connection using TLS.",
"admin.connectionSecurityTest": "Test Connection", "admin.connectionSecurityTest": "Test Connection",