安全套接层(SSL)及其后续版本:传输层安全(TLS)加密服务器和客户机之间传输的数据是两种应用最广泛的协议。这些协议经常被使用X.509证书及非对称加密方法。
STARTTTLS另一种保证明文通信安全的方法。该协议也被使用SSL或TLS,加密数据,但使用与明文协议相同的端口,而不是使用其他端口传输SSL/TLS加密数据。例如,基于STARTTLS的IMAP使用与IMAP基于同一端口(端口143)SSL的IMAP(IMAPS)使用单独的端口:993端口。
前一个教程(http://xmodulo.com/2014/01/mail-server-ubuntu-debian.html)介绍了如何搭建一个Postfix和Dovecot运行在上面的邮件服务器,但没有讨论安全问题。在本教程中,我们将演示如何基于它TLS/SSL加密技术为邮件服务器增加了安全性。
TLS/SSL所需证书可由免费认证机构自行签名(如CAcert)或由商业认证机构签字(如VeriSign)可以借助签名OpenSSL生成实用工具。我们准备在本教程中使用自签证书。
为Postfix登记TLS加密
以下命令可以创建自签证书。
# openssl req -new -x509 -days 365 -nodes -out /etc/ssl/certs/postfixcert.pem -keyout /etc/ssl/private/postfixkey.pem上述命令要求新证书,证书类型为X.509,保持365天有效。-nodes参数明确规定私钥不得加密。出口证书文件作为postfixcert.pem保存,输出密钥文件作为postfixkey.pem保存起来。
所有必要的证书都可以赋予:
Country Name (2 letter code) [AU]:BDState or Province Name (full name) [Some-State]:DhakaLocality Name (eg,city) []:DhakaOrganization Name (eg,company) [Internet Widgits Pty Ltd]:Organizational Unit Name (eg,section) []:Example.tstCommon Name (e.g. server FQDN or YOUR name) []:mail.example.tstEmail Address []:sarmed@example.tst由于证书已准备就绪,可以调整postfix配置文件中的必要参数:
root@mail:~# vim /etc/postfix/main.cf### STARTTLS已被启用###smtpd_tls_security_level = maysmtpd_tls_received_header = yessmtpd_tls_auth_only = yes### 故障排除时应使用 loglevel 3 ###smtpd_tls_loglevel = 1### 证书和密钥文件的路径 ###smtpd_tls_cert_file = /etc/ssl/certs/postfixcert.pemsmtpd_tls_key_file = /etc/ssl/private/postfixkey.pemsmtpd_use_tls=yes重启postfix,以启用TLS。
root@mail:~# service postfix restart至此,postfix已准备对发到和来自服务器的数据进行加密。关于Postfix TLS官方可以支持更多的详细信息README(http://www.postfix.org/TLS_README.html)中找到。
为Dovecot启用SSL加密
加密配置dovecot的方法与postfix大同小异。
首先,使用自签证书openssl来创建:
# openssl req -new -x509 -days 365 -nodes -out /etc/ssl/certs/dovecotcert.pem -keyout /etc/ssl/private/dovecotkey.pem上述命令要求新的X.509365天有效证书。-nodes可选参数明确规定存储的私钥不应加密。输出证书文件将是dovecotcert.pem,将是输出密钥文件dovecotkey.pem。
证书中应明确规定所有必要参数:
Country Name (2 letter code) [AU]:BDState or Province Name (full name) [Some-State]:DhakaLocality Name (eg,city) []:DhakaOrganization Name (eg,company) [Internet Widgits Pty Ltd]:Organizational Unit Name (eg,section) []:Example.tstCommon Name (e.g. server FQDN or YOUR name) []:mail.example.tstEmail Address []:sarmed@example.tst下一步,添加证书路径dovecot配置中。
root@mail:~# vim /etc/dovecot/conf.d/10-ssl.confssl_cert =ssl_key =***,重启dovecot,使用新证书使用SSL。
root@mail:~# service dovecot restartThunderbird邮件客户端配置
下面的屏幕快照显示了如何配置Mozilla Thunderbird中的帐户。
故障排查
首先,确保防火墙允许所有必要的端口。
其次,试着通过telnet连接到邮件服务器。您应该能够连接它。以下是一些仅供参考的例子。
连接到IMAPS
$ telnet mail.example.tst 993Trying mail.example.tst...Connected to mail.example.tst.Escape character is '^]'.exitexitConnection closed by foreign host.连接到POP3S
$ telnet mail.example.tst 995Trying mail.example.tst...Connected to mail.example.tst.Escape character is '^]'.exitexitConnection closed by foreign host.连接到SMTP
$ telnet mail.example.tst 25Trying mail.example.tst...Connected to mail.example.tst.Escape character is '^]'.220 mail.example.tst ESMTP Postfix (Ubuntu)### 命令 ###ehlo mail.example.tst250-mail.example.tst250-PIPELINING250-SIZE 10240000250-VRFY250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN原文地址:http://xmodulo.com/2014/01/secure-mail-server-using-encryption.html