精華區beta FreeBSD 關於我們 聯絡資訊
http://giayiu.adsldns.org/FreeBSD/Sendmail_SASL2_TLS(SSL).htm * 本文可以任意轉載,但是請不要篡名。 * 有錯誤的地方,煩請告知,謝謝。 要在 Sendmail 上面建立 SSL 連線,首先您要有伺服器憑證。 假如您尚未有伺服器憑證,請買一個、要一個、請別人做一個, 或者參考其它文章自行製作。 ‧自行製作憑證請注意: 憑證名稱 (Common Name) 請與伺服器名稱相同 (Server Name)。 製作好的憑證在使用上可能會出現「憑證無效」、「憑證無法驗證」等的訊息。 因為這些憑證的簽發者不是客戶端所已知且被信任的, 所以您需要將簽發此憑證的根憑證發散出去給需要用到這些憑證的使用者。 在 Internet Explorer 上,下載根憑證後開啟可以將憑證匯入系統之內, 日後此根憑證所簽發的憑證都會被信任。 注意:發散的是憑證檔 (.crt, ex. RootCA.crt), 不是 Private Key (.key, ex. RootCA.key) 檔。 ‧SSL 要建立 SSL 連線,必需在編譯時加上 TLS Support 的選項。 TLS 是在原本的連接埠 (usually, 25) 上面使用 STARTTLS 來建立 SSL 連線。 ‧SASL2 要使用 SASL2,要先安裝 cyrus-sasl2 與 cyrus-sasl2-saslauthd,再編譯 Sendmail。 SASL 讓使用者經過伺服器認證後,能使用本伺服器寄發信件。 ‧Outlook Express 客戶端設定: 開啟 Outlook Express,點選[工具]→[帳戶]→雙點您的 Email 帳戶 SASL)→伺服器→勾選 "我的伺服器需要驗證"。 TLS)→進階→勾選在 外寄郵件-SMTP 下方的 "這個伺服器需要安全連線-SSL"。 ‧使用 Ports 安裝 Sendmail + SASL2 + TLS: # 使用 CVSup 更新 Ports。 cd /usr/ports/mail/sendmail # 安裝 Sendmail Support SASL2+TLS make -DSENDMAIL_WITH_TLS -DSENDMAIL_WITH_SASL2 install ‧使用 Port 安裝 Sendmail + SASL2 + TLS 請注意: 使用 ports 安裝並不會動到系統內建的 Sendmail。 在 /etc/rc.conf 設定 sendmail_enable="NONE" 以關閉系統內建的 Sendmail。 用 /usr/local/etc/rc.d/sendmail.sh start 啟動。(開機時會自動執行此檔) 想讓系統內建的 Sendmail Support SASL2+TLS 請參考非 Port 安裝部份。 請跳過此行之後的安裝步驟,跳至接在之後的 sendmail.cf 設定。 --------------< 非 Ports 安裝 Sendmail + SASL2 + TLS >--------------------- ‧使用 Ports 安裝 cyrus-sasl2 與 cyrus-sasl2-saslauthd: # 使用 CVSup 更新 Ports。 cd /usr/ports make update # 安裝 cyrus-sasl2 cd /usr/ports/security/cyrus-sasl2 make install clean # 安裝 cyrus-sasl2-saslauthd cd /usr/ports/security/cyrus-sasl2-saslauthd make install clean ‧編譯 Sendmail 請在 /etc/make.conf 中加入一些 Sendmail 編譯選項: SENDMAIL_CFLAGS=-I/usr/local/include -DSASL=2 -DSTARTTLS SENDMAIL_LDFLAGS=-L/usr/local/lib SENDMAIL_LDADD=-lsasl2 -lssl -lcrypto 您可以另外安裝 Sendmail 來替換系統內建的, 或者在 /usr/src/usr.sbin/sendmail 重編譯系統內建的 Sendmail。 或者 make update 後順道 make world 一下。 重新編譯系統內建的 Sendmail 請用: cd /usr/src/usr.sbin/sendmail ; make clea ; make all install -------------------------< Sendmail.cf 檔設定 >---------------------------- ‧設定 sendmail.cf 請在 /etc/mail 或 /usr/local/etc/mail 設定 {hostname}.mc 請加入以下設定: dnl The following lines are used to enable the STARTTLS function define(`confCACERT_PATH', `/usr/local/CA') define(`confCACERT', `/usr/local/CA/RootCA.crt') define(`confSERVER_CERT', `/etc/mail/CA/HostCA.crt') define(`confSERVER_KEY', `/etc/mail/CA/HostCA.key') define(`confCLIENT_CERT', `/etc/mail/CA/HostCA.crt') define(`confCLIENT_KEY', `/etc/mail/CA/HostCA.key') define(`confDONT_BLAME_SENDMAIL', `GroupReadableKeyFile') dnl The following lines are used to enable CYRUS-SASL function TRUST_AUTH_MECH(`LOGIN PLAIN')dnl define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl 製作並安裝 sendmail.cf make install ‧憑證設定: 將根憑證 RootCA.crt 放在 /usr/local/CA/ 將伺服器憑證: HostCA.crt 放在 /etc/mail/CA/ 將伺服器憑證 Private Key: HostCA.key 放在 /etc/mail/CA 設定 Private Key 權限: chgrp smmsp /etc/mail/HostCA.key chmod o-rwx /etc/mail/HostCA.key ‧憑證設定注意: 您可以自行決定檔名及目錄,但請連同更改 {hostname}.mc 的 CA 位置。 記得重做 sendmail.cf (cd /mail/etc/ ; make install)。