SSL をメールサーバに導入すると,クライアントとサーバ間の通信の やり取りが暗号化できる.以下はその導入のためのドキュメントである.
この作業は再構築後にusuzumi からgrey に変更されるために, もう一度証明書を作り直す.また,qmail の起動スクリプト にはusuzumi と書かれているため,それもgrey に修正する.
openssl をソースからインストールする
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
展開して移動, コンパイル.
$ tar zxvf openssl-1.0.1c.tar.gz $ cd openssl-1.0.1c $ ./config --prefix=/usr --openssldir=/usr/local/openssl shared $ make $ sudo make install_sw (_sw を付けないとman の設定でエラーが出てしまう)
ucspi-tcp のソースを取得する
$ wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz $ tar zxvf ucspi-tcp-0.88.tar.gz
ssl 化パッチと他のパッチを持ってくる
$ wget http://qmail.org/moni.csi.hu/pub/glibc-2.3.1/ucspi-tcp-0.88.a_record.patch $ wget http://qmail.org/moni.csi.hu/pub/glibc-2.3.1/ucspi-tcp-0.88.nobase.patch $ wget http://www.nrg4u.com/qmail/ucspi-tcp-ssl-20050405.patch.gz $ gzip -d ucspi-tcp-ssl-20050405.patch.gz
パッチを充て, make.
$ cd ucspi-tcp-0.88 $ patch -p0 < ../ucspi-tcp-ssl-20050405.patch $ patch -p1 < ../ucspi-tcp-0.88.a_record.patch $ patch -p1 < ../ucspi-tcp-0.88.nobase.patch $ make $ sudo cp tcpserver /usr/local/bin/tcpserver-ssl
smtp over ssl を用いるため, qmail にsmtp-auth のパッチをあてる. 以前qmail のソースを展開したディレクトリに移動し, パッチをあてる.
# tar zxvf netqmail-1.06.tar.gz # cp -r netqmail-1.06 netqmail-1.06_smtps # cd netqmail-1.06_smtps # patch -p1 < ../qmail-103.patch # patch -p1 < ../qmail-date-localtime.patch # patch -p1 < ../qmail-smtpd-relay-reject # cp -r ../qmail-smtpd-auth-0.31/* ./ # make # cp qmail-smtpd /var/qmail/bin/qmail-smtpd-auth
証明書を発行する. 途中入力箇所があるので注意.
# make cert
openssl req -new -x509 -nodes \ -out cert.pem -days 366 \ -keyout cert.pem Generating a 1024 bit RSA private key .....++++++ .................++++++ writing new private key to 'cert.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]:JP State or Province Name (full name) [Some-State]:Hokkaido Locality Name (eg, city) []:Sapporo Organization Name (eg, company) [Internet Widgits Pty Ltd]:Department of Science Organizational Unit Name (eg, section) []:Earth and Planetary Science Common Name (e.g. server FQDN or YOUR name) []:usuzumi.ep.sci.hokudai.ac.jp Email Address []:mondo4@usuzumi.ep.sci.hokudai.ac.jp |
作成した秘密鍵を設置し、適切にパーミッションを設定
# mkdir /var/qmail/server.key # cp cert.pem /var/qmail/server.key/ # chmod 700 /var/qmail/server.key/; chmod 600 /var/qmail/server.key/cert.pem # rm cert.pem
起動スクリプトのコメントアウトを外す.
# emacs /etc/init.d/qmail
start) . . . # For SMTP over SSL sh -c " /sbin/start-stop-daemon --start --quiet --user qmaild \ --pidfile /var/run/tcpserver_ssmtp.pid --make-pidfile \ --exec /usr/local/bin/tcpserver-ssl -- -s -HRv -u \ ` id -u qmaild ` -g ` id -g qmaild ` -x /etc/tcp.smtp.cdb \ -n /var/qmail/server.key/cert.pem 0 ssmtp \ /usr/local/bin/rblsmtpd -r bl.spamcop.net \ /var/qmail/bin/qmail-smtpd-auth usuzumi.ep.sci.hokudai.ac.jp \ /bin/checklocalpwd /bin/true 2>&1 \ | /var/qmail/bin/splogger smtpd 3 > /dev/null 2>&1 &" # For POP3 over SSL sh -c "/sbin/start-stop-daemon --start --quiet --user root \ --pidfile /var/run/tcpserver_pop3s.pid --make-pidfile \ --exec /usr/local/bin/tcpserver-ssl -- -s \ -n /var/qmail/server.key/cert.pem \ -v -u 0 -g 0 0 pop3s \ /var/qmail/bin/qmail-popup \ usuzumi.ep.sci.hokudai.ac.jp /bin/checkapoppw \ /var/qmail/bin/qmail-pop3d Maildir 2>&1 \ | /var/qmail/bin/splogger pop3d 3 > /dev/null 2>&1 &" stop) . . . /sbin/start-stop-daemon --user qmaild --stop --quiet --oknodo --pidfile /var/run/tcpserver_ssmtp.pid --exec /usr/local/bin/tcpserver-ssl # smtp over SSL start-stop-daemon --user root --stop --quiet --oknodo --pidfile /var/run/tcpserver_pop3s.pid --exec /usr/local/bin/tcpserver-ssl |
認証のために checklocalpwd を用いる. checklocalpwd のソースを落として展開する.
$ $ wget http://www.ep.sci.hokudai.ac.jp/~epmail/y2015/dvlop/script/checklocalpwd-1.0.tar.gz $ tar zxvf checklocalpwd-1.0.tar.gz $ cd checklocalpwd-1.0
パスワードファイルの名前を変更する.
$ emacs checklocalpwd.c
#define CONFIG_FILE "/etc/poppasswd" → #define CONFIG_FILE "/etc/smtppasswd" |
make する.
# make install
権限を変更する.
# chown root:nofiles /bin/checklocalpwd # chmod 4710 /bin/checklocalpwd # chmod 750 /bin/poppasswd_change # chmod 750 /bin/poppasswd_basic
パスワード自動生成スクリプトを取得する.
# wget http://www.ep.sci.hokudai.ac.jp/~epmail/y2015/dvlop/script/smtppwdbg
取得したパスワード生成スクリプトを /etc/cron.daily 以下に置く.
# chmod +x smtppwdbg # cp smtppwdbg /etc/cron.daily
crontab にsmtppwdbg を追加する.
# crontab -e
以下の一行を追加する.
50 * * * * /etc/cron.daily/smtppwdbg |
smtp-auth 用にパスワードファイルを作成する.
# poppasswd_basic > /etc/smtppasswd
パーミッション変更
# chmod 600 /etc/smtppasswd
パスワードの作成(ここではユーザ hogehoge のパスワードを password とした場合の例を載せる)
# poppasswd_change /etc/smtppasswd hogehoge password
qmail の再起動と挙動の確認
# /etc/init.d/qmail restart
# netstat -an | grep 995 tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN # netstat -an | grep 110 tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN # netstat -an | grep 25 tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN # netstat -an | grep 465 tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN |
Thunderbird で「ツール」→「アカウント設定」→「アカウント操作」→「メールアカウントを追加」
名前: ssl メールアドレス: mondo4@usuzumi.ep.sci.hokudai.ac.jp |
「続ける」→「手動設定」
受信サーバ: POP ポート番号: 995 SSL: SSL/TLS 認証方式: 暗号化されたパスワード認証 送信サーバ: SMTP ポート番号: 465 SSL: SSL/TLS 認証方式: 通常のパスワード認証 |
自分宛にメールを出してみる. メールを送信する際にパスワードを聞かれるので入力する.
自己証明書を発行する
# cd /etc/ssl # /usr/lib/ssl/misc/CA.sh -newca
CA certificate filename (or enter to create) ←[そのままEnter] Making CA certificate ... Generating a 1024 bit RSA private key .......++++++ ..............++++++ writing new private key to './demoCA/private/./cakey.pem' Enter PEM pass phrase:←[仮passを入力] Verifying - Enter PEM pass phrase:←[仮passを再度入力] .... Country Name (2 letter code) [AU]:←[JPと入力] State or Province Name (full name) [Some-State]: ←[Hokkaidoと入力] Locality Name (eg, city) []:←[Sapporoと入力] Organization Name (eg, company) [Internet Widgits Pty Ltd]: :←[Department of Scienceと入力] Organizational Unit Name (eg, section) []:←[Earth and Planetary Science と入力]: Common Name (eg, YOUR name) []:←[usuzumi.ep.sci.hokudai.ac.jp と入力] Email Address []:←[mondo4@usuzumi.ep.sci.hokudai.ac.jp と入力] Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:←[空白のままEnter] An optional company name []:←[空白のままEnter] Using configuration from /usr/lib/ssl/openssl.cnf Enter pass phrase for ./demoCA/private/./cakey.pem:←[先程入力した仮pass を入力] Check that the request matches the signature Signature ok Certificate Details: Serial Number: 0 (0x0) Validity Not Before: Oct 19 16:28:59 2008 GMT Not After : Oct 19 16:28:59 2011 GMT Subject: countryName = JA stateOrProvinceName = Hokkaido organizationName = Department of Science organizationalUnitName = Earth and Planetaly science commonName = usuzumi.ep.sci.hokudai.ac.jp emailAddress = mondo04@usuzumi.ep.sci.hokudai.ac.jp .... Certificate is to be certified until Oct 19 16:28:59 2011 GMT (1095 days) |
パスフレーズを消去する
# cd ./demoCA # openssl rsa -in ./private/cakey.pem -out ./private/cakey.pem
/etc/dovecot/conf.d/ 以下のファイル を編集
# cd /etc/dovecot/conf.d/
# emacs 10-master.conf
port = 993 ssl = yes |
# emacs 10-ssl.conf
ssl = yes ssl_cert = </etc/ssl/demoCA/cacert.pem ssl_key = </etc/ssl/demoCA/private/cakey.pem |
dovecot を再起動する.
# service dovecot restart
imaps の動作確認
# netstat -an | grep 993 tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN # netstat -an | grep 143 tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN |
Thunderbird で「ツール」→「アカウント設定」→「アカウント操作」→「メールアカウントを追加」 この際, dovecotpwdbg がcronで動いていると/etc/dovecot.cram-md5 の中身が書き換わってしまうので,MD5 認証データベースファイルの作成を 参考にMD5形式のパスワードを作成しなおす.
名前: ssl メールアドレス: mondo4@usuzumi.ep.sci.hokudai.ac.jp |
「続ける」→「手動設定」
受信サーバ: IMAP ポート番号: 993 SSL: SSL/TLS 認証方式: 暗号化されたパスワード認証 |
「完了」, 自分宛にメールを出してみる.
最終更新日:2015/12/17 (三上 峻) | Copyright © 2000-2015 epcore |