后缀“警告:无法从文件中获取 RSA 私钥”

phe*_*hew 15 postfix ssl-certificate

我只是按照本教程设置了一个 postfix 邮件服务器,使用 dovecot 和 mysql 作为虚拟用户的后端。

现在我得到了大部分工作,我可以连接到 POP3(S) 和 IMAP(S)。

使用

echo TEST-MAIL | mail myaccount@hotmail.com
Run Code Online (Sandbox Code Playgroud)

工作正常,当我登录到我的 hotmail 帐户时,它会显示电子邮件。

它也可以反向工作,因此我的example.com 的MX 条目终于被传播了,所以我能够接收从myaccount@hotmail.com发送到myvirtualuser@example.com 的电子邮件,并通过 IMAP 使用 STARTTLS 在 Thunderbird 中查看它们。

在尝试使用登录myvirtualuser@example.com 的Thunderbird向myaccount@hotmail.com发送邮件时收到错误消息“ 5.7.1:中继访问被拒绝”后,我做了更多研究,我发现我的服务器正在运行作为“开放邮件中继”,这当然是一件坏事。

深入研究本教程的可选部分(如此评论其他教程),我决定也完成这些步骤,以便能够通过 Mozilla Thunderbird通过myvirtualuser@example.com发送邮件,而不会收到错误消息“ 5.7.1” :中继访问被拒绝”(因为普通邮件服务器拒绝打开的中继电子邮件)。

但是现在我遇到了一个错误,试图让 postfix 与 SMTPS 一起工作,在/var/log/mail.log 中它读取

Sep 28 17:29:34 domain postfix/smtpd[20251]: warning: cannot get RSA private key from file /etc/ssl/certs/postfix.pem: disabling TLS support
Sep 28 17:29:34 domain postfix/smtpd[20251]: warning: TLS library problem: 20251:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:650:Expecting: ANY PRIVATE KEY:
Sep 28 17:29:34 domain postfix/smtpd[20251]: warning: TLS library problem: 20251:error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib:ssl_rsa.c:669:
Run Code Online (Sandbox Code Playgroud)

在我尝试使用 SMTP SSL/TLS 通过 Thunderbird 中的端口 465 从我新安装的邮件服务器发送邮件后,立即记录了该错误。Thunderbird 然后告诉我发生了超时。

谷歌有一些关于这个问题的结果,但我无法解决这些问题。我会在这里链接其中一些,但作为新用户,我只能使用两个超链接。

我的/etc/postfix/master.cf看起来像

smtp      inet  n       -       -       -       -       smtpd
smtps     inet  n       -       -       -       -       smtpd
   -o smtpd_tls_wrappermode=yes
   -o smtpd_sasl_auth_enable=yes
Run Code Online (Sandbox Code Playgroud)

NMAP告诉我

PORT     STATE SERVICE
[...]
465/tcp  open  smtps
[...]
Run Code Online (Sandbox Code Playgroud)

我的/etc/postfix/main.cf看起来像

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
readme_directory = no
#smtpd_tls_cert_file = /etc/ssl/certs/postfix.pem            #default postfix generated
#smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key #default postfix generated
smtpd_tls_cert_file = /etc/ssl/certs/postfix.pem
smptd_tls_key_file = /etc/ssl/private/postfix.pem
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smptd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

myhostname = example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.com, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
mailbox_command = /usr/lib/dovecot/deliver
Run Code Online (Sandbox Code Playgroud)

*.pem 文件是按照上面教程中的描述创建的,使用

Postfix
To create a certificate to be used by Postfix use:

openssl req -new -x509 -days 3650 -nodes -out /etc/ssl/certs/postfix.pem -keyout /etc/ssl/private/postfix.pem

Do not forget to set the permissions on the private key so that no unauthorized people can read it:

chmod o= /etc/ssl/private/postfix.pem

You will have to tell Postfix where to find your certificate and private key because by default it will look for a dummy certificate file called "ssl-cert-snakeoil":

