Postfixで暗号通信しよう

概要

手順

...FreeBSDのPortsに感謝して、TLS版のPostfixをportsよりinstallする。
他のOSについては Postfix/TLS - Installing the patchkitを見た感じだとpatchを当てて makeすれば同じようにいけるとおもいます。

  1. 自己証明を作る
    1. 自己証明書を置くディレクトリを作成。
      /usr/local/etc/postfix/certsを作成する
      
      # mkdir /usr/local/etc/postfix/certs
      
      
    2. /usr/local/etc/postfix/certsに移動し、証明書を作成
      
      # cd /usr/local/etc/postfix/certs
      # openssl req -new -x509 -nodes -out cert.pem
      
      

      このときに色々と質問されますが、適宜答えると/usr/local/etc/postfix/certsに privkey.pemとcert.pemが作成されます。

      回答例

      おふざけで書いているのでこのまま書かないようにしてください(^^;

      % openssl req -new -x509 -nodes -out cert.pem
      Using configuration from /etc/ssl/openssl.cnf
      Generating a 1024 bit RSA private key
      ..........................++++++
      ..........++++++
      writing new private key to 'privkey.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]:Nagano	(県名)
      Locality Name (eg, city) []:New Tokyo City No.3		(市町村名)
      Organization Name (eg, company) [Internet Widgits Pty Ltd]:NERV JAPAN	(組織名)
      Organizational Unit Name (eg, section) []:Evangelion Dept.	(部署)
      Common Name (eg, YOUR name) []:Magi.NERV.JP	(SMTP Serverのホスト名)
      Email Address []:postmaster@NERV.JP		(管理者のメールアドレス)
      % 
      
    3. 証明書を一般ユーザーから保護
      
      # chmod -R go-rwx /usr/local/etc/postfix/certs
      
      
  2. main.cfに証明書の在処を書く
    1. CERT File,Private Key Fileをmain.cfに書く
      main.cfを開き、下記のような行を追加する。
      
      smtpd_tls_cert_file = /usr/local/etc/postfix/certs/cert.pem
      smtpd_tls_key_file = /usr/local/etc/postfix/certs/privkey.pem
      
      
    2. E-mailの受信でTLSを使うようにする。
      main.cfを開き、下記のような行を追加する。
      
      smtpd_use_tls = yes
      
      
    3. 暗号化の鍵の作成に使う乱数を取得するデバイスを設定
      main.cfを開き、下記のような行を追加する。
      
      tls_random_source = dev:/dev/urandom
      tls_daemon_random_source = dev:/dev/urandom
      
      
  3. 他のホストにSMTPするときにTLSを試すよう設定
    1. E-mailの送信で可能ならTLSを使うようにする。
      main.cfを開き、下記のような行を追加する。
      
      smtp_use_tls = yes
      
      

      さっきはsmtp*d*で、今回はsmtpなので注意してください。

    2. 仲間を探したいのでTLSを使っているMTAに送った時はログに残してもらう
      main.cfを開き、下記のような行を追加する。
      
      smtp_tls_note_starttls = yes
      
      
以上。

参考文献


© 2001 Yoshisato YANAGISAWA PCC-Software.org. All rights reserved.