本文共 6460 字,大约阅读时间需要 21 分钟。
案例1:邮件TLS/SSL加密通信
1 案例1:邮件TLS/SSL加密通信
1.1 问题本案例要求为基于Postfix+Dovecot的邮件服务器提供加密通信支持,主要完成以下任务操作:
为SMTP服务(postfix)添加TLS/SSL加密通信支持基于dovecot配置POP3s+IMAPS加密通信支持客户端收发信测试,确保加密的邮件通信可用
1.2 方案
使用两台RHEL7虚拟机,其中svr7作为CA服务器,而mail作为测试用的Postfix+Dovecot邮件服务器。另外可准备一台pc120作为收发邮件的Windows测试机,安装邮件客户端软件或Outlook 2010。
1.3 步骤实现此案例需要按照如下步骤进行。
步骤一:准备一个简单的Postfix+Dovecot邮件服务器,支持SMTP认证
1) 快速安装邮件相关软件、添加邮箱账号
确认已安装postfix、dovecot、cyrus-sasl软件包,启动saslauthd服务:
[root@www ~]# yum -y install postfix dovecot cyrus-sasl.. ..[root@www ~]# vim /etc/sasl2/smtpd.confpwcheck_method: saslauthdmech_list: plain login[root@www ~]# service saslauthd start ; chkconfig saslauthd on正在启动 saslauthd: [确定]
添加两个邮箱账号mickey、minnie。
[root@www ~]# useradd mickey[root@www ~]# echo 123456 | passwd --stdin mickeyy更改用户 mickeyy 的密码 。passwd: 所有的身份验证令牌已经成功更新。[root@www ~]# useradd minnie[root@www ~]# echo 123456 | passwd --stdin minnie更改用户 minnie 的密码 。passwd: 所有的身份验证令牌已经成功更新。
2) 配置并启动postfix服务
[root@mail ~]# cd /etc/postfix/[root@mail postfix]# cp main.cf main.cf.origin[root@mail postfix]# vim main.cf.. ..myhostname = mail.tedu.cnmydomain = tedu.cnmyorigin = $mydomaininet_interfaces = allmydestination = $myhostname, localhost.$mydomain, localhost, $mydomainmynetworks = 127.0.0.0/8home_mailbox = Maildir/ //设置邮箱路径smtpd_sasl_auth_enable = yessmtpd_sasl_security_options = noanonymoussmtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination[root@mail postfix]# systemctl restart postfix[root@mail postfix]# netstat -anpt | grep mastertcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 32120/master
3) 配置并启动dovecot服务
[root@mail dovecot]# vim /etc/dovecot/conf.d/10-mail.confmail_location = maildir:~/Maildir //设置邮箱路径.. .. [root@mail dovecot]# vim /etc/dovecot/conf.d/10-ssl.conf.. ..ssl = no //先禁用SSL#ssl_cert =
4) 简单测试一下,确认未作TLS/SSL加密时邮件收发可用
由root给mickey用户发送一封邮件,确认mickey的邮箱能收到该邮件。
[root@mail ~]# echo "Hello Mickey" | mail -s "Test Mail XXXX" mickey@tedu.cn[root@mail ~]# cat /home/mickey/Maildir/new/137690.. //找最新的一封邮件Return-Path:X-Original-To: mickey@tedu.cnDelivered-To: mickey@tedu.cnReceived: by mail.tedu.cn (Postfix, from userid 0) id 28846836EA; Mon, 19 Aug 2017 17:36:58 +0800 (CST)Date: Mon, 19 Aug 2017 17:36:58 +0800To: mickey@tedu.cnSubject: Test Mail XXXXUser-Agent: Heirloom mailx 12.4 7/29/08MIME-Version: 1.0Content-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 7bitMessage-Id: <20130819093658.28846836EA@mail.tedu.cn>From: root@tedu.cn (root)Hello Mickey
步骤二:创建CSR证书签发申请,提交给CA服务器签署,下载签署后的证书
1) 在mail服务器上,创建服务私钥
由于此例中的私钥主要用于加密的邮件通信,为了方便服务控制,不要设置私钥口令(在postfix中也不好配置) 。
[root@mail ~]# cd /etc/pki/tls/private/[root@mail private]# openssl genrsa 2048 > mail.key //不设置私钥口令Generating RSA private key, 2048 bit long modulus............................................................+++................+++e is 65537 (0x10001)[root@mail private]# chmod 600 mail.key
2)在mail服务器上,创建CSR证书签发请求
基于前一步创建的服务私钥来建立CSR请求,根据提示设置的国家、省、市、组织信息要与CA根证书的设置保持一致。
[root@mail private]# openssl req -new -key mail.key > ~/mail.csrYou are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:BeijingLocality Name (eg, city) [Default City]:BeijingOrganization Name (eg, company) [Default Company Ltd]:Tedu Technology LtdOrganizational Unit Name (eg, section) []:Common Name (eg, your name or your server's hostname) []:mail.tedu.cnEmail Address []:postmaster@tedu.cnPlease enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:An optional company name []:
3)在CA服务器svr7上,签署并发布证书
首先获得mail服务器(比如SCP方式)提交的CSR证书签发请求文件,然后正式签署并通过httpd服务提供下载。
[root@svr7 ~]# scp 192.168.4.120:/root/mail.csr ./root@192.168.4.120's password:mail.csr 100% 1062 1.0KB/s 00:00 [root@svr7 ~]# cd /etc/pki/CA/certs/[root@svr7 certs]# openssl ca -in ~/mail.csr > mail.crt //签署证书Using configuration from /etc/pki/tls/openssl.cnfEnter pass phrase for /etc/pki/CA/private/my-ca.key: //验证私钥口令Check that the request matches the signatureSignature okCertificate Details: .. ..Certificate is to be certified until Aug 19 08:31:12 2014 GMT (365 days)Sign the certificate? [y/n]:y1 out of 1 certificate requests certified, commit? [y/n]yWrite out database with 1 new entriesData Base Updated [root@svr7 certs]# cp mail.crt /var/www/html/certs/ //复制到Web下载目录
4)在mail服务器上,下载签发好的证书文件,确认私钥、证书的存放路径
[root@mail ~]# cd /etc/pki/tls/certs/[root@mail certs]# wget http://192.168.4.7/certs/mail.crt.. ..2017-05-17 16:35:27 (300 MB/s) - 已保存 “mail.crt” [4633/4633])[root@mail certs]# ls -lh /etc/pki/tls/certs/mail.crt-rw-r--r--. 1 root root 4.6K 8月 19 16:32 /etc/pki/tls/certs/mail.crt[root@mail certs]# ls -lh /etc/pki/tls/private/mail.key-rw-------. 1 root root 1.7K 8月 19 16:22 /etc/pki/tls/private/mail.key
步骤三:分别为postfix、dovecot添加TLS/SSL加密通信支持
大多数情况下,加密的和非加密的服务会同时提供,允许邮箱用户自行选择 。当然,如果确实有需要,可以只提供加密的收发信服务,禁用非TLS/SSL加密的收发信服务。
1) 修改postfix服务配置,启用SSL加密通信
[root@svr7 ~]# vim .. ..smtpd_use_tls = yes#smtpd_tls_auth_only = yes //若启用此项,则非TLS的SMTP通信将被阻止smtpd_tls_key_file = /etc/pki/tls/private/mail.keysmtpd_tls_cert_file = /etc/pki/tls/certs/mail.crt#smtpd_tls_loglevel = 1 //排错阶段可启用此配置[root@mail ~]# service postfix reload重新载入postfix: [确定]
2)修改dovecot服务配置,启用SSL加密通信
[root@mail ~]# vim /etc/dovecot/conf.d/10-ssl.conf.. ..ssl = yes#ssl_cert =
注意:若要禁用非加密的POP3、IMAP通信,可以参考以下配置(可选)。
[root@mail ~]# vim /etc/dovecot/conf.d/10-master.confinet_listener imap { port = 0 //停用非加密的imap服务} inet_listener pop3 { port = 0 //停用非加密的pop3服务}
步骤四:在邮件客户端(比如Outlook Express)验证加密的邮件通信
1)为测试用户mickey配置邮件收发账号
设置好电子邮件地址、用户账号密码、收发信服务器等属性。接收邮件选POP3或IMAP,勾选安全连接(SSL) ,如图-1所示。
图-1
2)加密的收发信测试
新建一封测试邮件,发送给minnie@tedu.cn、抄送给自己,确认能够成功发送并接收邮件。首次发送邮件时会出现安全提示,如图-2所示,选“是”继续即可。
图-2
成功发出邮件以后,即可收取到抄送给自己的邮件,如图-3所示。
图-3
转载于:https://blog.51cto.com/13735155/2134584