net / smtp是否以纯文本形式发送凭据?

时间:2015-05-11 00:22:01

标签: security email go smtp

我正在看这个例子。 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是否安全?

1 个答案:

答案 0 :(得分:3)

PlainAuth使用RFC 4616中的Plain auth mech,它是普通明文中的用户名/密码。通常在使用此时,将在较低级别处理加密,例如,您将创建TLS连接。然后使用PlainAuth。如果您没有通过加密连接进行交谈,那么使用PlainAuth可能会有风险,就像截获流量一样,用户/通行证也很容易获得。

但如果你看过,你会看到SendMail函数说明如下:

  

SendMail在addr处连接到服务器,如果可能,切换到TLS,如果可能,使用可选机制a进行身份验证,然后使用消息msg从地址向地址发送电子邮件。

因此,它会尽可能自动升级到TLS。因此,只要您使用支持TLS的服务器,您就应该相对安全。另一个Auth选择是CramMD5,但是这种方法的服务器支持通常不如PlainAuth那么普遍,大多数都支持。