如何使用加密技术为邮件服务器保驾护航?

译文
安全 数据安全
TLS/SSL所需的证书可以是自签名、由免费的认证机构(比如CAcert)签名,或者由商业认证机构(比如VeriSign)签名,可以借助OpenSSL等实用工具来生成。

安全套接层(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

责任编辑:蓝雨泪 来源: 51CTO.com
相关推荐

2019-03-22 08:39:14

NginxWeb服务器Linux

2012-09-12 09:40:36

云服务GIS技术弹性云计算

2014-05-16 09:38:14

2011-12-16 11:11:24

戴尔

2018-08-24 11:03:49

邮件归档

2012-05-21 09:38:43

2013-06-28 11:35:13

方物

2014-09-04 09:18:15

2010-11-04 15:32:05

SecSSM服务器安全网神

2012-11-13 18:24:03

LinOTPApache2一次性密码

2015-08-19 10:06:21

2013-11-08 11:03:37

2022-07-28 09:54:41

Testin

2010-06-21 14:45:00

2015-08-24 16:34:54

咻咻验证码

2010-06-14 23:32:04

综合布线机场西蒙

2018-04-11 07:06:04

物联网鲜花冷链物联网应用

2011-11-29 14:13:22

StrixMesh

2012-06-25 16:57:07

2013-12-09 16:16:29

初志科技数据动车
点赞
收藏

51CTO技术栈公众号