无法收到来自Gmail的邮件

几天前,Gmail突然决定停止向我的邮件服务器发送邮件。 我正在使用Postfix和Dovecot以及在Debian 7上运行的付费SSL证书,并更新了所有内容。

我的mail.log显示以下错误:

 Dec 19 11:09:11 server postfix/smtpd[19878]: initializing the server-side TLS engine Dec 19 11:09:11 server postfix/tlsmgr[19880]: open smtpd TLS cache btree:/var/lib/postfix/smtpd_scache Dec 19 11:09:11 server postfix/tlsmgr[19880]: tlsmgr_cache_run_event: start TLS smtpd session cache cleanup Dec 19 11:09:11 server postfix/smtpd[19878]: connect from mail-wi0-x230.google.com[2a00:1450:400c:c05::230] Dec 19 11:09:11 server postfix/smtpd[19878]: setting up TLS connection from mail-wi0-x230.google.com[2a00:1450:400c:c05::230] Dec 19 11:09:11 server postfix/smtpd[19878]: mail-wi0-x230.google.com[2a00:1450:400c:c05::230]: TLS cipher list "aNULL:-aNULL:ALL:+RC4:@STR ENGTH:!aNULL:!DES:!3DES:!MD5:!DES+MD5:!RC4:!RC4-MD5" Dec 19 11:09:11 server postfix/smtpd[19878]: SSL_accept:before/accept initialization Dec 19 11:09:11 server postfix/smtpd[19878]: SSL_accept:error in unknown state Dec 19 11:09:11 server postfix/smtpd[19878]: SSL_accept error from mail-wi0-x230.google.com[2a00:1450:400c:c05::230]: -1 Dec 19 11:09:11 server postfix/smtpd[19878]: warning: TLS library problem: 19878:error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol:s23_srvr.c:647: Dec 19 11:09:11 server postfix/smtpd[19878]: lost connection after STARTTLS from mail-wi0-x230.google.com[2a00:1450:400c:c05::230] Dec 19 11:09:11 server postfix/smtpd[19878]: disconnect from mail-wi0-x230.google.com[2a00:1450:400c:c05::230] 

摘自我的postfix main.cf

 smtpd_use_tls=yes smtpd_tls_security_level = may smtpd_tls_auth_only = yes smtpd_tls_CAfile = path to CA Bundle smtpd_tls_cert_file= path to cert (pem) smtpd_tls_key_file=path to key (pem) smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3,!TLSv1,!TLSv1.1 smtpd_tls_exclude_ciphers = aNULL, DES, 3DES, MD5, DES+MD5, RC4, RC4-MD5 smtpd_tls_protocols=!SSLv2,!TLSv1,!TLSv1.1,!SSLv3 smtpd_tls_mandatory_ciphers = medium smtpd_tls_received_header = yes tls_preempt_cipherlist = yes tls_medium_cipherlist = AES256+EECDH:AES256+EDH 

我不知道问题在哪里,因为我经常收到别人的邮件。 没有错误通过telnet或端口465通过openssl连接到端口25

另外:我从Google收到这封邮件:

 Delivery to the following recipient failed permanently: <removed> Technical details of permanent failure: TLS Negotiation failed ----- Original message ----- [...] 

也许这是我的密码列表的问题?

回答masegaloeh的问题:

 openssl s_client -connect localhost:25 -starttls smtp CONNECTED(00000003) depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP Network, CN = AddTrust External CA Root verify error:num=19:self signed certificate in certificate chain verify return:0 --- Certificate chain [...] --- Server certificate -----BEGIN CERTIFICATE----- [...] --- No client certificate CA names sent --- SSL handshake has read 6267 bytes and written 477 bytes --- New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384 Server public key is 2048 bit Secure Renegotiation IS supported Compression: zlib compression Expansion: zlib compression SSL-Session: Protocol : TLSv1.2 Cipher : ECDHE-RSA-AES256-GCM-SHA384 Session-ID: [...] Session-ID-ctx: Master-Key: [...] Key-Arg : None PSK identity: None PSK identity hint: None SRP username: None TLS session ticket lifetime hint: 3600 (seconds) TLS session ticket: [...] Compression: 1 (zlib compression) Start Time: 1418986680 Timeout : 300 (sec) Verify return code: 19 (self signed certificate in certificate chain) --- 250 DSN 

