Postfix SMTP 客户端未使用 tls_append_default_CA 验证系统范围的 CA 证书

ger*_*ijk 6 postfix tls

在运行 Debian Wheezy 的面向 Internet 的 Postfix SMTP 服务器上,我想与一些已知服务器建立安全连接。有些是我自己的,运行我自己的 PKI/CA,有些是公共 SMTP 服务器,如 Google 的 Gmail 服务器。要检查我自己运行的服务器上的证书,我已指定

smtp_tls_CAfile = /usr/local/share/ca-certificates/Gert_van_Dijk_Root_CA_2014.crt
Run Code Online (Sandbox Code Playgroud)

并确保公共服务器也可以根据内置系统证书存储进行验证,我已经明确指定

tls_append_default_CA = yes
Run Code Online (Sandbox Code Playgroud)

为了确保 Postfix 正确验证证书,我将全局 TLS 安全级别设置为“安全”。我将这一回“可能”与某些领域改变securesmtp_tls_policy_maps一旦我完成调试这里介绍这个问题。

smtp_tls_security_level = secure
Run Code Online (Sandbox Code Playgroud)

它可以很好地验证我自己的服务器!这些都使用由Gert_van_Dijk_Root_CA_2014.crt. 但是,当 SMTP 客户端tls_append_default_CA尝试将邮件发送到 Google 的 SMTP 服务器时,它似乎实际上并未通过设置附加证书。我希望它能够附加/etc/ssl/certsDebian 上的那些内容。

postfix/smtp[32271]: effective TLS level: secure
[...]
postfix/smtp[32271]: < alt1.gmail-smtp-in.l.google.com[64.233.164.26]:25: 220 2.0.0 Ready to start TLS
[...]
postfix/smtp[32271]: DE6D0403EB: Server certificate not verified
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

  • master.cf像这样为 smtp 客户端禁用 chroot :

    smtp      unix  -       -       n      -       -       smtp
    
    Run Code Online (Sandbox Code Playgroud)

    没有帮助。

  • 添加详细日志记录。我已经添加-v到上面的行。不得不禁用 rsyslog 速率限制,但这并没有改善任何东西。它提到的有关 TLS 验证的唯一一行就是该DE6D0403EB: Server certificate not verified行。

  • 尝试跟踪该过程以查看它是否会遇到访问 CA 证书的任何问题。看来 SMTP 客户端是作为每次传递尝试的新进程产生的。这使得一般strace -p <PID>不可能。

  • 搜索类似的问题。我似乎只发现了这个非常相似的问题,但这与我没有指定smtp_tls_CAfile设置有关。使用smtp_tls_CAfile集合,它应该真正附加系统范围的 CA 证书。

  • 将所有恢复到 Debian 默认设置,但smtp_tls_security_level = secure. 它也无法以相同的错误交付给 Google。Debian 的 Postfix 中的错误呢?

  • 同上,然后为 SMTP 客户端禁用 chroot,然后smtp_tls_CApath = /etc/ssl/certs显式设置。证书验证仍然失败。

  • 添加 TLS 调试级别。节目:

    postfix/tlsmgr[17486]: write smtp TLS cache entry smtp:64.233.164.26:25:mx.google.com&p=1&c=aNULL:-aNULL:ALL:!EXPORT:!LOW:+RC4:@STRENGTH:!aNULL&l=268439647: time=1421622891 [data 1975 bytes]
    postfix/smtp[17485]: alt1.gmail-smtp-in.l.google.com[64.233.164.26]:25: subject_CN=mx.google.com, issuer_CN=Google Internet Authority G2, fingerprint 88:C0:85:C8:CB:96:29:8F:4E:15:11:80:C5:9A:89:0D, pkey_fingerprint=E0:32:29:21:69:38:EA:F9:B6:0C:F6:BD:86:12:16:B9
    postfix/smtp[17485]: Untrusted TLS connection established to alt1.gmail-smtp-in.l.google.com[64.233.164.26]:25: TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)
    postfix/smtp[17485]: DE6D0403EB: Server certificate not trusted
    
    Run Code Online (Sandbox Code Playgroud)
  • 同一系统上的 OpenSSL 手动验证显示一切都应该没问题。

    $ openssl s_client -connect 64.233.164.26:25 -starttls smtp
    CONNECTED(00000003)
    depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
    verify error:num=20:unable to get local issuer certificate
    verify return:0
    
    Run Code Online (Sandbox Code Playgroud)
  • 还为 tlsmgr 禁用 chroot 后,我​​终于得到了一个Trusted TLS connection established,但是 postfix 仍然认为连接不安全(Server certificate not verified):

    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: certificate verification depth=3 verify=1 subject=/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: certificate verification depth=2 verify=1 subject=/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: certificate verification depth=1 verify=1 subject=/C=US/O=Google Inc/CN=Google Internet Authority G2
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: certificate verification depth=0 verify=1 subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=mx.google.com
    postfix/smtp[27198]: SSL_connect:SSLv3 read server certificate A
    postfix/smtp[27198]: SSL_connect:SSLv3 read server key exchange A
    postfix/smtp[27198]: SSL_connect:SSLv3 read server done A
    postfix/smtp[27198]: SSL_connect:SSLv3 write client key exchange A
    postfix/smtp[27198]: SSL_connect:SSLv3 write change cipher spec A
    postfix/smtp[27198]: SSL_connect:SSLv3 write finished A
    postfix/smtp[27198]: SSL_connect:SSLv3 flush data
    postfix/smtp[27198]: SSL_connect:SSLv3 read server session ticket A
    postfix/smtp[27198]: SSL_connect:SSLv3 read finished A
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: aspmx.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt1.aspmx.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt2.aspmx.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt3.aspmx.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt4.aspmx.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: gmail-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt1.gmail-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt2.gmail-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt3.gmail-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt4.gmail-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: gmr-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt1.gmr-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt2.gmr-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt3.gmr-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: alt4.gmr-smtp-in.l.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: mx.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: aspmx2.googlemail.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: aspmx3.googlemail.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: aspmx4.googlemail.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subjectAltName: aspmx5.googlemail.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25 CommonName mx.google.com
    postfix/smtp[27198]: gmail-smtp-in.l.google.com[173.194.67.26]:25: subject_CN=aspmx.l.google.com, issuer_CN=Google Internet Authority G2, fingerprint 88:C0:85:C8:CB:96:29:8F:4E:15:11:80:C5:9A:89:0D, pkey_fingerprint=E0:32:29:21:69:38:EA:F9:B6:0C:F6:BD:86:12:16:B9
    postfix/smtp[27198]: Trusted TLS connection established to gmail-smtp-in.l.google.com[173.194.67.26]:25: TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)
    postfix/smtp[27198]: DE6D0403EB: Server certificate not verified
    
    Run Code Online (Sandbox Code Playgroud)

