首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 认证考试-> Adobe认证
postfix + tls + sasl2 + courier-imap ( 建立加密及安全認證之郵件伺服器 )_qmail
作者:网友供稿 点击:0
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
Description :

TLS - Transport Layer Security ( 為網路 OSI 七層中的第四層加密技術,SSL - Secure Socket Layer 協定為之前身 )
SASL - Simple Authentication and Security Layer ( 簡易的安全認證,SASL 同時也提供 SMTP 認證,定義在 RFC-2554
http://www.ietf.org/rfc/rfc2554.txt )
Key - 安全連線金鑰 ( key-pair ) CA - 授權憑證 ( Certification Authority )

網路上有些獨立公正單位例如 VeriSign 及 GlobalSign 等等、、、它們就是專門販賣安全金鑰 Key 以及授權憑證 CA 的單位,我們
這邊採用自行製作安全金鑰以及授權憑證,自行製作的安全金鑰與授權憑證在功能上與買來的相同只是向獨立公正單位購買來的 Key 跟 CA會讓 Client 使用者心理上覺得比較有保障因為我們不做生意所以也不需要花錢買Key 跟 CA ,這邊 Postfix + TLS 主要目的是保障我的連線加密防止帳號密碼外洩

Environment :

硬體:i386 PC Intel Pentium III 500
記憶體:
256M RAM
作業系統:
FreeBSD 6.0 Release

Setp 1. 伺服器的 SMTP 安全強化


#cd /usr/ports/mail/postfix
# 安裝 Postfix MTA 郵件伺服器軟體
#make install clean

※ 出現的第一個選單只選擇 SASL 跟 TLS

[X] SASL2 Cyrus SASLv2 (Simple Authentication and Security Layer)
[X] TLS SSL and TLS
[X] DB41 Berkeley DB4.1 (required if SASL also built with DB4.1)

You need user "postfix" added to group "mail".
Would you like me to add it [y]? y

Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y

# cd /usr/ports/security/cyrus-sasl2-saslauthd # 安裝 cyrus-sasl2-saslauthd
#make install clean


#vi /etc/rc.conf
# 關閉 sendmail , 在 FreeBSD 中 Sendmail 預設是開機會自動啟動 127.0.0.1 本機的 MTA 功能,同時也加入開機自動啟動 postfix 及 saslauthd

sendmail_enable="NONE"
postfix_enable="YES"
saslauthd_enable="YES"

#ls -l /usr/local/etc/sasldb* # 查看 sasdb 檔權限因為 postfix 要使用 SASL 認證必須要對 sasldb 有讀取的權限

-rw-r----- 1 cyrus mail 16384 6 13 02:52 sasldb2.db

# vi /etc/group # 把 postfix 代理使用者加入 cyrus 群組 postfix 便可讀取 sasldb 檔

cyrus:*:60:postfix


#vi /usr/local/etc/postfix/main.cf # 修改 postfix 設定檔 main.cf

myhostname = ms1.ntut.idv.tw
mydomain = nttu.idv.tw
alias_maps = hash:/usr/local/etc/postfix/aliases
smtpd_banner = $myhostname ESMTP
myorigin = $myhostname
mynetworks = $myhostname, 127.0.0.1
home_mailbox = Maildir/


broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable= yes
smtpd_sasl_security_options= noanonymous
smtpd_sasl_local_domain =
smtpd_recipient_restrictions = permit_sasl_authenticated, check_relay_domains

#vi master.conf # 修改 master.conf 中的 smtp 及 smtps,smtps 是開 465 port 提供 outlook express 做加密傳輸使用

smtp inet n n n - - smtpd
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes

#postalias /usr/local/etc/postfix/aliases # 製做 aliases.db 檔

#vi /usr/local/lib/sasl2/smtpd.conf # 編寫 SASL smtpd 的認證方式採用 plain login

pwcheck_method: saslauthd
mechlist: plain login crammd5 digestmd5

#vi /usr/local/etc/rc.d/saslauthd.sh # 修改 saslauthd.sh

原本 >> saslauthd_flags=${saslauthd_flags:-"-a pam"}
改為 >> saslauthd_flags=${saslauthd_flags:-"-a getpwent"}

#reboot # 重新開機自動啟動 saslauthd 及 postfix

#ps -aux | grep saslauthd # 再次確認 saslauthd 有無啟動

584 ?? Is 0:00.01 /usr/local/sbin/saslauthd -a getpwent
585 ?? I 0:00.00 /usr/local/sbin/saslauthd -a getpwent
586 ?? I 0:00.00 /usr/local/sbin/saslauthd -a getpwent
587 ?? I 0:00.00 /usr/local/sbin/saslauthd -a getpwent
588 ?? I 0:00.00 /usr/local/sbin/saslauthd -a getpwent


#telnet localhost 25 # 測試 25 port 看是否多了兩行 250-AUTH
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.ntut.idv.tw.
Escape character is ^].
220 ms1.ntut.idv.tw ESMTP
ehlo locahost
250-ms1.ntut.idv.tw
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH NTLM LOGIN PLAIN GSSAPI DIGEST-MD5 CRAM-MD5
250-AUTH=NTLM LOGIN PLAIN GSSAPI DIGEST-MD5 CRAM-MD5

