Server ≫ Linux Server ≫ Fedora Core 4 ≫ SSLによる暗号化通信

 
 
注意
 
ここでの内容は、コンソールモード時の文字化け対策 で紹介した bterm を起動した状態での内容です。bterm を起動しない状態でも内容は同じですが一部日本語表記が文字化けする場合があります。
SSL
これまでのApacheの設定だけではデータはインターネット上にそのまま平分として流れていきます。ログイン画面等でパスワード等を入力する際この平分のままではインターネット上に悪意のあるユーザーがいた場合、そのパスワード等を盗み見て悪用してしまう可能性があります。

そこで、暗号化通信を行うSSL(Sekure Sockets Layer)ソフト『mod_ssl』をインストールします。

mod_ssl のインストール
下記のように yum install mod_ssl と入力して Enter キーを押します。
 [root@linux]# yum install mod_ssl       ← yum inatall mod_ssl を入力
 Setting up install Process
 Setting up repositories
 updates-released                           100% |============================| 951 B 00:00
      
  ↓↓
    ↓↓ 途中省略
    ↓↓

 Total download size: 205 k
 Is this ok [y/n]: y      
← y を入力
        
↓↓
    ↓↓ 途中省略
    ↓↓

 Installed: mod_ssl.i386 1:2.0.54-10.4
 Dependency Installed: distcache.i386 0:1.4.5-7
 Complete!      
← Complete! と表示されれば完了
 [root@linux]#
ポートの開放
Webサーバー用のポート 443 を開放します。

下記のように入力します。

 [root@linux]# vi /etc/sysconfig/iptables      ← vi /etc/sysconfig/iptables を入力(設定ファイル iptables を開く)
設定ファイル iptables が開きますので最終行に -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT を追記してポート番号 443 を開きます。
 # Firewall configuration written by system-config-securitylevel
 # Manual customization of this file is recommended.
 *filter
 :IMPUT ACCEPT [0:0]
         ↓↓
    ↓↓ 途中省略
    ↓↓

 -A INPUT -j RH-Firewall-1-INPUT
         ↓↓
    ↓↓ 途中省略
    ↓↓

 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
      ← 最終行に追記
 
  設定を反映させるため iptables を再起動させます。
   
 
 [root@papa-net ~]# /etc/rc.d/init.d/iptables restart
     ← /etc/rc.d/init.d/iptables iptables を入力
 ファイアウォールルールを適用中:                                  [ OK ]
 チェインポリシーを ACCEPT に設定中filter                         [ OK ]
 iptables モジュールを取り外し中                                  [ OK ]
 iptables ファイアウォールルールを適用中:                         [ OK ]
 iptables モジュールを読み込み中ip_conntrack_netbios_ns           [ OK ]
 
認証キーの作成

最初に認証キー用ディレクトリの作成です。

 [root@linux]# mkdir /etc/httpd/conf/ssl.key/      ← ssl.key ディレクトリの作成
認証キーの作成。
 [root@linux]# cd /etc/httpd/conf/ssl.key/     ← ssl.key ディレクトリに移動
 [root@linux ssl.key]# openssl genrsa -des. 1024 > server.key
     ← 入力
 Generating RSA private key, 1024 bit long modulus
 ......******
 ....******
 e is 65537 (0x10001)
 Enter pass phrase: ******    
 ← パスワード入力(* は実際には表示されません)
 Verifying - Enter pass phrase: ******    
 ← 再度パスワード入力(* は実際には表示されません)
 [root@linux ssl.key]#
このままではWebサーバー起動時にパスワードを求められるのでWebサーバー起動時にパスワードを要求されないようにするためサーバー用認証キーからパスワードを削除します。
 [root@linux ssl.key]# openssl rsa -in server.key -out server.key     ← 入力
 Enter pass phrase for server.key: ******    
 ← パスワード入力(* は実際には表示されません)
 writing RSA key
 [root@linux ssl.key]#
自己認証書の作成。
 [root@linux ssl.key]# openssl req -new -key server.key -out server.csr       ← 入力
 You are about to be askde to enter information that will be incorporated
 into your certificate request.
 What you are about to enter is what is called a Distinguiahed 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     
← 国名入力(jp = 日本)
 State or Province Name (full name) [Berkshire]: tokyo      
← 都道府県名入力(tokyo = 東京都)
 Locality Name (eg, city) [Newbury]: chiyoda     
← 市区町村名入力(chiyoda = 千代田区)
 Organization Name (eg, company) [My Company Ltd]: linux-server   
 ← 会社名入力(linux-server = 個人運営の場合はサーバー名)
 Organizational Unit Name (eg, section) []:      
