我正在看这个例子。 http://golang.org/pkg/net/smtp/#example_PlainAuth
package main
import (
"log"
"net/smtp"
)
func main() {
// Set up authentication information.
auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com")
to := []string{"recipient@example.net"}
mesg := []byte("This is the email body.")
err := smtp.SendMail("mail.example.com:25", auth, "sender@example.org", to, mesg)
if err != nil {
log.Fatal(err)
}
}
smtp.PlainAuth
是否以明文形式向邮件服务器发送凭据?在野外使用 net/smtp 安全吗?
最佳答案
PlainAuth 使用来自 RFC 4616 的 Plain auth mech,它是明文形式的用户名/密码。通常当您使用它时,加密将在较低级别处理,例如您将创建一个 TLS 连接。然后在上面使用 PlainAuth。如果您不是通过加密连接进行通话,那么使用 PlainAuth 可能会有风险,因为流量被拦截了,用户/密码很容易获得。
但是如果你阅读,你会看到 SendMail
函数是这样写的:
SendMail connects to the server at addr, switches to TLS if possible, authenticates with the optional mechanism a if possible, and then sends an email from address from, to addresses to, with message msg.
所以它会尝试在可能的情况下自动升级到 TLS。所以只要你使用的是支持 TLS 的服务器,你应该是相对安全的。另一种 Auth 选择是 CramMD5,但服务器对这种方法的支持通常不如 PlainAuth 普遍,而 PlainAuth 大多数都支持。
关于security - net/smtp 是否以纯文本形式发送凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30158027/