Dovecot にTLS/SSL(pop3s)を導入する

Dovecot にMUAからメールを取りに行く際の通信をセキュア化(暗号化)するために、Dovecot にTLS/SSLを導入します。
Dovecot には証明書の作成ツールが付属していますので、実に簡単に導入することができます。
その手順を整理しておきます。

1.dovecot-openssl.cnf の編集
[root ~]# vim /etc/pki/dovecot/dovecot-openssl.cnf
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
# country (2 letter code)
C=JP                                              | 変更

# State or Province Name (full name)
ST=xxxxxxxx                                       | 変更

# Locality Name (eg. city)
L=xxxxxxxx                                        | 変更

# Organization (eg. company)
O=goofoo                                          | 変更

# Organizational Unit Name (eg. section)
OU=Dovecot                                        | 変更

# Common Name (*.example.com is also possible)
CN=xxx.goofoo.jp                                  | 変更(正式なホスト名を設定する)

# E-mail contact
emailAddress=xxxxxx@xxx.goofoo.jp                 | 変更(管理者のメールアドレスを設定する)

[ cert_type ]
nsCertType = server
2.証明書の作成

ここでは、Dovecotのインストール時点で作成されている証明書を削除して、その後で、Dovecotに付属している証明書作成シェルスクリプト mkcert.sh を実行します。
mkcert.sh で作成される証明書のフルパスは次の通りです。

  • 証明書ファイル・・・/etc/pki/dovecot/certs/dovecot.pem
  • 秘密鍵ファイル・・・/etc/pki/dovecot/private/dovecot.pem

証明書の作成手順は次の通りです。

[root ~]# rm -f /etc/pki/dovecot/certs/dovecot.pem
[root ~]# rm -f /etc/pki/dovecot/private/dovecot.pem
[root ~]# /usr/share/doc/dovecot-1.0.7/examples/mkcert.sh
Generating a 1024 bit RSA private key
........................++++++
......................................................................++++++
writing new private key to '/etc/pki/dovecot/private/dovecot.pem'
-----

subject= /C=JP/ST=xxxxxxxx/L=xxxxxxxx/O=goofoo/OU=Dovecot/CN=xxx.goofoo.jp/emailAddress=xxxxxx@xxx.goofoo.jp
SHA1 Fingerprint=85:F7:CF:E0:E5:AC:23:9D:E2:F0:B2:F9:70:38:05:A4:4C:8E:35:F9

これで、公開鍵ファイルと秘密鍵ファイルが作成されます。

3.dovecot.conf の編集
[root ~]# vim /etc/dovecot.conf
パラメータ 編集の説明
protocols = pop3 pop3s pop3sを追記
ssl_disable = no コメントアウトを外す
ssl_cert_file = /etc/pki/dovecot/certs/dovecot.pem コメントアウトを外す
ssl_key_file = /etc/pki/dovecot/private/dovecot.pem コメントアウトを外す
4.dovecot の再起動
[root ~]# service dovecot restart
Dovecot Imap を停止中:                                     [  OK  ]
Dovecot Imap を起動中:                                     [  OK  ]
5.ファイアウォールの設定変更

pop3s接続には、TCPの995番ポートを使用しますので、iptablesの設定を変更して、再起動します。

[root ~]# vim /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -d 183.181.30.79 --dport 995 -j ACCEPT
[root ~]# service iptables restart
ファイアウォールルールを適用中:                            [  OK  ]
チェインポリシーを ACCEPT に設定中mangle filter nat        [  OK  ]
iptables モジュールを取り外し中                            [  OK  ]
iptables ファイアウォールルールを適用中:                   [  OK  ]

これで、Dovecot がpop3s接続を受け付けている状態になります。

Comments are closed.