#contents
----
* FC4 における qpopper を用いた APOP 認証と pop3s の対応 [#p6162793]
** 準備 [#s2a82051]
まずはじめに qpopper のコンパイルとセットアップが必要になります。
[[FC4付属の sendmail で POP before SMTP(qpopper+DRAC)への対応:http://pocketstudio.jp/linux/?FC4%C9%D5%C2%B0%A4%CE%20sendmail%20%A4%C7%20POP%20before%20SMTP%28qpopper%2BDRAC%29%A4%D8%A4%CE%C2%D0%B1%FE]]のページを参考にして qpopper のセットアップを済ませてください。
- [[qpopper のインストール:http://pocketstudio.jp/linux/?FC4%C9%D5%C2%B0%A4%CE%20sendmail%20%A4%C7%20POP%20before%20SMTP%28qpopper%2BDRAC%29%A4%D8%A4%CE%C2%D0%B1%FE#y4a23d25]]
** APOP 認証への対応 [#h0079520]
実は qpopper のインストール時に APOP 認証に対応できるよう、configure 時にオプション指定を済ませています。
--enable-apop=/etc/mail/apop.auth
ですので、あとは【 /etc/mail/apop.auth 】ファイルにユーザ名とパスワードの登録を済ませるだけで済みます。ここで使うコマンドは /usr/local/sbin/popauth です。
/usr/local/sbin/popauth -user ユーザ名
ユーザ名は linux アカウント、つまり普通のメール受信ユーザ名です。パスワードはログインパスワードと別のものが設定できます。
以下は実行例です。
# /usr/local/sbin/popauth -user akane
Adding only APOP password for akane.
New password:
Retype new password:
これは akane というユーザに対して APOP 認証用のパスワードを設定しています。パスワード入力欄には文字が表示されませんが、確認のため2度パスワードを入力します。
あとはメールソフト側で認証方法を APOP に切り替えるだけで利用可能です。
/var/log/maillog には次のような認証時の記録が保存されます。
Jul 19 21:02:53 sion popper[14833]: apop "akane"
sion というホスト名で popper プロセス pid 14833 が apop でユーザ akane を認証したという意味です。
認証に失敗すると通常の認証時と同様にエラーが記録されます。
popper[15018]: akane at 192.168.11.102 (192.168.11.102): -ERR [AUTH] Password supplied for "akane" is incorrect.
ちなみに APOP 認証を行わせない(リストから削除する)時は
/usr/local/sbin/popauth -delete ユーザ名
こちらのコマンドを使います。
** pop3s への対応 [#p8e6c5d2]
以下手順を追って POP3S に対応します。POP3S に対応すると通信が SSL 化されますので、ネットワーク上ではメールを暗号化して安全に受信することができます。
まず xinetd 用のファイルを作成します。
# vi /etc/xinetd.d/pop3s
ファイルを開いたら、以下のようにサービスの記述を行います。
service pop3s
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/local/sbin/popper
server_args = -s -f /etc/mail/qpopper.config
}
次に vi で設定ファイルを作ります。
# vi /etc/mail/qpopper.config
中身は次のようにしてください。
set tls-support = alternate-port
set tls-server-cert-file =/etc/pki/qpopper.pem
次に、/etc/pki/qpopper.pem と指定した SSL 用の証明書を作成します。本来は認証機関(ベリサイン社やセコム・トラストネット社など)といった正規の CA 局からの認証が必要
次に、/etc/pki/qpopper.pem と指定した SSL 用の証明書を作成します。本来は認証機関(ベリサイン社やセコム・トラストネット社など)といった正規の CA 局からの認証が必要な訳ですが、[[qpopper の FAQ:http://www.eudora.com/products/unsupported/qpopper/faq.html#certs]]を参考にして自己認証させることにします。
まずはディレクトリ作成です。
# mkdir -p -m665 /etc/mail/certs
# chown root:mail /etc/mail/certs
# chmod 660 /etc/mail/certs
# cd /etc/mail/certs
次は公開鍵と秘密鍵の組み合わせを作成します。
# /usr/bin/openssl req -new -nodes -out req.pem -keyout /etc/mail/certs/cert.pem
Generating a 1024 bit RSA private key
.........................++++++
.................++++++
writing new private key to '/etc/mail/certs/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) [GB]:
まずここでは国コード、日本なので【 JP 】と入力してエンターを押します。
Country Name (2 letter code) [GB]:JP
State or Province Name (full name) [Berkshire]:
州名・都道府県名を記述します。私は富山県なので【 Toyama-ken 】としました。ここから先はみなさんの環境に合わせて適時書き換えてください。
State or Province Name (full name) [Berkshire]:Toyama-ken
Locality Name (eg, city) [Newbury]:
次は市区町村名です。私は滑川市という所に住んでいるので【 Namerikawa-shi 】とします。
Locality Name (eg, city) [Newbury]:Namerikawa-shi
Organization Name (eg, company) [My Company Ltd]:
その次は組織名です。【 Pocketstudio.jp 】と入力しました。
Organization Name (eg, company) [My Company Ltd]:Pocketstudio.jp
Organizational Unit Name (eg, section) []:
その次は部署名です。特にないので、そのままエンターを押します。
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
ここではサーバの正しい名前(FQDN)を入力しなくてはいけません。もしメールソフトでメールサーバ名を mail.example.jp としているなら、そのように入力します。私の場合はローカル IP アドレスのテストサーバなので【 192.168.11.253 】と入力しました。
あとはエンターで飛ばします。
Common Name (eg, your name or your server's hostname) []:192.168.11.253
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
次にコマンドを実行してパーミッションを変えます。
# chmod 600 /etc/mail/certs/cert.pem
# chown root:0 /etc/mail/certs/cert.pem
これで秘密鍵の作成を完了しました。
次からは自己認証の設定です。
# cd /etc/mail/certs
# /usr/bin/openssl genrsa -out ca.key 1024
Generating RSA private key, 1024 bit long modulus
................................................++++++
....++++++
e is 65537 (0x10001)
(本当は -des3 オプションをつけてパスフレーズをつけるべきですが、今回の証明書用ファイルは POP3S だけのためなので、特に指定しないことにします。)
引き続き、次のコマンドを入力します。
# /usr/bin/openssl req -new -x509 -days 365 -key ca.key -out ca.crt
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) [GB]:
先のように所在地情報を尋ねてきますので、一字一句間違えず、同じように正確に入力をします。
Country Name (2 letter code) [GB]:JP
State or Province Name (full name) [Berkshire]:Toyama-ken
Locality Name (eg, city) [Newbury]:Namerikawa-shi
Organization Name (eg, company) [My Company Ltd]:Pocketstudio.jp
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:192.168.11.253
Email Address []:
# /usr/bin/openssl x509 -req -CA ca.crt -CAkey ca.key -days 365 -in req.pem -out signed-req.pem -CAcreateserial
Signature ok
subject=/C=JP/ST=Toyama-ken/L=Namerikawa-shi/O=Pocketstudio.jp/CN=192.168.11.253
Getting CA Private Key
これで署名が終わりました。
最期に署名ファイルと鍵をまとめます(どうもこれをしないと正常に認識できないみたいです)。
# cat signed-req.pem >> cert.pem
あとは /etc/mail/qpopper.config ファイルを編集します。
set tls-options = 0x00000800
set tls-support = alternate-port
set tls-server-cert-file =/etc/mail/certs/cert.pem
最期に xinetd を再起動して pop3s サービスを有効にします。
# /sbin/service xinetd restart
xinetd を停止中: [ OK ]
xinetd を起動中: [ OK ]
メールソフト側でメールを POP3S に対応して受信できるようになります。
正しく認証できると、以下のように SSL に対応した旨の記録が残ります。
popper[xxxxx]: (v4.0.8) TLSv1/SSLv3 handshake with client at 192.168.11.102;
new session-id; cipher: RC4-MD5 (RC4-MD5 SSLv3 Kx=RSA Au=RSA Enc=RC4(128) Mac=MD5 ), 128 bits
もちろん、この状態でも APOP 認証は有効ですから POP before SMTP 設定も使えますし、[[SMTP 認証 と SMTPS へも対応:http://pocketstudio.jp/linux/?FC4%2Fsendmail%2FFC4%C9%D5%C2%B0%A4%CEsendmail%A4%C7SMTPS%A4%C8SMTP%20AUTH%28SMTP%C7%A7%BE%DA%29%A4%CB%C2%D0%B1%FE%A4%B5%A4%BB%A4%EB%CA%FD%CB%A1]]できるようになれば、メール送受信ともセキュリティ的に暗号化された安全な通信ができることになります(といっても、メールは外部のサーバに送信された時点で暗号化されていない訳でして、メールの本文も PGP などを使って暗号化したり、手軽な方法では PDF や WORD ファイルに鍵をかけるのが安全な方法でしょう)。