postconf -e smtpd_tls_cert_file=/etc/ssl/certs/postfix.pem
postconf -e smtpd_tls_key_file=/etc/ssl/private/postfix.pem
Run Code Online (Sandbox Code Playgroud)

我想我不必在这里包含/etc/dovecot/dovecot.conf,因为根据日志,通过 imaps 和 pop3s 登录工作正常。唯一的问题是使 postfix 正确使用自生成的自签名证书。

任何帮助表示赞赏!

编辑: 我刚刚尝试了有关为 postfix 生成自签名证书的不同教程,但仍然遇到相同的错误。我真的不知道还有什么要测试的。

我也确实检查了 SSL 库,但一切似乎都很好:

  root@domain:~# ldd /usr/sbin/postfix
    linux-vdso.so.1 =>  (0x00007fff91b25000)
    libpostfix-global.so.1 => /usr/lib/libpostfix-global.so.1 (0x00007f6f8313d000)
    libpostfix-util.so.1 => /usr/lib/libpostfix-util.so.1 (0x00007f6f82f07000)
    libssl.so.0.9.8 => /usr/lib/libssl.so.0.9.8 (0x00007f6f82cb1000)
    libcrypto.so.0.9.8 => /usr/lib/libcrypto.so.0.9.8 (0x00007f6f82910000)
    libsasl2.so.2 => /usr/lib/libsasl2.so.2 (0x00007f6f826f7000)
    libdb-4.8.so => /usr/lib/libdb-4.8.so (0x00007f6f8237c000)
    libnsl.so.1 => /lib/libnsl.so.1 (0x00007f6f82164000)
    libresolv.so.2 => /lib/libresolv.so.2 (0x00007f6f81f4e000)
    libc.so.6 => /lib/libc.so.6 (0x00007f6f81beb000)
    libdl.so.2 => /lib/libdl.so.2 (0x00007f6f819e7000)
    libz.so.1 => /usr/lib/libz.so.1 (0x00007f6f817d0000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00007f6f815b3000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f6f83581000)
Run Code Online (Sandbox Code Playgroud)

在遵循Ansgar Wiechers 的指示之后,它终于可以工作了。

postconf -n包含应有的行。通过 openssl 进行的证书/密钥检查确实表明这两个文件都是有效的。

所以确实是权限问题!不知道将 /etc/ssl/*/postfix.pem 文件转换为 postfix:postfix 不足以让 postfix 读取文件。

Ans*_*ers 17

的内容main.cf不一定代表您活动的 Postfix 配置。检查postconf -n以下两个参数的输出:

smtpd_recipient_restrictions = 
  permit_mynetworks, 
  permit_sasl_authenticated, 
  reject_unauth_destination
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Run Code Online (Sandbox Code Playgroud)

如果$mynetworks被限制为 localhost 并且$smtpd_recipient_restrictions显示permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination为前三个限制,那么你不是一个开放的中继。

验证/etc/ssl/private/postfix.pem包含有效密钥和/etc/ssl/certs/postfix.pem有效证书:

openssl rsa -in /etc/ssl/private/postfix.pem -check -noout
openssl x509 -in /etc/ssl/certs/postfix.pem -text -noout
Run Code Online (Sandbox Code Playgroud)

您还需要检查 Postfix 是否可以访问该文件。在我的服务器上,权限/etc/ssl/private

drwx--x---  2 root ssl-cert  4096 Aug 03 01:55 private/
Run Code Online (Sandbox Code Playgroud)

因此,简单地chown输入密钥文件对您没有任何好处,因为目录权限会阻止 Postfix 访问其中的任何文件。

尝试简化您的设置。将证书和密钥放入一个文件中:

cat /etc/ssl/*/postfix.pem > /etc/postfix/server.pem
chmod 640 /etc/postfix/server.pem
chown postfix:postfix /etc/postfix/server.pem
Run Code Online (Sandbox Code Playgroud)

main.cf像这样改变你:

smtpd_tls_cert_file = /etc/postfix/server.pem
smtpd_tls_key_file = $smtpd_tls_cert_file
Run Code Online (Sandbox Code Playgroud)

重启Postfix,看看服务器是否可以访问key。