SSLの設定方法


osCommerceをインストールしてしまった結果、SSL機能がないとセキュリティ面で問題が発生するこで

SSLを導入することにしました。

ここでは、プピュラーなopensslとHTTPD-2.2.17の設定について説明します。

OpenSSL0をopenssl-1.0.0a.tar.gzよりダウンロードします。

最新更新日:2010年11月16日


◆セキュアWebの設定は以下の順序で行ないます。
  1. 前準備

  2. open_sslのインストール

  3. apacheの再インストール

  4. クライアント証明書リクエストの発行

  5. 証明書発行に必要な CSR の作成

  6. 電子証明書の作成

  7. httpd.confの編集

  8. SSLの起動と停止編集

  9. SSLの動作確認




◆前準備
セキュアWeb環境を構築するには「perl」と「gcc」が必要です。。

  1. perlの確認は以下のコマンドで確認してください。

    # perl -v ←でperlがインストールされていることを確認。

  2. gccの確認は以下のコマンドで確認してください。

    # gcc -v ←でgccがインストールされていることを確認。

トップへ戻る

◆open_sslのインストール
#/usr/local/src
/usr/local/src# tar zxvf openssl-1.0.0a.tar.gz ← openssl-1.0.0a.tar.gzを解凍をする
/usr/local/src #cd openssl-1.0.0a
/usr/local/src/openssl-1.0.0a# ./config
/usr/local/src/openssl-1.0.0a# make
/usr/local/src/openssl-1.0.0a# make test
/usr/local/src/openssl-1.0.0a# su
/usr/local/src/openssl-1.0.0a# make install

トップへ戻る

◆apacheの再インストール
この作業は必ずしも必要でないかも知れません。
HTTPD-2.*.**をインストールした場合は/***/***/apache/conf/extraにhttpd-ssl.confがあれば
個人的な見解として不必要に思えます。.....私の勉強不足かな???
# killall httpd     ←でApacheを終了させる。
# rm -r /var/lib/Apache  ←Apacheをディレクトリ毎削除をしました
# /usr/local/src
/usr/local/src# tar zxvf httpd-2.2.17.tar.gz←解凍をする
/usr/local/src# cd httpd-2.2.17
/usr/local/src/httpd-2.2.17# ./configure --prefix=/var/lib/Apache --enable-rule=SHARED_CORE \ 
> --with-layout=Apache --enable-module=so --enable-module=status --enable-module=info \
> --enable-module=rewrite --enable-module=usertrack \
> --enable-modules=ssl --with-ssl=/usr/local/openssl --enable-proxy --enable-proxy-ajp 

/usr/local/src/httpd-2.2.17# make
/usr/local/src/httpd-2.2.17# su
/usr/local/src/httpd-2.2.17# make install

トップへ戻る

◆クライアント証明書リクエストの発行
# openssl genrsa -des 1024 > /usr/local/ssl/private/pri.pem
Enter Press Phrase:    ←パスワードを入力します。
Verfiying Enter Press Phrase:    ←同じパスワードを入力します。

ここで作成されたファイルの内容が表示されます。

----------END RSA PRIVATE KEY-------     ←メッセージを確認します。

# chmod 600 /usr/local/ssl/private/pri.pem

トップへ戻る

◆証明書発行に必要な CSR の作成
# # openssl req -new -days 365 -key /usr/local/ssl/private/pri.pem -out /usr/local/ssl/csr.pem
Enter pass phrase for /usr/local/ssl/private/pri.pem ←クライアント証明書リクエストの発行で入力したパスワードを入れます。

Country Name (2 letter code) [AU]:  ←JPと入力します。
State of Province Name (full name) [Some-state]: ←TOKYOと入力しました。
Localiity Name (eg, city) []:   ←KITA-KUと入力しました。
Organization Name(eg, company)[Internet Widgits Pty Ltd]: ←組織名(会社名など)です。hero-island,corpと入力しました。
Organization Unit Name (eg, section)[]: ←部門名などです。hero-islandと入力しました。
Common Name (eg, your name or your server's hostname)[]: ←サーバの名称などです。www.hero-island.ne.jpと入力しました。
Email Address []:←管理者のメールアドレスを入力します。

Please enter following 'extra' attributes
to be sent with your certificate request
A challenge password[]:  ←パスワードを入力します。
An optional company name: ←別会社名があれば入力します。私の場合は空enterです。

トップへ戻る

◆電子証明書の作成
通常では、この CSR を使って認証局に認証の依頼をしますが, ここでは自分で電子証明書を作成します。
# openssl x509 -in /usr/local/ssl/csr.pem -out /usr/local/ssl/certs/httpsd.pem -req -signkey /usr/local/ssl/private/pri.pem -days 365
Enter pass phrase for /usr/local/ssl/private/pri.pem ←クライアント証明書リクエストの発行で入力したパスワードを入れます。
Signature ok が上の方に表示されています。

トップへ戻る

◆httpd.confの編集
サーバの鍵ファイル(ca.key)と証明書ファイル(ca.der)が準備できたら、いよいよApacheのhttpd.confの設定です。
httpd.confの基本的な設定については、Apacheの設定で説明していますので、ここではSSLの部分のみを説明します。
# cd /var/lib/apache/conf
/var/lib/apache/conf/# vi httpd.conf← vi コマンドでhttpd.comfを開きます。

# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf ← #を外します。この行は最下位に近い行です。

以下のようにhttpd.confを設定します。

# cd /var/lib/apache/conf/extra
/var/lib/apache/conf/# vi httpd-ssl.conf← vi コマンドでhttpd-ssl.comfを開きます。

#   General setup for the virtual host
DocumentRoot "/var/lib/apache/htdocs"
ServerName www.hogehoge.com:443   ← 78行目付近、自分のドメイン名に変更しました。
ServerAdmin you@hogehoge.com      ← 79行目付近、管理者のメールアドレスに変更しました。
ErrorLog "/var/lib/apache/logs/error_log"
TransferLog "/var/lib/apache/logs/access_log"

   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.  Keep
#   in mind that if you have both an RSA and a DSA certificate you
#   can configure both in parallel (to also allow the use of DSA
#   ciphers, etc.)
SSLCertificateFile "/usr/local/ssl/certs/httpds.pem"  ← 99行目付近、/usr/local/ssl/certs/httpds.pemに修正にしました。


#   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"/usr/local/ssl/private/pri.pem"  ← 109行目付近、/usr/local/ssl/private/pri.pemに修正にしました。

/var/lib/apache/bin/apachectl -t  ← httpd.confにミスがない事を確認します。

/var/lib/apache/bin/apachectl restart  ← httpdを再起動します。

トップへ戻る

◆SSLの起動と停止
Apacheの起動と停止は以下のコマンドで行います。
# /var/lib/apache/bin/httpsdctl start      ←起動する場合

# /var/lib/apache/bin/httpsdctl stop       ←停止する場合

トップへ戻る

◆動作確認
クライアントPCのブラウザーを立ち上げて以下の動作確認を行います。
http://localhost
https://localhost


トップへ戻る

前ページへ戻る


ご質問・お問い合わせ - 免責事項
Copyright (C) 1998 hero-island. All Rights Reserved.