有没有办法在前台运行的 Postfix 中调试 SMTP客户端?所有调试内容似乎都与 smtpd 进程有关。:-(

相关的进一步配置:

# postconf -n | grep -E "^(smtp_|tls_)"
smtp_tls_CAfile = /usr/local/share/ca-certificates/Gert_van_Dijk_Root_CA_2014.crt
smtp_tls_security_level = secure
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
tls_append_default_CA = yes

# /etc/postfix/master.cf:
tlsmgr    unix  -       -       n       1000?   1       tlsmgr
smtp      unix  -       -       n       -       -       smtp -v
Run Code Online (Sandbox Code Playgroud)

mas*_*oeh 5

使用smtp_tls_security_level = secure默认值smtp_tls_secure_cert_match(smtp_tls_secure_cert_match = nexthop, dot-nexthop) 后缀不会信任来自 MX 记录的结果。换句话说,postfix 将使用从内部表(如传输表)获得的下一跳。

这就是为什么 postfix 仍然声明Server certificate not verify 的原因Postfix 文档明确指出

已验证(由受信任的 CA 签署的对等证书和经过验证的对等名称;或:具有预期公钥或证书指纹的对等证书)

Postfix SMTP 客户端:远程 SMTP 服务器的证书由 Postfix SMTP 客户端信任的 CA 签名,并且证书名称与目标或服务器名称匹配。Postfix SMTP 客户端被配置为需要经过验证的名称,否则验证状态将只是“受信任”。

您可以将 MX 记录的结果减少smtp_tls_security_levelverified使 postfix 信任并将其用于验证过程。另一种方式在postfix 文档中有所描述。

  • 没有传输 (5) 表覆盖的安全通道 TLS

    Postfix 将smtp_tls_policy_maps用来做验证过程。

  • 具有传输 (5) 表覆盖的安全通道 TLS:

    在这种情况下,example.com 及其相关域的流量被发送到单个逻辑网关(为避免单点故障,其名称可能会解析为一个或多个负载均衡器地址,或多个物理主机的组合地址)。通过网关的 IP 地址可访问的所有物理主机都在其证书中列出了逻辑网关名称。