SSLによるメールサーバの通信の暗号化

外部からメールの通信を暗号化するためにSSLを利用します。
ここでは、WebサーバへSSLを導入していることを前提にし、その秘密鍵と証明書を利用します。
WebサーバへのSSLの導入はこちらを参考にして下さい。

「Postfix」の設定

Webサーバの秘密鍵と証明書をPostfixに流用します。

「CentOS4.1」の場合
[root@CentOS ~]# ln -s /usr/share/ssl/certs/server.pem /etc/postfix/server.pem <= Webサーバの証明書をリンク
[root@CentOS ~]# ln -s /usr/share/ssl/certs/server.key /etc/postfix/server.key <= Webサーバの秘密鍵をリンク

「CentOS5.0」の場合
[root@CentOS ~]# ln -s /etc/pki/tls/certs/server.pem /etc/postfix/server.pem <= Webサーバの証明書をリンク
[root@CentOS ~]# ln -s /etc/pki/tls/certs/server.key /etc/postfix/server.key <= Webサーバの秘密鍵をリンク

「Postfix」の設定ファイルを編集します。

[root@CentOS ~]# vi /etc/postfix/main.cf <= 設定ファイルの編集
最終行に以下を追加
smtpd_tls_cert_file = /etc/postfix/server.pem
smtpd_tls_key_file = /etc/postfix/server.key
smtpd_use_tls = yes
smtpd_tls_session_cache_database = sdbm:/etc/postfix/smtpd_scache

次にmasterの設定ファイルを編集します。

[root@CentOS ~]# vi /etc/postfix/master.cf <= 設定ファイルの編集
「CentOS4.1」の場合
#smtps     inet  n       -       n       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes
↓
smtps     inet  n       -       n       -       -       smtpd <= コメント解除
  -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes <= コメント解除

#tlsmgr    fifo  -       -       n       300     1       tlsmgr
↓
tlsmgr    fifo  -       -       n       300     1       tlsmgr <= コメント解除

「CentOS5.0」の場合
#smtps     inet  n       -       n       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
↓
smtps     inet  n       -       n       -       -       smtpd <= コメント解除
  -o smtpd_tls_wrappermode=yes <= コメント解除
  -o smtpd_sasl_auth_enable=yes <= コメント解除

tlsmgr    unix  -       -       n       1000?   1       tlsmgr <= 確認

「Postfix」を再起動し、設定を反映させます。

[root@CentOS postfix]# /etc/rc.d/init.d/postfix restart

SMTPでSSLを利用する際、ポートの465番を利用しますので、ルータで開けます。

「Dovecot」の設定

「Postfix」用の秘密鍵と証明書を「Dovecot」に流用します。
なお、設定前の内容が「CentOS」のバージョンによって多少違いますが、変更後の内容になるように設定します。

[root@CentOS ~]# vi /etc/dovecot.conf <= 設定ファイルの編集
protocols = imap imaps pop3 pop3s
↓
protocols = imaps pop3s <= SSL認証のみ許可する

#ssl_disable = no
↓
ssl_disable = no <= コメント解除

ssl_cert_file = /usr/share/ssl/certs/dovecot.pem
↓
ssl_cert_file = /etc/postfix/server.pem <= 「Postfix」の証明書を指定

ssl_key_file = /usr/share/ssl/private/dovecot.pem
↓
ssl_key_file = /etc/postfix/server.key <= 「Postfix」の秘密鍵を指定

「Dovecot」を再起動し、設定を反映させます。

[root@CentOS ~]# /etc/rc.d/init.d/dovecot restart

ポート番号は
POPの場合、995番
IMAPの場合、993番
を利用しますので、ルータで開けます。

▲ページのトップへ