Postfix + SASL2 認證
Postfix 和 SASL 的 SMTP 認證整合方式在網路上已經有多位前輩寫了不少的參考文件,內容也相當的豐富,小弟在此介紹的,也是很單純的 Postfix + SASL2 的認證方式,並且使用 Cyrus SASL 來做配合。
參考文件
所需套件
在您的 Linux 上,至少需要有 Cyrus SASL 函式庫,請使用下列方式查看是否已安裝了 cyrus-sasl 套件。
0001 0002 0003 0004 0005 0006 0007 |
root # rpm -qa | grep sasl cyrus-sasl-md5-2.1.18-2.2 cyrus-sasl-2.1.18-2 cyrus-sasl-2.1.18-2.2 cyrus-sasl-plain-2.1.18-2.2 cyrus-sasl-devel-2.1.18-2.2 root # |
若您的 SASL 函式庫安裝完成,請到 postfix 網頁下載原始碼,在此使用 postfix-2.4.10 的 tarball 來做示範。
重新產生 Makefile 並且指定 SASL 函式庫位置,若您之前已經先行編譯過,則必需先執行 make tidy 與 make clean 清空先前編譯所產生的檔案。
產生之後,請進行編譯動作並安裝。
0001 0002 |
root # make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl" AUXLIBS="-L/usr/lib -lsasl2" root # make && make install |
編輯 /etc/postfix/main.cf 檔案,在檔案最後加入以下參數:
0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 |
smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_sasl_authenticated reject_unauth_destination permit_mynetworks smtpd_sasl_authenticated_header = yes broken_sasl_auth_clients = yes smtpd_sasl_path = smtpd |
廣 告 |
設定 SASL
若您使用 yum 或是 RPM 進行安裝(Fedora 2∼Fedora 10、CentOS 4∼CentOS 5),則需查看 saslauthd 檔案的參數是否正確。
編輯 /etc/sysconfig/saslauthd
0001 |
root # vi /etc/sysconfig/saslauthd |
修改 MECH 的參數,在認證時使用系統 PAM 做帳號密碼認證。
0001 |
MECH=PAM |
接下來有一個重要的檔案,是 smtpd.conf,這個檔案在安裝完 SASL 函式庫後並不會出現,需要手動建立才行,若已經有這個檔案的話請開啟並編輯。
若您使用 RPM 安裝,請在 /usr/lib/sasl2 下建立 smtpd.conf 檔案。
0001 |
root # vi /usr/lib/sasl2/smtpd.conf |
smtpd.conf 檔案內容如下:
0001 |
pwcheck_method: saslauthd |
啟動 saslauthd,並且設定開機啟動。
0001 0002 |
root # service saslauthd start root # chkconfig saslauthd on |
請記得,此時應重新啟動 postfix 讓所有設定生效。
測試認證
首先,請使用 perl 建立帳號密碼的編碼。
以下的範例中,第一行 "\0test" 的 test 為帳號,第二個 "\0testuser" 的 testuser 為密碼,這一組帳號密碼需在系統中確實存在才行。
0001 0002 0003 |
root # perl -MMIME::Base64 -e 'print encode_base64("\0test\0testuser"); AHRlc3QAdGVzdHVzZXI= root # |
使用 telnet 測試是否認證成功。
在 SMTP 交易時,請使用 AUTH PLAIN 並加入剛剛使用 perl 所算出的加密編碼文字,若驗證成功,則表示 SASL 認證機制生效。
0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 |
root # telnet abc.com.tw 25 Trying 11.22.33.88... Connected to abc.com.tw (11.22.33.88). Escape character is '^]'. 220 abc.com.tw ESMTP Postfix EHLO abc.com.tw 250-abc.com.tw 250-SIZE 52428800 250-VRFY 250-ETRN 250-AUTH CRAM-MD5 PLAIN LOGIN DIGEST-MD5 250-AUTH=CRAM-MD5 PLAIN LOGIN DIGEST-MD5 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN AUTH PLAIN ABN0DXZlbgB0cWd0eTN3Ng3= 235 2.0.0 Authentication successful quit 221 2.0.0 Bye Connection closed by foreign host. root # |
使用者 Client 設定
Windows Mail 設定,需把“我的伺服器需要驗證”選取。
Mozilla Thunderbird 設定
01/07/2009