10.9. SSL による POP3/IMAP4 の暗号化

POP3/IMAP4 のサービスを提供するときに、SSL を利用してサーバーとクライアントとの通信経路を暗号化することが可能です。サーバー、クライアントともに SSL に対応している必要がありますが、現在では多くのメールクライアントが SSL による暗号化通信をサポートしています。

SSL により暗号化された POP3/IMAP4 サーバーを構築するには、openssl コマンドを実行して、/etc/mail/certs ディレクトリに ipop3sd.pem と imapsd.pem という名前の鍵ファイルを作成します。ipop3sd.pem は POP3 用の鍵ファイルであり、imapsd.pem は IMAP4 用の鍵ファイルとなります。imapsd.pem と ipop3sd.pem の内容は同一のものでも別のものでも構いません。

鍵を生成するために以下のコマンドを実行します。openssl コマンドは、幾つかの質問をしてきますので、入力してください。

# mkdir -p /etc/mail/certs
# cd /etc/mail/certs
# openssl req -new -x509 -nodes -out imapsd.pem -keyout imapsd.pem
Using configuration from /var/ssl/openssl.cnf
Generating a 1024 bit RSA private key
...................................................++++++
................++++++
writing new private key to 'imapsd.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]:Tokyo
Locality Name (eg, city) []:Shibuya
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Turbolinux
Organizational Unit Name (eg, section) []:Doc
Common Name (eg, YOUR name) []:Doc Administrator
Email Address []:doc@turbolinux.co.jp

作成後は、鍵ファイルが他のユーザーから参照されないようにファイルのパーミッションを変更します。

# chmod 600 ipop3sd.pem
# chmod 600 imapsd.pem

次に、サービスを開始します。これらのサービスは xinetd 経由で起動されます。SSL に対応した POP3 サービスを有効にするには、以下のコマンドを実行します。

# chkconfig pop3s on

SSL に対応した IMAP4 サービスを有効にするには、以下のコマンドを実行します。

# chkconfig imaps on

xinetd を再起動して、これらのサービスを有効にします。

# /etc/init.d/xinetd restart

実際にクライアントが POP3/IMAP4 サーバーにアクセスするには、/etc/hosts.allow でアクセスを許可するホストを指定する必要があります。Turbolinux 10 Server の xinetd は、TCP Wrappers によるアクセス制御を行う仕様になっており、/etc/hosts.allow でのアクセス制御のあとに、xinetd でのアクセス制御を行います。

例えば、以下のように記述をすれば、すべてのホストからのアクセス要求を受け入れるようになります。TCP Wrappers の詳細については、項19.1 を参照してください。

ipop3sd: ALL
imapsd: ALL