debian postfix + dovecot + sasl + TLS

postfix + dovecot + sasl で構築している前提。
http://d.hatena.ne.jp/kt_hiro/20120318/1332023507

・鍵と証明書の作成

# mkdir /etc/postfix/certs
# cd /etc/postfix/certs
# openssl genrsa -aes128 1024 > server.key
# openssl rsa -in server.key -out server.key # 鍵のパスフレーズの解除
# openssl req -new -x509 -key server.key -days 3650 -out server.crt
※CommonName はMUAがsmtpサーバとして指定するサーバ名を入力すること

・derファイルの作成
MUAによっては手動で証明書を読み込ませる必要があるため、証明書をderファイルでエクスポートする。

# openssl x509 -in server.crt -outform der -out server.der

postfix

・設定追加

# vi /etc/postfix/main.cf
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/postfix/certs/server.crt
smtpd_tls_key_file = /etc/postfix/certs/server.key
smtpd_tls_loglevel = 1
# vi /etc/postfix/master.cf
smtps     inet  n       -       -       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

smtps である点に注意

・再起動

# /etc/init.d/postfix restart

dovecot

・設定変更

# vi /etc/dovecot/dovecot.conf
protocols = imaps pos3s
ssl = yes
ssl_cert_file = /etc/postfix/certs/server.crt
ssl_key_file = /etc/postfix/certs/server.key

※server.key のパスフレーズを外しておかないと、MUAdovecot に接続した際に下記エラーが出る

dovecot: imap-login: Fatal: Can't load private key file ***/server.key: error:0906A068:PEM routines:PEM_do_header:bad password read

MUAの設定

送信(SMTP)のポート番号を465に変更
受信(POP3)のポート番号を995に変更
受信(IMAP)のポート番号を993に変更

動作確認

# telnet localhost 25
	Trying 127.0.0.1...
	Connected to localhost.
	Escape character is '^]'.
	220 mail.hirohiro.net ESMTP Postfix (@@DISTRO@@)
EHLO localhost
	250-mail.hirohiro.net
	250-PIPELINING
	250-SIZE 10485760
	250-VRFY
	250-ETRN
	250-STARTTLS		←追加される
	250-AUTH DIGEST-MD5 LOGIN CRAM-MD5 PLAIN
	250-ENHANCEDSTATUSCODES
	250-8BITMIME
	250 DSN