← 部署名入力(個人運営の場合は空白 そのまま Enter を押す)
 Common Name (eg, your name or your server's hostname) []: ******.com      
← ホスト(ドメイン)名入力(******.com = ドメイン名)
 Email address []: zzzz@******.com     
← サーバー管理者のメールアドレス入力

 Please enter the following 'extra' attributes
 to be sent with your certificate request
 A challenge password []:     
← パスワード入力(ここではパスワードを入力しないで、そのまま Enter を押す)
 An optional company name []:      
← 会社名入力(個人運営の場合は空白 そのまま Enter を押す)
 [root@linux ssl.key]#
サーバー用証明書の作成。下記のように OK メッセージと上で入力した内容が表示されれば完了
 [root@linux ssl.key]# openssl x509 -in server.csr -out server.crt -reg -signkey server.key       ← 入力
 Signature ok
 subject=/c=jp/ST=tokyo/L=chiyoda/O=linux-server/CN=******.com/emailAddress=zzzz@******.com
 Getting Private key
rootのみが SSL の内容を参照できるようにパーミッションを変更します。
 [root@linux ssl.key]# chmod 400 /etc/httpd/conf/ssl.key/server.key       ← 入力
以上で終了です。
SSL の設定
設定ファイルの編集をします。
 [root@linux]# vi /etc/httpd/conf.d/ssl.conf       ← 入力
下記のようなファイルが開きますので緑色の部分を青色に変更(書き換え・削除)して下さい。赤文字は説明です。
 #
 # This is the Apache server configuration file providing SSL support.
 # It contains the configuration directives to instruct the server how to
 # serve pages over an https connection. For detailing information about these
 # directives see <URL:http://httpd.apache.org/docs-2.0/mod/mod_ssl.html>
 #
       
 ↓↓
    ↓↓ 途中省略
    ↓↓

 <VirtualHost _default_:443>

 # General setup for the virtual host, inherited from global configuration
 #DocumentRoot "/var/www/html"
     
↓ ドキュメントルート(ホームぺージファイルの格納フォルダ)の指定
 DocumentRoot "/home/user/www"       ← 自分の環境に合わせて変更して下さい
 #ServerName www.example.com:443
       
 ↓↓
    ↓↓ 途中省略
    ↓↓

 # Server Certificate:
 # Point SSLCertificateFile at a PEM encoded certificate. If
 # the certificate is encrypted, then you will be prompted for a
 # pass phrase. Note that a kill -HUP will prompt again. A new
 # certificate can be generated using the genkey(1) command.
 SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    
 ↓ 認証キーファイルの指定
 SSLCertificateFile /etc/httpd/conf/ssl.key/server.crt

 # Server Private Key:
 # If the key is not combined with the certificate, use this
 # directive to point at the key file. Keep in mind that if
 # you've both a RSA and a DSA private key you can configure
 # both in parallel (to also allow the use of DSA ciphers, etc.)
 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
   
  ↓ 認証キーファイルの指定
 SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
        
↓↓
    ↓↓ 途中省略
    ↓↓

 # Per-Server Logging:
 # The home of a custom SSL log file. Use this when you want a
 # compact non-error SSL logfile on a virtual host basis.
 CustomLog logs/ssl_request_log \
 "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

 </VirtualHost>
以上の書き換え(変更)をしたら保存します。
apacheの再起動
最後に apache を下記のように再起動して完了です。
 
 [root@linux]# /etc/rc.d/init.d/httpd restart      ← /etc/rc.d/init.d/httpd restart を入力(apache の再起動)
 httpd を停止中:        [ OK ]
 httpd を起動中:        [ OK ]
閲覧者への周知
これでホームページの暗号化通信ができるようになりましたが正規の認証局から認証され た訳ではないのでSSL通信をする場合はホームページ閲覧者に対してその旨を説明し下記のような作業をしていただくようにお願いしなければなりません。

以下はホームページ閲覧者に実際に行ってもらう作業です。

下図のようにホームページを表示させます。(下図では Fedora のテストページを表示させています)

そして、http の後に s を追加して https://localhost と入力して SSL を使った暗号化通信で自分のホームページを表示させます。

下図のような警告が表示されます。この警告は、Webサーバーが正規の認証局によって認証されていないことをユーザーに示すものです。 『証明書の表示(V)』をクリックします。

下図のようなダイアログが表示されます。『証明書のインストール』をクリックします。

下図のような“証明書のインポートウィザード”が表示されます。『次へ(N)』をクリックします。

『次へ(N)』をクリックします。

『完了』をクリックします。

続いて、下図のような“セキュリティ警告”が表示されます。『はい(Y)』をクリックします。

『OK』をクリックします。

『OK』をクリックします。

『はい(Y)』をクリックします。

SSL を使った暗号化通信でホームページを表示させました。画面右下に鍵マークが付いています。この鍵マークが暗号通信で表示されている証拠です。

この設定以後はセキュリティメッセージは出なくなります。

ホームページ閲覧者に対してよく説明して上記の設定をしてもらって下さい。

戻る