更新1:重新签发我的SSL证书。 生成一切如下:
openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out server.csr -sha256

然后我创build了一个由crtkey组成的新文件,之后创build了CA bundle:
cat COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > bundle.crt

添加了一切到我的鸽舍和后缀configuration,并重新启动这两个服务。
Google仍然无法发送邮件给我的服务器导致TLS Negotiation failed

我尝试了另一个邮件提供商(web.de),邮件得到发送。
web.de日志:

 Dec 19 17:33:15 server postfix/smtpd[14105]: connect from mout.web.de[212.227.15.3] Dec 19 17:33:15 server postfix/smtpd[14105]: setting up TLS connection from mout.web.de[212.227.15.3] Dec 19 17:33:15 server postfix/smtpd[14105]: mout.web.de[212.227.15.3]: TLS cipher list "aNULL:-aNULL:ALL:+RC4:@STRENGTH" Dec 19 17:33:15 server postfix/smtpd[14105]: mout.web.de[212.227.15.3]: save session EA1635ED786AFC2D9C7AB43EF43620A1D9092DC640FDE21C01E7BA25981D2445&s=smtp&l=268439647 to smtpd cache Dec 19 17:33:15 server postfix/tlsmgr[14107]: put smtpd session id=EA1635ED786AFC2D9C7AB43EF43620A1D9092DC640FDE21C01E7BA25981D2445&s=smtp&l=268439647 [data 127 bytes] Dec 19 17:33:15 server postfix/tlsmgr[14107]: write smtpd TLS cache entry EA1635ED786AFC2D9C7AB43EF43620A1D9092DC640FDE21C01E7BA25981D2445&s=smtp&l=268439647: time=1419006795 [data 127 bytes] Dec 19 17:33:15 server postfix/smtpd[14105]: Anonymous TLS connection established from mout.web.de[212.227.15.3]: TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits) 

Soultion:
smtpd_(mandatory)_protocols部分启用TLSv1TLSv1.1 ,一切正常。 谢谢masegaloeh

 Dec 20 11:44:46 server postfix/smtpd[31966]: initializing the server-side TLS engine Dec 20 11:44:46 server postfix/tlsmgr[31968]: open smtpd TLS cache btree:/var/lib/postfix/smtpd_scache Dec 20 11:44:46 server postfix/tlsmgr[31968]: tlsmgr_cache_run_event: start TLS smtpd session cache cleanup Dec 20 11:44:46 server postfix/smtpd[31966]: connect from mail-wi0-x235.google.com[2a00:1450:400c:c05::235] Dec 20 11:44:46 server postfix/smtpd[31966]: setting up TLS connection from mail-wi0-x235.google.com[2a00:1450:400c:c05::235] Dec 20 11:44:46 server postfix/smtpd[31966]: mail-wi0-x235.google.com[2a00:1450:400c:c05::235]: TLS cipher list "aNULL:-aNULL:ALL:+RC4:@STRENGTH" Dec 20 11:44:46 server postfix/smtpd[31966]: Anonymous TLS connection established from mail-wi0-x235.google.com[2a00:1450:400c:c05::235]: TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits) 

TLDR :您的TLS协议太严格,因为您只允许TLSv1.2连接。

 smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3,!TLSv1,!TLSv1.1 smtpd_tls_protocols=!SSLv2,!TLSv1,!TLSv1.1,!SSLv3 

GMAIL 使用TLSv1协议将电子邮件发送到您的服务器。 这就是TLS协商失败的原因。

