作者的文章“
RHEL4上安装基于postfix的全功能邮件服务器(全部使用目前最新源码包构建) ”在Chinaunix上发表后,引起了许多网友的关注,其中更是有如
柳拂风和
Zenglingping在完成系统构建后又对作者的系统进行了一些扩充,现将他们的扩充转载至此处,以供有需要的朋友参照。
一、增加FCGI支持
为extmail增加FCGI的支持,主要是为了获得优异的web效能,克服CGI不能应付大量访问及低效率的缺陷。据说,FCGI的页面效率是CGI模式的十倍以上。
安装mod_fastcgi
mod_fastcgi 是针对Apache Web服务器的FCGI支持模块,
下载地址 [url]http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz[/url]
# tar -zxvf mod_fastcgi-2.4.6.tar.gz
# cd mod_fastcgi-2.4.6
# cp Makefile.AP2 Makefile
# make top_dir=/usr/local/apache install
除了Apache需要FCGI的支持外,extmail也需要相应的perl-FCGI模块。
下载地址 [url]http://dries.ulyssis.org/rpm/packages/perl-FCGI/info.html[/url]
用以下命令安装:
# rpm -ivh perl-FCGI-0.67-1.2.el5.rf.i386.rpm
(请安装跟你的操作系统版本对应的安装包)
在apache的配置文件的Extmail虚拟主机部分,添加如下内容:
LoadModule fastcgi_module modules/mod_fastcgi.so
<Ifmodule mod_fastcgi.c>
FastCgiExternalServer /var/www/extsuite/extmail/dispatch.fcgi -host 127.0.0.1:8888
</Ifmodule>
同时,去掉如下行:
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
Alias /extmail /var/www/extsuite/extmail/html
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman /var/www/extsuite/extman/html
改为:
Alias /extmail/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extmail /var/www/extsuite/extmail/html
Alias /extman/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extman /var/www/extsuite/extman/html
<Location "/extmail/cgi">
SetHandler fastcgi-script
</Location>
<Location "/extman/cgi">
SetHandler fastcgi-script
</Location>
然后编辑/var/www/extsuite/extmail/dispatch-init文件,修改如下:
SU_UID=vmail
SU_GID=vmail
BASE=/var/www/extsuite/extmail
启动fastcgi server:
# /var/www/extsuite/extmail/dispatch-init start
如果没有意外将启动5个dispatch.fcgi守护进程.
添加自启动:
# echo "/var/www/extsuite/extmail/dispatch-init start" >> /etc/rc.d/rc.local
重启apache
# /usr/local/apache/bin/apachectl restart
为extmail增加FCGI的支持,主要是为了获得优异的web效能,克服CGI不能应付大量访问及低效率的缺陷。据说,FCGI的页面效率是CGI模式的十倍以上。
安装mod_fastcgi
mod_fastcgi 是针对Apache Web服务器的FCGI支持模块,
下载地址 [url]http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz[/url]
# tar -zxvf mod_fastcgi-2.4.6.tar.gz
# cd mod_fastcgi-2.4.6
# cp Makefile.AP2 Makefile
# make top_dir=/usr/local/apache install
除了Apache需要FCGI的支持外,extmail也需要相应的perl-FCGI模块。
下载地址 [url]http://dries.ulyssis.org/rpm/packages/perl-FCGI/info.html[/url]
用以下命令安装:
# rpm -ivh perl-FCGI-0.67-1.2.el5.rf.i386.rpm
(请安装跟你的操作系统版本对应的安装包)
在apache的配置文件的Extmail虚拟主机部分,添加如下内容:
LoadModule fastcgi_module modules/mod_fastcgi.so
<Ifmodule mod_fastcgi.c>
FastCgiExternalServer /var/www/extsuite/extmail/dispatch.fcgi -host 127.0.0.1:8888
</Ifmodule>
同时,去掉如下行:
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
Alias /extmail /var/www/extsuite/extmail/html
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman /var/www/extsuite/extman/html
改为:
Alias /extmail/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extmail /var/www/extsuite/extmail/html
Alias /extman/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extman /var/www/extsuite/extman/html
<Location "/extmail/cgi">
SetHandler fastcgi-script
</Location>
<Location "/extman/cgi">
SetHandler fastcgi-script
</Location>
然后编辑/var/www/extsuite/extmail/dispatch-init文件,修改如下:
SU_UID=vmail
SU_GID=vmail
BASE=/var/www/extsuite/extmail
启动fastcgi server:
# /var/www/extsuite/extmail/dispatch-init start
如果没有意外将启动5个dispatch.fcgi守护进程.
添加自启动:
# echo "/var/www/extsuite/extmail/dispatch-init start" >> /etc/rc.d/rc.local
重启apache
# /usr/local/apache/bin/apachectl restart
二、设置反垃圾邮件网关
将此邮件系统套装设置成一个反垃圾邮件网关来使用,为没有过滤功能的邮件系统提供过滤服务。
前提是本postfix系统主机具有公网ip或做了端口映射(总之是能直接接收来自internet的邮件),
并能访问到旧邮件系统主机。
本例如下:
一个旧邮件系统example.com,
ip=211.147.xx.xx
已作如下域名解析
mail.example.com
pop3.example.com
smtp.example.com
都指向211.147.xx.xx
并做MX记录指向mail.example.com
因系统较老,没有垃圾邮件过滤功能,上面又有大量用户,不方便更换系统,
而购买商业反垃圾邮件网关又价格昂贵,拟使用本postfix系统来为其作垃圾邮件过滤。
旧邮件系统无须作任何更改,所有操作都是针对本postfix系统的。
新建域名解析mailgw.example.com,使其指向本postfix系统主机ip,
并修改原MX记录,使其指向mailgw.example.com
修改本postfix系统的配置:
# vi /etc/postfix/main.cf
在后面加入两行
relay_domains = example.com
transport_maps = hash:/etc/postfix/transport_maps
新建文件
# vi /etc/postfix/transport_maps
加入一行
example.com relay:[211.147.xx.xx]
生成db文件:
# /usr/local/postfix/sbin/postmap /etc/postfix/transport_maps
查看确认db文件已生成:
# ls -l /etc/postfix/transport_maps.db
-rw-r--r-- 1 root root 12288 02-01 14:45 /etc/postfix/transport_maps.db
重启postfix,
使用第三方邮件系统(比如网易邮箱)发送邮件到 [email]user@example.com[/email]进行测试,
查看/var/log/maillog,
成功的话可以看到如下信息:
Feb 1 17:25:43 vtest postfix/smtp[9330]: 81CAC458400: to=< [email]user@example.com[/email]>, relay=211.147.xx.xx[211.147.xx.xx]:25, delay=0.41, delays=0.26/0.03/0.08/0.05, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 3F57846098D)
Feb 1 17:25:43 vtest postfix/qmgr[9319]: 81CAC458400: removed
表明发往 [email]user@example.com[/email]的邮件已经被转发到211.147.xx.xx上了。
登陆旧邮件系统进行查收。
注:此邮件网关仅对来自internet的邮件进行过滤,而用户日常收发邮件仍然直接使用旧的系统,这样做对旧邮件系统几乎没有影响。
(参考资料:《POSTFIX权威指南》第九章)
将此邮件系统套装设置成一个反垃圾邮件网关来使用,为没有过滤功能的邮件系统提供过滤服务。
前提是本postfix系统主机具有公网ip或做了端口映射(总之是能直接接收来自internet的邮件),
并能访问到旧邮件系统主机。
本例如下:
一个旧邮件系统example.com,
ip=211.147.xx.xx
已作如下域名解析
mail.example.com
pop3.example.com
smtp.example.com
都指向211.147.xx.xx
并做MX记录指向mail.example.com
因系统较老,没有垃圾邮件过滤功能,上面又有大量用户,不方便更换系统,
而购买商业反垃圾邮件网关又价格昂贵,拟使用本postfix系统来为其作垃圾邮件过滤。
旧邮件系统无须作任何更改,所有操作都是针对本postfix系统的。
新建域名解析mailgw.example.com,使其指向本postfix系统主机ip,
并修改原MX记录,使其指向mailgw.example.com
修改本postfix系统的配置:
# vi /etc/postfix/main.cf
在后面加入两行
relay_domains = example.com
transport_maps = hash:/etc/postfix/transport_maps
新建文件
# vi /etc/postfix/transport_maps
加入一行
example.com relay:[211.147.xx.xx]
生成db文件:
# /usr/local/postfix/sbin/postmap /etc/postfix/transport_maps
查看确认db文件已生成:
# ls -l /etc/postfix/transport_maps.db
-rw-r--r-- 1 root root 12288 02-01 14:45 /etc/postfix/transport_maps.db
重启postfix,
使用第三方邮件系统(比如网易邮箱)发送邮件到 [email]user@example.com[/email]进行测试,
查看/var/log/maillog,
成功的话可以看到如下信息:
Feb 1 17:25:43 vtest postfix/smtp[9330]: 81CAC458400: to=< [email]user@example.com[/email]>, relay=211.147.xx.xx[211.147.xx.xx]:25, delay=0.41, delays=0.26/0.03/0.08/0.05, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 3F57846098D)
Feb 1 17:25:43 vtest postfix/qmgr[9319]: 81CAC458400: removed
表明发往 [email]user@example.com[/email]的邮件已经被转发到211.147.xx.xx上了。
登陆旧邮件系统进行查收。
注:此邮件网关仅对来自internet的邮件进行过滤,而用户日常收发邮件仍然直接使用旧的系统,这样做对旧邮件系统几乎没有影响。
(参考资料:《POSTFIX权威指南》第九章)
三、配置DNS缓存
发送邮件时,系统必须到DNS服务器上进行查询,如果自己有DNS服务器或者DNS缓存,会大大加快域名查询速度。
这里安装的是djbdns,如果你装有bind的话,就不要装这个了。
发送邮件时,系统必须到DNS服务器上进行查询,如果自己有DNS服务器或者DNS缓存,会大大加快域名查询速度。
这里安装的是djbdns,如果你装有bind的话,就不要装这个了。
进入本安装包install-djbdns-rpm目录运行install.sh安装,
注:install.sh最后两行的ip地址是广西电信的DNS服务器地址,运行前请修改为你所在区域的dns服务器地址。
(你也可以自己去下载djbdns的源码来编译安装,下载地址及安装教程 [url]http://cr.yp.to/djbdns.html[/url],这个貌似很麻烦~~)
启动
# /etc/init.d/djbdns start
启动正常的话会在53端口监听
验证djbdns是否起作用:
# dig [url]www.163.com[/url] (别的网站域名也可以)
再执行一次上述命令,应该能感觉到第二次运行时的响应速度明显比第一次快。
刷新DNS缓存:
有时候互联网上的DNS记录已经发生改变了,而你的DNS缓存还是旧的,可用如下命令来刷新
# /usr/bin/svc -t /service/dnscache
你也可以将上述命令写个脚本添加到crontab进行定期刷新:
# vi /root/flush_dns.sh
添加下行
/usr/bin/svc -t /service/dnscache
# chmod 755 /root/flush_dns.sh
# crontab -e
添加下行
1 1 * * * /root/flush_dns.sh
(这个本不应属于postfix邮件服务器的一部分的,加进来只是为了方便一点。如果你的邮件数量不是很多的话,作DNS缓存的意义不大;如果你经常往外大量群发邮件,就比较有用了。)
(你也可以自己去下载djbdns的源码来编译安装,下载地址及安装教程 [url]http://cr.yp.to/djbdns.html[/url],这个貌似很麻烦~~)
启动
# /etc/init.d/djbdns start
启动正常的话会在53端口监听
验证djbdns是否起作用:
# dig [url]www.163.com[/url] (别的网站域名也可以)
再执行一次上述命令,应该能感觉到第二次运行时的响应速度明显比第一次快。
刷新DNS缓存:
有时候互联网上的DNS记录已经发生改变了,而你的DNS缓存还是旧的,可用如下命令来刷新
# /usr/bin/svc -t /service/dnscache
你也可以将上述命令写个脚本添加到crontab进行定期刷新:
# vi /root/flush_dns.sh
添加下行
/usr/bin/svc -t /service/dnscache
# chmod 755 /root/flush_dns.sh
# crontab -e
添加下行
1 1 * * * /root/flush_dns.sh
(这个本不应属于postfix邮件服务器的一部分的,加进来只是为了方便一点。如果你的邮件数量不是很多的话,作DNS缓存的意义不大;如果你经常往外大量群发邮件,就比较有用了。)
以下是Zenglingping网友的扩充:
一、开启Postfix(smtp)的TLS功能
STARTTLS(TLS)介绍
TLS - Transport Layer Security ( 为网路 OSI 七层中的第四层加密技术,SSL - Secure Socket Layer 协定为之前身 )
SASL - Simple Authentication and Security Layer ( 简易的安全认证,SASL 同时也提供 SMTP 认证,定义在 RFC-2554 [url]http://www.ietf.org/rfc/rfc2554.txt[/url] )
Key - 安全连线金钥 ( key-pair ) CA - 授权凭证 ( Certification Authority )
网路上有些独立公正单位例如 VeriSign 及 GlobalSign 等等……它们就是专门贩卖安全金钥 Key 以及授权凭证 CA 的单位,我们这边採用自行製作安全金钥以及授权凭证,自行製作的安全金钥与授权凭证,在功能上与买来的相同,只是向独立公正单位购买来的 Key 跟 CA,会让 Client 使用者心理上觉得比较有保障,因为我们不做生意所以也不需要花钱买Key 跟 CA ,这边 Postfix + TLS 主要目的是保障我的连线加密防止帐号密码外洩。
(一)SMTP和STARTTLS
[转自Marion博客]
SMTP协议默认使用明文在网络传送用户名和密码,这是十分危险的。为此,Postfix使用TLS(Transport Layer Security)来解决这个潜在的危险问题。TLS不仅可以用来加密用户名和密码,还可以加密传送信件的内容。Sendmail使用starttls命令来启动一个SMTP会话加密进程(TLS会话)。Micorsoft的outlook软件和其它的许多MUA也支持STARTTLS。
STARTTLS能实现什么样的功能?
1.实现对一次E-MAIL通讯中server端以及client端彼此身份的校验;
2.加密传输信件(身份不能确认的情况下亦可以实现);
3.认证转发;
由于SMTP是一个存储转发协议,并且一封电子邮件的转交投递可能会涉及到多台SMTP服务器,因此,一个MUA就算能够通过认证并把E-MAIL加密传输至将要经过的第一台SMTP服务器,让最终用户的SMTP通过发送端的身份认证,并认为信件传送过程中没有被篡改也是不太可能的。故而,RFC文件声明说一个实现公共Email的SMTP服务器是不必苛求于在传送邮件中实现上述功能的。不过,对于一个私有网络中的邮件传输来讲,能够以要求必需提供有效证书来实现严格的身份认证和加密传输,因为我们可以将证书部署到需要传送EMAIL服务的每个客户端。
当然,尽管基于TLS的SMTP服务所提供的功能不像基于SSL的HTTP服务那样完美,但在服务器和客户端之间的一次认证会话间加密传输用户名和密码却是完全可以实现的。
(二)openssl简明使用手册
[转自Marion博客]
此处简要介绍了使用openssl来生成CA证书、申请证书、颁发证书以及撤销证书的过程,临时补上openssl一课。
1. 首先建立CA密钥:
openssl genrsa -des3 -out ca.key 1024 (创建密钥)
chmod 400 ca.key (修改权限为仅root能访问)
openssl rsa -noout -text -in ca.key (查看创建的证书)
2. 利用CA密钥自签署CA证书:
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
chmod 400 ca.crt (修改权限为仅root能访问)
openssl x509 -noout -text -in ca.crt (查看创建的证书)
3. 创建服务器证书签署申请:
openssl genrsa -des3 -out client.key 1024
chmod 400 server.key (修改权限为仅root能访问)
openssl rsa -noout -text -in client.key (查看创建的证书)
4. 利用证书签署申请生成请求:
openssl req -new -key client.key -out client.csr
openssl req -noout -text -in client.csr (查看创建的请求)
5.进行证书签署:
这时候需要先设置一下openssl的配置文件。
modify /usr/share/ssl/openssl.cnf并根据这个配置文件创建相应的目录和文件。
在创建了serial文件之后,还需要添加当前的八进制的serial number,如:01
然后执行:
openssl ca -keyfile ca.key -cert ca.crt -in client.csr -out client.pem
6.证书撤销:
openssl ca -keyfile ca.key -cert ca.crt -revoke client.pem
这时数据库被更新证书被标记上撤销的标志,需要生成新的证书撤销列表:
openssl ca -gencrl -keyfile ca.key -cert ca.crt -out crl/test.crl
查看证书撤销列表:
openssl crl -noout -text -in crl/test.crl
证书撤销列表文件要在WEB站点上可以使用,必须将crldays或crlhours和crlexts加到证书中:
openssl ca -gencrl -config /etc/openssl.cnf -crldays 7 -crlexts crl_ext -out crl/sopac-ca.crl
1. 制作CA证书与Private Key给Postfix SSL/TLS
#建立存放CA的文件夹(非必须)
使用CA.pl这个脚本可以方便的制作证书,将此脚本复制到刚刚建立的CA目录下
a. Become your own Certificate Authority, so that you can sign your own public key(官方原文)
执行perl脚本
b. Create an unpassworded private key for host mail.lanexpert.local and create an unsigned public key certificate.(官方原文,大意为创建一个没有密码的私有Key给主机和创建一个没有签名的公共Key证书)
c. Sign the public key certificate for host mail.lanexpert.local with the Certification Authority private key that we created a few steps ago.
d. Install the host private key, the host public key certificate, and the Certification Authority certificate files. This requires super-user privileges.(官方原文)
为了管理方便,将以上创建的证书全部复制到/etc/postfix目录下,并设置相应的权限
2. 修改Postfix配置文件,添加启用TLS选项
#nano /etc/postfix/main.cf
添加以下内容:
#nano /etc/postfix/master.cf
启用以下选项:
注意“-o”前面的空格
重新加载Postfix配置文件
检查并测试TLS是否启动成功
Smtp默认SSL端口是465
#telnet localhost 25 #测试是否启动TLS加密
在客户端(如Outlook)设置加密的smtp发信测试是否正常
经测试,使用加密后的smtp发送邮件是正常的。
配置文件部分参考资料: [url]http://www.postfix.org/TLS_README.html[/url]
PS.开始时没有按照官方文档配置(参考此文档 [url]http://www.lihuawei.cn/FreeBSD/d[/url] ... 2_courier-imap.html),出现如下错误(未解决),后来按照官方文档重新配置,此问题解决:
Report:同样telnet localhost 25 ‘out’表示自动出现的,’In’表示手动输入的
根据自己的实据情况作出相应的修改:
2.设置IMAPs(Port:993)证书产生的配置文件
3. 运行以下命令生成安全登陆认证的金钥imapd.pem和pop3d.pem文件,存放于/usr/local/courier-imap/share/目录下
检查证书文件是否成功生成:
4. 修改imapd-ssl及pop3d-ssl配置文件,启用imapd-ssl及pop3d-ssl
#nano /usr/local/courier-imap/etc/imapd-ssl
将 IMAPDSSLSTART=NO
改为:
#nano /usr/local/courier-imap/etc/pop3d-ssl
将POP3_STARTTLS=NO
改为:
保存并退出,重启courier-imapd 服务
检查imapd-ssl及pop3d-ssl启动是否正常:
从以上检查结果可知,993&995在正常监听状态中,基本上,imapd-ssl与pop3d-ssl正常启用并运行,可以在客户端(outlook)设置测试接收邮件是否正常来验正其实现情况。
配置部分参考资料: [url]http://www.lihuawei.cn/FreeBSD/d[/url] ... 2_courier-imap.html
STARTTLS(TLS)介绍
TLS - Transport Layer Security ( 为网路 OSI 七层中的第四层加密技术,SSL - Secure Socket Layer 协定为之前身 )
SASL - Simple Authentication and Security Layer ( 简易的安全认证,SASL 同时也提供 SMTP 认证,定义在 RFC-2554 [url]http://www.ietf.org/rfc/rfc2554.txt[/url] )
Key - 安全连线金钥 ( key-pair ) CA - 授权凭证 ( Certification Authority )
网路上有些独立公正单位例如 VeriSign 及 GlobalSign 等等……它们就是专门贩卖安全金钥 Key 以及授权凭证 CA 的单位,我们这边採用自行製作安全金钥以及授权凭证,自行製作的安全金钥与授权凭证,在功能上与买来的相同,只是向独立公正单位购买来的 Key 跟 CA,会让 Client 使用者心理上觉得比较有保障,因为我们不做生意所以也不需要花钱买Key 跟 CA ,这边 Postfix + TLS 主要目的是保障我的连线加密防止帐号密码外洩。
(一)SMTP和STARTTLS
[转自Marion博客]
SMTP协议默认使用明文在网络传送用户名和密码,这是十分危险的。为此,Postfix使用TLS(Transport Layer Security)来解决这个潜在的危险问题。TLS不仅可以用来加密用户名和密码,还可以加密传送信件的内容。Sendmail使用starttls命令来启动一个SMTP会话加密进程(TLS会话)。Micorsoft的outlook软件和其它的许多MUA也支持STARTTLS。
STARTTLS能实现什么样的功能?
1.实现对一次E-MAIL通讯中server端以及client端彼此身份的校验;
2.加密传输信件(身份不能确认的情况下亦可以实现);
3.认证转发;
由于SMTP是一个存储转发协议,并且一封电子邮件的转交投递可能会涉及到多台SMTP服务器,因此,一个MUA就算能够通过认证并把E-MAIL加密传输至将要经过的第一台SMTP服务器,让最终用户的SMTP通过发送端的身份认证,并认为信件传送过程中没有被篡改也是不太可能的。故而,RFC文件声明说一个实现公共Email的SMTP服务器是不必苛求于在传送邮件中实现上述功能的。不过,对于一个私有网络中的邮件传输来讲,能够以要求必需提供有效证书来实现严格的身份认证和加密传输,因为我们可以将证书部署到需要传送EMAIL服务的每个客户端。
当然,尽管基于TLS的SMTP服务所提供的功能不像基于SSL的HTTP服务那样完美,但在服务器和客户端之间的一次认证会话间加密传输用户名和密码却是完全可以实现的。
(二)openssl简明使用手册
[转自Marion博客]
此处简要介绍了使用openssl来生成CA证书、申请证书、颁发证书以及撤销证书的过程,临时补上openssl一课。
1. 首先建立CA密钥:
openssl genrsa -des3 -out ca.key 1024 (创建密钥)
chmod 400 ca.key (修改权限为仅root能访问)
openssl rsa -noout -text -in ca.key (查看创建的证书)
2. 利用CA密钥自签署CA证书:
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
chmod 400 ca.crt (修改权限为仅root能访问)
openssl x509 -noout -text -in ca.crt (查看创建的证书)
3. 创建服务器证书签署申请:
openssl genrsa -des3 -out client.key 1024
chmod 400 server.key (修改权限为仅root能访问)
openssl rsa -noout -text -in client.key (查看创建的证书)
4. 利用证书签署申请生成请求:
openssl req -new -key client.key -out client.csr
openssl req -noout -text -in client.csr (查看创建的请求)
5.进行证书签署:
这时候需要先设置一下openssl的配置文件。
modify /usr/share/ssl/openssl.cnf并根据这个配置文件创建相应的目录和文件。
在创建了serial文件之后,还需要添加当前的八进制的serial number,如:01
然后执行:
openssl ca -keyfile ca.key -cert ca.crt -in client.csr -out client.pem
6.证书撤销:
openssl ca -keyfile ca.key -cert ca.crt -revoke client.pem
这时数据库被更新证书被标记上撤销的标志,需要生成新的证书撤销列表:
openssl ca -gencrl -keyfile ca.key -cert ca.crt -out crl/test.crl
查看证书撤销列表:
openssl crl -noout -text -in crl/test.crl
证书撤销列表文件要在WEB站点上可以使用,必须将crldays或crlhours和crlexts加到证书中:
openssl ca -gencrl -config /etc/openssl.cnf -crldays 7 -crlexts crl_ext -out crl/sopac-ca.crl
1. 制作CA证书与Private Key给Postfix SSL/TLS
#建立存放CA的文件夹(非必须)
#mkdir /usr/local/postfix/CA
#cd /usr/local/postfix/CA/
#cd /usr/local/postfix/CA/
使用CA.pl这个脚本可以方便的制作证书,将此脚本复制到刚刚建立的CA目录下
#cp /usr/local/ssl/misc/CA.pl ./
a. Become your own Certificate Authority, so that you can sign your own public key(官方原文)
执行perl脚本
#perl CA.pl -newca [code]
回车后出现如下代码:
[code]CA certificate filename (or enter to create) #此处我直接回车,保持默认证书名称
Making CA certificate ...
Generating a 1024 bit RSA private key
.......++++++
...++++++
writing new private key to './demoCA/private/cakey.pem'
Enter PEM pass phrase: #输入密码
Verifying - Enter PEM pass phrase: #再次输入密码
-----
You are about to be asked to enter information that will be incorporated
into 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 blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN ←此处为国家名称代码
State or Province Name (full name) [Some-State]:GD ←此处为地域(省)名称
Locality Name (eg, city) []:DG ←此处为城市名称
Organization Name (eg, company) [Internet Widgits Pty Ltd]:lanexpert ←此处为单位名称
Organizational Unit Name (eg, section) []:IT ←此处为部分名称
Common Name (eg, YOUR name) []:lingping ←此处为你的名称或服务器名字或省略
Email Address []:lpzeng@lanexpert.cn ←此处为管理邮件
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456 ←输入密码
An optional company name []: ←输入公司名称或省略
Using configuration from /usr/local/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
c9:46:33:18:b3:8d:33:d2
Validity
Not Before: Jul 14 03:17:09 2008 GMT
Not After : Jul 14 03:17:09 2011 GMT
Subject:
countryName = CN
stateOrProvinceName = GD
organizationName = lanexpert
organizationalUnitName = IT
commonName = lingping
emailAddress = [email]lpzeng@lanexpert.cn[/email]
X509v3 extensions:
X509v3 Subject Key Identifier:
5F:5D:AB:C6:D1:8E:56:7E:01:24:12:16:70:3C:5F:F9:B2:FE:78:C7
X509v3 Authority Key Identifier:
keyid:5F:5D:AB:C6:D1:8E:56:7E:01:24:12:16:70:3C:5F:F9:B2:FE:78:C7
DirName:/C=CN/ST=GD/O=lanexpert/OU=IT/CN=lingping/emailAddress=lpzeng@lanexpert.cn
serial:C9:46:33:18:B3:8D:33:D2
X509v3 Basic Constraints:
CA:TRUE
Certificate is to be certified until Jul 14 03:17:09 2011 GMT (1095 days)
回车后出现如下代码:
[code]CA certificate filename (or enter to create) #此处我直接回车,保持默认证书名称
Making CA certificate ...
Generating a 1024 bit RSA private key
.......++++++
...++++++
writing new private key to './demoCA/private/cakey.pem'
Enter PEM pass phrase: #输入密码
Verifying - Enter PEM pass phrase: #再次输入密码
-----
You are about to be asked to enter information that will be incorporated
into 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 blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN ←此处为国家名称代码
State or Province Name (full name) [Some-State]:GD ←此处为地域(省)名称
Locality Name (eg, city) []:DG ←此处为城市名称
Organization Name (eg, company) [Internet Widgits Pty Ltd]:lanexpert ←此处为单位名称
Organizational Unit Name (eg, section) []:IT ←此处为部分名称
Common Name (eg, YOUR name) []:lingping ←此处为你的名称或服务器名字或省略
Email Address []:lpzeng@lanexpert.cn ←此处为管理邮件
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456 ←输入密码
An optional company name []: ←输入公司名称或省略
Using configuration from /usr/local/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
c9:46:33:18:b3:8d:33:d2
Validity
Not Before: Jul 14 03:17:09 2008 GMT
Not After : Jul 14 03:17:09 2011 GMT
Subject:
countryName = CN
stateOrProvinceName = GD
organizationName = lanexpert
organizationalUnitName = IT
commonName = lingping
emailAddress = [email]lpzeng@lanexpert.cn[/email]
X509v3 extensions:
X509v3 Subject Key Identifier:
5F:5D:AB:C6:D1:8E:56:7E:01:24:12:16:70:3C:5F:F9:B2:FE:78:C7
X509v3 Authority Key Identifier:
keyid:5F:5D:AB:C6:D1:8E:56:7E:01:24:12:16:70:3C:5F:F9:B2:FE:78:C7
DirName:/C=CN/ST=GD/O=lanexpert/OU=IT/CN=lingping/emailAddress=lpzeng@lanexpert.cn
serial:C9:46:33:18:B3:8D:33:D2
X509v3 Basic Constraints:
CA:TRUE
Certificate is to be certified until Jul 14 03:17:09 2011 GMT (1095 days)
b. Create an unpassworded private key for host mail.lanexpert.local and create an unsigned public key certificate.(官方原文,大意为创建一个没有密码的私有Key给主机和创建一个没有签名的公共Key证书)
# openssl req -new -nodes -keyout lp-key.pem -out lp-req.pem -days 3650
Generating a 1024 bit RSA private key
.++++++
...........................++++++
writing new private key to 'lp-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into 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 blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:DG
Organization Name (eg, company) [Internet Widgits Pty Ltd]:lanexpert
Organizational Unit Name (eg, section) []:IT
Common Name (eg, YOUR name) []:lingping
Email Address []:lpzeng@lanexpert.cn
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:
Generating a 1024 bit RSA private key
.++++++
...........................++++++
writing new private key to 'lp-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into 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 blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:DG
Organization Name (eg, company) [Internet Widgits Pty Ltd]:lanexpert
Organizational Unit Name (eg, section) []:IT
Common Name (eg, YOUR name) []:lingping
Email Address []:lpzeng@lanexpert.cn
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:
c. Sign the public key certificate for host mail.lanexpert.local with the Certification Authority private key that we created a few steps ago.
# openssl ca -out lp-cert.pem -infiles lp-req.pem
Using configuration from /usr/local/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
c9:46:33:18:b3:8d:33:d3
Validity
Not Before: Jul 14 03:19:53 2008 GMT
Not After : Jul 14 03:19:53 2009 GMT
Subject:
countryName = CN
stateOrProvinceName = GD
organizationName = lanexpert
organizationalUnitName = IT
commonName = lingping
emailAddress = [email]lpzeng@lanexpert.cn[/email]
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
21:B8:4C:AB:8D:D6:E3:E8:E1:14:E4:50:8E:0B:AF:C7:0D:08:4C:86
X509v3 Authority Key Identifier:
keyid:5F:5D:AB:C6:D1:8E:56:7E:01:24:12:16:70:3C:5F:F9:B2:FE:78:C7
Certificate is to be certified until Jul 14 03:19:53 2009 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
Using configuration from /usr/local/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
c9:46:33:18:b3:8d:33:d3
Validity
Not Before: Jul 14 03:19:53 2008 GMT
Not After : Jul 14 03:19:53 2009 GMT
Subject:
countryName = CN
stateOrProvinceName = GD
organizationName = lanexpert
organizationalUnitName = IT
commonName = lingping
emailAddress = [email]lpzeng@lanexpert.cn[/email]
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
21:B8:4C:AB:8D:D6:E3:E8:E1:14:E4:50:8E:0B:AF:C7:0D:08:4C:86
X509v3 Authority Key Identifier:
keyid:5F:5D:AB:C6:D1:8E:56:7E:01:24:12:16:70:3C:5F:F9:B2:FE:78:C7
Certificate is to be certified until Jul 14 03:19:53 2009 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
d. Install the host private key, the host public key certificate, and the Certification Authority certificate files. This requires super-user privileges.(官方原文)
为了管理方便,将以上创建的证书全部复制到/etc/postfix目录下,并设置相应的权限
#cp demoCA/cacert.pem lp-key.pem lp-cert.pem /etc/postfix/
#chmod 644 /etc/postfix/lp-cert.pem /etc/postfix/cacert.pem
#chmod 400 /etc/postfix/lp-key.pem
#chmod 644 /etc/postfix/lp-cert.pem /etc/postfix/cacert.pem
#chmod 400 /etc/postfix/lp-key.pem
2. 修改Postfix配置文件,添加启用TLS选项
#nano /etc/postfix/main.cf
添加以下内容:
# Smtp TLS config
smtp_use_tls = yes
smtp_tls_security_level = may
smtp_tls_session_cache_databases = btree:/var/lib/postfix/smtp_tls_session_cache
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/lp-key.pem (注意路径是否正确)
smtpd_tls_cert_file = /etc/postfix/lp-cert.pem (注意路径是否正确)
smtpd_tls_CAfile = /etc/postfix/cacert.pem (注意路径是否正确)
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_tls_security_level = may
smtpd_tls_session_cache_databases = btree:/var/lib/postfix/smtpd_tls_session_cache
tls_random_source = dev:/dev/urandom
smtp_use_tls = yes
smtp_tls_security_level = may
smtp_tls_session_cache_databases = btree:/var/lib/postfix/smtp_tls_session_cache
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/lp-key.pem (注意路径是否正确)
smtpd_tls_cert_file = /etc/postfix/lp-cert.pem (注意路径是否正确)
smtpd_tls_CAfile = /etc/postfix/cacert.pem (注意路径是否正确)
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_tls_security_level = may
smtpd_tls_session_cache_databases = btree:/var/lib/postfix/smtpd_tls_session_cache
tls_random_source = dev:/dev/urandom
#nano /etc/postfix/master.cf
启用以下选项:
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
注意“-o”前面的空格
重新加载Postfix配置文件
#postfix reload
检查并测试TLS是否启动成功
Smtp默认SSL端口是465
# netstat -tunlp |grep 465
tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 20559/master
tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 20559/master
#telnet localhost 25 #测试是否启动TLS加密
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 Welcome to our mail.lanexpert.cn ESMTP,Warning:Version not Available!
ehlo lanexpert.local
250-mail.lanexpert.local
250-PIPELINING
250-SIZE 14336000
250-VRFY
250-ETRN
250-STARTTLS #多出一行
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
Starttls #手动输入
220 2.0.0 Ready to start TLS #显示此字样为成功启用
quit
quit
Connection closed by foreign host.
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 Welcome to our mail.lanexpert.cn ESMTP,Warning:Version not Available!
ehlo lanexpert.local
250-mail.lanexpert.local
250-PIPELINING
250-SIZE 14336000
250-VRFY
250-ETRN
250-STARTTLS #多出一行
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
Starttls #手动输入
220 2.0.0 Ready to start TLS #显示此字样为成功启用
quit
quit
Connection closed by foreign host.
在客户端(如Outlook)设置加密的smtp发信测试是否正常
经测试,使用加密后的smtp发送邮件是正常的。
配置文件部分参考资料: [url]http://www.postfix.org/TLS_README.html[/url]
PS.开始时没有按照官方文档配置(参考此文档 [url]http://www.lihuawei.cn/FreeBSD/d[/url] ... 2_courier-imap.html),出现如下错误(未解决),后来按照官方文档重新配置,此问题解决:
Report:同样telnet localhost 25 ‘out’表示自动出现的,’In’表示手动输入的
Out: 220 Welcome to our mail.lanexpert.cn ESMTP,Warning:Version not Available!
In: ehlo lanexpert.cn
Out: 250-mail.lanexpert.local
Out: 250-PIPELINING
Out: 250-SIZE 14336000
Out: 250-VRFY
Out: 250-ETRN
Out: 250-STARTTLS
Out: 250-AUTH LOGIN PLAIN
Out: 250-AUTH=LOGIN PLAIN
Out: 250-ENHANCEDSTATUSCODES
Out: 250-8BITMIME
Out: 250 DSN
In: starttls
Out: 454 4.7.0 TLS not available due to local problem
In: quit
Out: 221 2.0.0 Bye
In: ehlo lanexpert.cn
Out: 250-mail.lanexpert.local
Out: 250-PIPELINING
Out: 250-SIZE 14336000
Out: 250-VRFY
Out: 250-ETRN
Out: 250-STARTTLS
Out: 250-AUTH LOGIN PLAIN
Out: 250-AUTH=LOGIN PLAIN
Out: 250-ENHANCEDSTATUSCODES
Out: 250-8BITMIME
Out: 250 DSN
In: starttls
Out: 454 4.7.0 TLS not available due to local problem
In: quit
Out: 221 2.0.0 Bye
二、启用POP3及IMAP加密功能
1.设置POP3s (Port:995)证书产生的配置文件
# nano /usr/local/courier-imap/etc/pop3d.cnf
根据自己的实据情况作出相应的修改:
RANDFILE = /usr/local/courier-imap/share/pop3d.rand
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no
[ req_dn ]
C=CN #国家代码
ST=GD #地域或省名称
L=DG #城市名称
O=lanexpert #组织名称
OU=IT #单位名称
CN=localhost
emailAddress=lpzeng@lanexpert.cn #管理邮件
[ cert_type ]
nsCertType = server
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no
[ req_dn ]
C=CN #国家代码
ST=GD #地域或省名称
L=DG #城市名称
O=lanexpert #组织名称
OU=IT #单位名称
CN=localhost
emailAddress=lpzeng@lanexpert.cn #管理邮件
[ cert_type ]
nsCertType = server
2.设置IMAPs(Port:993)证书产生的配置文件
# nano /usr/local/courier-imap/etc/imapd.cnf
RANDFILE = /usr/local/courier-imap/share/imapd.rand
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no
[ req_dn ]
C=CN
ST=GD
L=DG
O=lanexpert
OU=IT
CN=localhost
emailAddress=lpzeng@lanexpert.cn
[ cert_type ]
nsCertType = server
RANDFILE = /usr/local/courier-imap/share/imapd.rand
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no
[ req_dn ]
C=CN
ST=GD
L=DG
O=lanexpert
OU=IT
CN=localhost
emailAddress=lpzeng@lanexpert.cn
[ cert_type ]
nsCertType = server
3. 运行以下命令生成安全登陆认证的金钥imapd.pem和pop3d.pem文件,存放于/usr/local/courier-imap/share/目录下
#/usr/local/courier-imap/sbin/mkimapdcert
#/usr/local/courier-imap/sbin/mkpop3dcert
#/usr/local/courier-imap/sbin/mkpop3dcert
检查证书文件是否成功生成:
# ll /usr/local/courier-imap/share/*.pem
-rw------- 1 root root 1999 Jul 14 12:24 /usr/local/courier-imap/share/imapd.pem
-rw------- 1 root root 2003 Jul 14 12:24 /usr/local/courier-imap/share/pop3d.pem
-rw------- 1 root root 1999 Jul 14 12:24 /usr/local/courier-imap/share/imapd.pem
-rw------- 1 root root 2003 Jul 14 12:24 /usr/local/courier-imap/share/pop3d.pem
4. 修改imapd-ssl及pop3d-ssl配置文件,启用imapd-ssl及pop3d-ssl
#nano /usr/local/courier-imap/etc/imapd-ssl
将 IMAPDSSLSTART=NO
改为:
IMAPDSSLSTART=YES
#nano /usr/local/courier-imap/etc/pop3d-ssl
将POP3_STARTTLS=NO
改为:
POP3_STARTTLS=YES
保存并退出,重启courier-imapd 服务
service courier-imapd restart
检查imapd-ssl及pop3d-ssl启动是否正常:
# netstat -tunlp |grep :993
tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 21361/couriertcpd
# netstat -tunlp |grep :995
tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 21373/couriertcpd
tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 21361/couriertcpd
# netstat -tunlp |grep :995
tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 21373/couriertcpd
从以上检查结果可知,993&995在正常监听状态中,基本上,imapd-ssl与pop3d-ssl正常启用并运行,可以在客户端(outlook)设置测试接收邮件是否正常来验正其实现情况。
配置部分参考资料: [url]http://www.lihuawei.cn/FreeBSD/d[/url] ... 2_courier-imap.html
转载于:https://blog.51cto.com/marion/135642