250 8BITMIME
quit
221 Bye
Connection closed by foreign host.

Setp 2. 伺服器的 SMTP 憑證製作

#cd /usr/ports/security/openssl
# 安裝 openssl 的目的為產生 CA.pl 這支 perl 程式,好讓我們可以輕鬆產生金鑰
#make install clean

#mkdir /usr/local/etc/postfix/CA
# 建立 CA 存放的資料夾
#cd /usr/local/etc/postfix/CA
#cp /usr/local/openssl/misc/CA.pl ./ # 將 CA.pl 這支 perl 程式 copy 到剛剛建立的 CA 目錄


# perl CA.pl -newca

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]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taichung
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ERA
Organizational Unit Name (eg, section) []:ISP
Common Name (eg, YOUR name) []:ms1.ntut.idv.tw
Email Address []:xxxxx@gmail.com

#openssl req -nodes -config /usr/local/openssl/openssl.cnf -new -days 3650 -newkey rsa:1024 -keyout serverkey.pem -out serverreq.pem
Generating a 1024 bit RSA private key
......++++++
...............++++++
writing new private key to serverkey.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]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taichung
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ERA
Organizational Unit Name (eg, section) []:ISP
Common Name (eg, YOUR name) []:ms1.ntut.idv.tw
Email Address []:xxxxxx@gmail.com

Please enter the following extra attributes
to be sent with your certificate request
A challenge password []: ( 輸入密碼 )
An optional company name []:ERA

#openssl ca -config /usr/local/openssl/openssl.cnf -policy policy_anything -out servercert.pem -infiles serverreq.pem
Using configuration from /usr/local/openssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
96:a5:d5:76:64:ad:3f:31
Validity
Not Before: Apr 13 01:52:30 2006 GMT
Not After : Apr 13 01:52:30 2007 GMT
Subject:
countryName = TW
stateOrProvinceName = Taiwan
localityName = Taichung
organizationName = ERA
organizationalUnitName = ISP
commonName = ms1.ntut.idv.tw
emailAddress = xxxxx@gmail.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
32:98:18:2A:98:B9:03:EC:A2:A9:E5:1A:C9:09:82:6B:95:5D:D2:D3
X509v3 Authority Key Identifier:
keyid:66:9D:78:67:61:75:95:B0:60:72:59:F5:77:4B:83:0D:D1:E4:B7:E8
DirName:/C=TW/ST=Taiwan/L=Taichung/O=ERA/OU=ISP/CN=ms1.ntut.idv.tw/emailAddress=xxxxx@gmail.com
serial:96:A5:D5:76:64:AD:3F:30

Certificate is to be certified until Apr 13 01:52:30 2007 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

#cat serverkey.pem servercert.pem > post.pem

#vi /usr/local/etc/postfix/main.cf
# 將 Postfix 的 smtpd 加入 TLS 設定

smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /usr/local/etc/postfix/CA/post.pem
smtpd_tls_cert_file = /usr/local/etc/postfix/CA/post.pem
smtpd_tls_CAfile = /usr/local/etc/postfix/CA/post.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
mtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

#postfix reload
# 重新啟動 postfix

#telnet loadlhost 25
# 測試是否啟動 TLS 加密,手動輸入 STARTTLS 如果成功會回應下面那行紅字

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.ntut.idv.tw.
Escape character is ^].
220 ms1.ntut.idv.tw ESMTP
ehlo localhost
250-ms1.ntut.idv.tw
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH NTLM LOGIN PLAIN GSSAPI DIGEST-MD5 CRAM-MD5
250-AUTH=NTLM LOGIN PLAIN GSSAPI DIGEST-MD5 CRAM-MD5

250 8BITMIME
STARTTLS
220 Ready to start TLS
quit
quit

221 Bye
Connection closed by foreign host.

※ SMTP 在 Client 端設定方式若以 Outlook Express 的設定方式如下:

圖 (一)、讓 Outlook Express 支援驗證 ( 可預防 Mail Relay )

在 Outlook Express
《工具》《帳戶》《郵件》《內容》《伺服器》中
把『 外寄郵件伺服器 』、『 我的外寄伺服器需要驗證 』打勾,就可以使用身分認證機制。

圖 (二)、讓 Outlook Express 支援 SSL/TLS 加密的郵件伺服器 ( 加密後可預防帳號密碼資料被竊取,就算資料被從中竊取也是加密的資料很難破解 )

必須向使用 Outlook Express 的使者宣導改用 SSL/TLS 來做寄信的動作,客戶端只要在 Outlook Express 《工具》《帳戶》《郵件》《內容》《
進階》中
將『 伺機器連接戶號碼 』、『 外寄伺服器 - SMTP 』的 port 號從 25 port 改到 465 port 以及『 這個伺服器需要安全連線 - SSL 』打勾,就可以採用 TLS 加密連線了。

圖 (一) 圖 (二)

Setp 3. 設定 POP3 及 IMAP 加密