明显的解决scheme是允许TLSv1和TLSv1.1协议,并仍然禁用(不安全)SSLv2和SSLv3协议。


说明

无法通过STARTTLS从GMAIL和FACEBOOK收到电子邮件时,我可以确认您的情况。

为什么只有GMAIL谁没有发送电子邮件到我的服务器

这是GMAIL发送电子邮件时的maillog片段

 Dec 19 23:37:47 tls postfix/smtpd[3876]: initializing the server-side TLS engine Dec 19 23:37:47 tls postfix/smtpd[3876]: connect from mail-wg0-f47.google.com[74.125.82.47] Dec 19 23:37:48 tls postfix/smtpd[3876]: setting up TLS connection from mail-wg0-f47.google.com[74.125.82.47] Dec 19 23:37:48 tls postfix/smtpd[3876]: mail-wg0-f47.google.com[74.125.82.47]: TLS cipher list "aNULL:-aNULL:ALL:+RC4:@STRENGTH:!aNULL:!DES:!3DES:!MD5:!DES+MD5:!RC4:!RC4-MD5" Dec 19 23:37:48 tls postfix/smtpd[3876]: SSL_accept:before/accept initialization Dec 19 23:37:48 tls postfix/smtpd[3876]: SSL_accept:error in unknown state Dec 19 23:37:48 tls postfix/smtpd[3876]: SSL_accept error from mail-wg0-f47.google.com[74.125.82.47]: -1 Dec 19 23:37:48 tls postfix/smtpd[3876]: warning: TLS library problem: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol:s23_srvr.c:647: Dec 19 23:37:48 tls postfix/smtpd[3876]: lost connection after STARTTLS from mail-wg0-f47.google.com[74.125.82.47] Dec 19 23:37:48 tls postfix/smtpd[3876]: disconnect from mail-wg0-f47.google.com[74.125.82.47] 

这是FACEBOOK发送邮件时的maillog片段

 Dec 19 23:11:14 tls postfix/smtpd[3844]: initializing the server-side TLS engine Dec 19 23:11:14 tls postfix/tlsmgr[3846]: open smtpd TLS cache btree:/var/lib/postfix/smtpd_scache Dec 19 23:11:14 tls postfix/tlsmgr[3846]: tlsmgr_cache_run_event: start TLS smtpd session cache cleanup Dec 19 23:11:14 tls postfix/smtpd[3844]: connect from outcampmail003.ash2.facebook.com[66.220.155.162] Dec 19 23:11:14 tls postfix/smtpd[3844]: setting up TLS connection from outcampmail003.ash2.facebook.com[66.220.155.162] Dec 19 23:11:14 tls postfix/smtpd[3844]: outcampmail003.ash2.facebook.com[66.220.155.162]: TLS cipher list "aNULL:-aNULL:ALL:+RC4:@STRENGTH:!aNULL:!DES:!3DES:!MD5:!DES+MD5:!RC4:!RC4-MD5" Dec 19 23:11:14 tls postfix/smtpd[3844]: SSL_accept:before/accept initialization Dec 19 23:11:15 tls postfix/smtpd[3844]: SSL_accept:error in unknown state Dec 19 23:11:15 tls postfix/smtpd[3844]: SSL_accept error from outcampmail003.ash2.facebook.com[66.220.155.162]: -1 Dec 19 23:11:15 tls postfix/smtpd[3844]: warning: TLS library problem: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol:s23_srvr.c:647: Dec 19 23:11:15 tls postfix/smtpd[3844]: lost connection after STARTTLS from outcampmail003.ash2.facebook.com[66.220.155.162] Dec 19 23:11:15 tls postfix/smtpd[3844]: disconnect from outcampmail003.ash2.facebook.com[66.220.155.162] Dec 19 23:11:16 tls postfix/smtpd[3844]: connect from outcampmail004.ash2.facebook.com[66.220.155.163] Dec 19 23:11:17 tls postfix/smtpd[3844]: 962C281443: client=outcampmail004.ash2.facebook.com[66.220.155.163] Dec 19 23:11:18 tls postfix/cleanup[3849]: 962C281443: message-id=<[email protected]> Dec 19 23:11:18 tls postfix/qmgr[3843]: 962C281443: from=<[email protected]>, size=18002, nrcpt=1 (queue active) Dec 19 23:11:18 tls postfix/local[3850]: 962C281443: to=<[email protected]>, orig_to=<[email protected]>, relay=local, delay=1.6, delays=1.5/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox) Dec 19 23:11:18 tls postfix/qmgr[3843]: 962C281443: removed Dec 19 23:11:24 tls postfix/smtpd[3844]: disconnect from outcampmail004.ash2.facebook.com[66.220.155.163] 

