mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-18 17:00:38 +01:00
Handle read errors in SMTP authentication flow
Add checks to handle errors when reading client messages. This ensures that an appropriate error message is sent back to the client if reading fails, improving the robustness of the SMTP authentication process.
This commit is contained in:
parent
03062c5183
commit
4c8c0d855e
1 changed files with 12 additions and 5 deletions
|
@ -1731,8 +1731,12 @@ func (s *testSCRAMSMTPServer) handleSCRAMAuth(conn net.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := reader.ReadString('\n')
|
data, err := reader.ReadString('\n')
|
||||||
clientMessage := strings.TrimSpace(data)
|
if err != nil {
|
||||||
decodedMessage, err := base64.StdEncoding.DecodeString(clientMessage)
|
_ = writeLine("535 Authentication failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data = strings.TrimSpace(data)
|
||||||
|
decodedMessage, err := base64.StdEncoding.DecodeString(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = writeLine("535 Authentication failed")
|
_ = writeLine("535 Authentication failed")
|
||||||
return
|
return
|
||||||
|
@ -1765,8 +1769,12 @@ func (s *testSCRAMSMTPServer) handleSCRAMAuth(conn net.Conn) {
|
||||||
_ = writeLine(fmt.Sprintf("334 %s", base64.StdEncoding.EncodeToString([]byte(serverFirstMessage))))
|
_ = writeLine(fmt.Sprintf("334 %s", base64.StdEncoding.EncodeToString([]byte(serverFirstMessage))))
|
||||||
|
|
||||||
data, err = reader.ReadString('\n')
|
data, err = reader.ReadString('\n')
|
||||||
clientFinalMessage := strings.TrimSpace(data)
|
if err != nil {
|
||||||
decodedFinalMessage, err := base64.StdEncoding.DecodeString(clientFinalMessage)
|
_ = writeLine("535 Authentication failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data = strings.TrimSpace(data)
|
||||||
|
decodedFinalMessage, err := base64.StdEncoding.DecodeString(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = writeLine("535 Authentication failed")
|
_ = writeLine("535 Authentication failed")
|
||||||
return
|
return
|
||||||
|
@ -1794,7 +1802,6 @@ func (s *testSCRAMSMTPServer) handleSCRAMAuth(conn net.Conn) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = writeLine("235 Authentication successful")
|
_ = writeLine("235 Authentication successful")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testSCRAMSMTPServer) extractNonce(message string) string {
|
func (s *testSCRAMSMTPServer) extractNonce(message string) string {
|
||||||
|
|
Loading…
Reference in a new issue