#cd /usr/ports/mail/courier-imap # 光讓發信 SMTP 加密還不夠,POP3 收信也得加密,這邊因為我們的 Postfix 採用 Maildir 格式所以我們安裝 Courier-imap
#make install

Options for courier-imap 4.0.6_1,1

[X] OPENSSL Build with OpenSSL support
# 因為採用 FreeBSD 本機上的帳號及密碼認證所以只選 openssl 不選其他種類的 AUTH

#cd /usr/local/etc/courier-imap
#cp pop3d.cnf.dist pop3d.cnf
# 設定 POP3s 995 port 金鑰產生設定檔

RANDFILE = /usr/local/share/courier-imap/pop3d.rand

[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
C=TW
ST=Taiwan
L=Taichung
O=ERA
OU=ISP
CN=localhost
emailAddress=xxxxx@gmail.com


[ cert_type ]
nsCertType = server

#cp imapd.cnf.dist imapd.cnf # 設定 IMAPs 993 port 金鑰產生設定檔

RANDFILE = /usr/local/share/courier-imap/imapd.rand

[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
C=TW
ST=Taiwan
L=Taichung
O=ERA
OU=ISP
CN=localhost
emailAddress=xxxxx@gmail.com

[ cert_type ]
nsCertType = server


#/usr/local/sbin/mkimapdcert
# 開始產生安全登入認證的金鑰 imapd.pem 及 pop3d.pem 檔,放置於 /usr/local/share/courier-iamp 下
#/usr/local/sbin/mkpop3dcert

#vi /etc/rc.conf
# 設定預設開機啟動程式

courier_authdaemond_enable="YES"
courier_imap_imapd_ssl_enable="YES"
courier_imap_pop3d_ssl_enable="YES"

#/usr/local/etc/rc.d/courier-authdaemond.sh start

#/usr/local/etc/rc.d/courier-imap-pop3d-ssl.sh start # 啟動 pop3s
#/usr/local/etc/rc.d/courier-imap-imapd-ssl.sh start # 啟動 imaps


# sockstat -l4
# 確定開啟的服務 port

USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root couriertcp 59481 3 tcp4 *:993 *:*
root couriertcp 59470 3 tcp4 *:995 *:*
root master 15580 11 tcp4 *:25 *:*
root master 15580 14 tcp4 *:465 *:*
root sshd 441 4 tcp4 *:22 *:*


※ POP3 在 Client 端設定方式若以 Outlook Express 的設定方式如下:

必須向使用 Outlook Express 的使者宣導改用 SSL/TLS 來收信,同時我們也關掉 110 port 讓這個不安全的協定 port 不再運行,客戶端只要在 Outlook Express 《工具》《帳戶》《郵件》《內容》《進階》中
將『 伺機器連接戶號碼 』、『 外寄伺服器 - POP3 』的 port 號從 110 port 改到 995 port 以及將『 這個伺服器需要安全連線 - SSL 』打勾,就可以採用加密連線了。

圖 (三)


參考資料:

http://www.hacker.org.tw/?c=articles_show%26amp;articleid=1225
http://www.ascc.sinica.edu.tw/nl/90/1713/02.txt


最後修改日期: 2006/04/14
最後修改:http://freebsd.ntut.idv.tw/document/postfix_tls_sasl2_courier-imap.html

文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·Java开发工具配置 UltraEdit-JSP教程,Java技巧及代码
·遍历设备管理器的设备-.NET教程,评论及其它
·用正则表达式剔除文本中的HTML标记-ASP教程,正则表达式
·一个通用的DataGridTableStyle的做法-.NET教程,数据库应用
·java连接Oracle数据库-JSP教程,Java技巧及代码
·将XML存入关系数据库-JSP教程,数据库相关
·如何在Web页面上直接打开、编辑、创建Office文档-ASP教程,ASP应用
·asp之日期和时间函数示例-ASP教程,ASP应用
·ASP.Net Web Page深入探讨-ASP教程,ASP应用
·浅析Microsoft .net PetShop程序中的购物车和订单处理模块(Profile技术,异步MSMQ消息)-.NET教程,.NET Framework
最新文章
·fireworks 8绘制精致指南针图案_fireworks教程
·卸载多重引导系统中的windows vista操作系统_windows vista
·如何做到google adsense好收入的几点_网赚技巧
·百度主题推广和google adsense的综合比较_网赚技巧
·[新闻会客厅]孙雁:八零后的女闪客_站长访谈
·“流量交换型站点”访客黏度问题凸显_站长心得
·大唐社区站长经验谈社区运营_站长心得
·blog站点如何用rss搜索来推广_站长心得
·自我防护web站点和恶意链接的方法_站长心得
·网站投资你和我的20个自身检查(2)_站长心得
相关主题
  • postfix + cyrus-imap + cyrus-sasl + mysql + imp 完全指南_qmail
  • postfix 邮件病毒过滤_qmail
  • postfix + courier-imap + cyrus-sasl + mysql + imp完全指南(新版)_qmail
  • postfix + spamassassin 安裝手冊_qmail
  • postfix + cyrus-sasl + cyrus-imapd + pgsql howto_qmail
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