一些分析

  • 在第一个片段中,GMAIL将尝试通过STARTTLS发送电子邮件。 当TLS协商时,会发生一些错误,所以GMAIL服务器将其断开连接。 我们将讨论为什么在下面发生的错误。
  • 在第二个片段中,FACEBOOK也没有通过STARTTLS发送电子邮件。 在回退过程中,FACEBOOK以纯文本模式重新发送电子邮件。 在这种情况下,我们的服务器高兴地接受它。

所以,这就解释了为什么只有GMAIL无法发送电子邮件到您的服务器。 如果TLS协商失败,GMAIL没有回退的机制 。 其他邮件服务器可能会使用回退机制来确保电子邮件传递成功。

为什么发生TLS协商错误

我从web.de maillogfind有趣的一行

 Dec 19 17:33:15 foxdev postfix/smtpd[14105]: Anonymous TLS connection established from mout.web.de[212.227.15.3]: TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits) 

发现你在main.cf指定了这个configuration

 smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3,!TLSv1,!TLSv1.1 smtpd_tls_protocols=!SSLv2,!TLSv1,!TLSv1.1,!SSLv3 

这意味着您的服务器仅在使用TLSv1.2时才接受 TLS连接。 除了TLSv1.2,您的服务器将会抱怨TLS协商错误。

如果我将smtpd_tls_(mandatory_)protocols更改为!SSLv2,!SSLv3,!TLSv1 ,错误仍然会发生。 这意味着GMAIL和FACEBOOK将尝试与TLSv1.1和TLSv1.2以外的协议联系您的邮件服务器。

如果我将smtpd_tls_(mandatory_)protocols更改为!SSLv2,!SSLv3 ,则TLS协商将成功。 它确认GMAIL和FACEBOOK将使用TLSv1协议与您的服务器联系

 Dec 20 00:21:46 tls postfix/smtpd[4261]: Anonymous TLS connection established from outmail038.prn2.facebook.com[66.220.144.165]: TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits) Dec 20 00:23:00 tls postfix/smtpd[4261]: Anonymous TLS connection established from mail-wi0-f174.google.com[209.85.212.174]: TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits) 

FreeBSD论坛上的其他人也证实了这一点。

明显的解决scheme是在你的后缀中启用TLSv1和TLSv1.1。 这将确保某些没有回退机制的邮件服务器(如GMAIL)仍然可以与您的服务器进行通信。

我不知道你的理由是禁止TLSv1和TLSv1.1支持,只留下TLSv1.2协议。 如果它是一个networking服务器,你的用户将只使用现代浏览器,那么你可以在你的服务器上禁用TLSv1。 这是可以接受的,因为只有不支持协议TLSv1的较老的浏览器 。

我可以看到的一个潜在问题是OpenSSL报告的自签名证书的明显使用:

 Verify return code: 19 (self signed certificate in certificate chain) 

如果您使用付费SSL证书,则不应使用自签名证书。

我会检查您的PEM文件是否包含您的付费证书,并validation是否包含完整的证书链。