Add support for SCRAM-SHA authentication methods

Extended SMTP authentication to include SCRAM-SHA-1, SCRAM-SHA-1-PLUS, SCRAM-SHA-256, and SCRAM-SHA-256-PLUS methods. This enhancement provides more secure and flexible authentication options for SMTP clients.
This commit is contained in:
Winni Neessen 2024-10-01 11:04:16 +02:00
parent e8fc6cd78f
commit 4f1a60760d
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -785,6 +785,35 @@ func (c *Client) auth() error {
return ErrXOauth2AuthNotSupported return ErrXOauth2AuthNotSupported
} }
c.smtpAuth = smtp.XOAuth2Auth(c.user, c.pass) c.smtpAuth = smtp.XOAuth2Auth(c.user, c.pass)
case SMTPAuthSCRAMSHA1:
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA1)) {
return ErrXOauth2AuthNotSupported
}
c.smtpAuth = smtp.ScramSHA1Auth(c.user, c.pass)
case SMTPAuthSCRAMSHA1PLUS:
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA1PLUS)) {
return ErrXOauth2AuthNotSupported
}
tlsConnState, err := c.smtpClient.GetTLSConnectionState()
if err != nil {
return err
}
c.smtpAuth = smtp.ScramSHA1PlusAuth(c.user, c.pass, tlsConnState)
case SMTPAuthSCRAMSHA256:
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA256)) {
return ErrXOauth2AuthNotSupported
}
c.smtpAuth = smtp.ScramSHA256Auth(c.user, c.pass)
case SMTPAuthSCRAMSHA256PLUS:
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA256PLUS)) {
return ErrXOauth2AuthNotSupported
}
tlsConnState, err := c.smtpClient.GetTLSConnectionState()
if err != nil {
return err
}
c.smtpAuth = smtp.ScramSHA256PlusAuth(c.user, c.pass, tlsConnState)
default: default:
return fmt.Errorf("unsupported SMTP AUTH type %q", c.smtpAuthType) return fmt.Errorf("unsupported SMTP AUTH type %q", c.smtpAuthType)
} }