如何使用加密技術為郵件服務器保駕護航?
譯文安全套接層(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]:BD State or Province Name (full name) [Some-State]:Dhaka Locality Name (eg, city) []:Dhaka Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []:Example.tst Common Name (e.g. server FQDN or YOUR name) []:mail.example.tst Email Address []:sarmed@example.tst
由于證書已準備就緒,可以調整postfix配置文件中的必要參數:
root@mail:~# vim /etc/postfix/main.cf ### STARTTLS已被啟用### smtpd_tls_security_level = may smtpd_tls_received_header = yes smtpd_tls_auth_only = yes ### 排查故障時,應該使用loglevel 3 ### smtpd_tls_loglevel = 1 ### 證書和密鑰文件的路徑 ### smtpd_tls_cert_file = /etc/ssl/certs/postfixcert.pem smtpd_tls_key_file = /etc/ssl/private/postfixkey.pem smtpd_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.509證書,保持365天有效。-nodes這個可選參數明確規定了存儲的私有密鑰不應該加密。輸出證書文件將是dovecotcert.pem,輸出密鑰文件將是dovecotkey.pem。
所有的必要參數需要在證書中加以明確指定:
Country Name (2 letter code) [AU]:BD State or Province Name (full name) [Some-State]:Dhaka Locality Name (eg, city) []:Dhaka Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []:Example.tst Common Name (e.g. server FQDN or YOUR name) []:mail.example.tst Email Address []:sarmed@example.tst
下一步,證書路徑添加到dovecot配置中。
root@mail:~# vim /etc/dovecot/conf.d/10-ssl.conf ssl_cert = ssl_key =
***,重啟dovecot,以便使用新證書啟用SSL。
root@mail:~# service dovecot restart
Thunderbird郵件客戶端配置
下面這個屏幕快照顯示了如何配置Mozilla Thunderbird中的帳戶。
故障排查
首先,確保所有的必要端口在防火墻中已被允許。
其次,試一試通過telnet連接到郵件服務器。你應該能夠連上去。下面給出了幾個例子,僅供參考。
連接到IMAPS
$ telnet mail.example.tst 993 Trying mail.example.tst... Connected to mail.example.tst. Escape character is '^]'. exit exit Connection closed by foreign host.
連接到POP3S
$ telnet mail.example.tst 995 Trying mail.example.tst... Connected to mail.example.tst. Escape character is '^]'. exit exit Connection closed by foreign host.
連接到SMTP
$ telnet mail.example.tst 25 Trying mail.example.tst... Connected to mail.example.tst. Escape character is '^]'. 220 mail.example.tst ESMTP Postfix (Ubuntu) ### 命令 ### ehlo mail.example.tst 250-mail.example.tst 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN
原文地址:http://xmodulo.com/2014/01/secure-mail-server-using-encryption.html