今回はさらにセキュリティを向上するためにSSLを導入したいと思います。
1.OpenSSLの設定ファイル編集およびサーバー証明書作成準備
メールサーバーのSSL証明書を作成する時にも実施しましたが下準備を行います。
[root@sl6 ~]# cd /etc/pki/tls
[root@sl6 tls]# mkdir www
# 設定ファイルを作業用ディレクトリにコピーします
[root@sl6 tls]# cp openssl.cnf ./www
[root@sl6 tls]# cd www
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 20
drwxr-xr-x. 2 root root 4096 6月 22 12:16 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 10906 6月 22 12:16 2011 openssl.cnf
# コピーしてきたopenssl.cnfファイルがあることを確認します
# 設定ファイルを編集します
[root@sl6 www]# vi openssl.cnf
# 42行目~44行目、48行目、55行目~56行目を修正します
dir = . # Where everything is kept # /etc/pki/CA から . に変更
certs = $dir # Where the issued certs are kept # $dir/certs から $dir に変更
crl_dir = $dir # Where the issued crl are kept # $dir/crl から $dir に変更
new_certs_dir = $dir # default place for new certs. # $dir/newcerts から $dir に変更
private_key = $dir/cakey.pem # The private key # $dir/private/cakey.pem から $dir/cakey.pem に変更
RANDFILE = $dir/.rand # private random number file # $dir/private/.rand から $dir/.rand に変更
# 保存してviエディタを終了します
# index.txtという空ファイルと01と書き込んだserialファイルを作成します
[root@sl6 www]# touch index.txt
[root@sl6 www]# echo 01 > serial
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 24
drwxr-xr-x. 2 root root 4096 6月 22 12:18 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
# index.txtファイルとserialファイルがあることを確認します
2.認証局の秘密鍵作成
認証局の秘密鍵を作成します。
Generating RSA private key, 2048 bit long modulus
............................++++++
....................++++++
e is 65537 (0x10001)
Enter pass phrase for ./cakey.pem: パスフレーズを入力
Verifying - Enter pass phrase for ./cakey.pem: パスフレーズを再入力
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 28
drwxr-xr-x. 2 root root 4096 6月 22 12:19 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
# 認証局の秘密鍵ファイル[cakey.pem]が作成されたことを確認します
3.認証局の証明書作成
「2.認証局の秘密鍵作成」で作成した認証局の秘密鍵ファイルを使って認証局の証明書を作成します。
Enter pass phrase for ./cakey.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) [XX]:JP # 日本なのでJP
State or Province Name (full name) []:chiba # 都道府県
Locality Name (eg, city) [Default City]:urayasu # 市区町村
Organization Name (eg, company) [Default Company Ltd]:sa-sa-ki.jp # 会社とかないのでとりあえずドメイン名
Organizational Unit Name (eg, section) []: 入力せずEnter
Common Name (eg, your name or your server's hostname) []:www.sa-sa-ki.jp # ウェブサーバーのFQDN名
Email Address []:入力せずEnter
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 32
drwxr-xr-x. 2 root root 4096 6月 22 12:21 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
# 認証局の証明書ファイル[cacert.pem]が作成されたことを確認します
4.サーバー秘密鍵作成
サーバー秘密鍵を作成します。
Generating RSA private key, 2048 bit long modulus
.....++++++
.................++++++
e is 65537 (0x10001)
Enter pass phrase for ./server.key: パスフレーズ入力
Verifying - Enter pass phrase for ./server.key: パスフレーズ再入力
# メールサーバーにSSLでアクセスした時に毎回パスフレーズを聞かれないようにパスフレーズ付きサーバー秘密鍵を作成します
[root@sl6 www]# openssl rsa -in ./server.key -out ./server.key
Enter pass phrase for ./server.key: server.keyファイル作成時のパスフレーズ入力
writing RSA key
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 36
drwxr-xr-x. 2 root root 4096 6月 22 12:21 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
-rw-r--r--. 1 root root 887 6月 22 12:21 2011 server.key
# サーバー秘密鍵ファイル[server.key]が作成されたことを確認します
5.サーバー証明要求書作成
「4.サーバー秘密鍵作成」で作成したサーバー秘密鍵ファイルを使ってサーバー証明要求書を作成します。
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) [XX]:JP
State or Province Name (full name) []:chiba
Locality Name (eg, city) [Default City]:urayasu
Organization Name (eg, company) [Default Company Ltd]:sa-sa-ki.jp
Organizational Unit Name (eg, section) []: 入力せずEnter
Common Name (eg, your name or your server's hostname) []:www.sa-sa-ki.jp
Email Address []: 入力せずEnter
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: 入力せずEnter
An optional company name []: 入力せずEnter
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 40
drwxr-xr-x. 2 root root 4096 6月 22 12:22 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial
-rw-r--r--. 1 root root 639 6月 22 12:22 2011 server.csr
-rw-r--r--. 1 root root 887 6月 22 12:21 2011 server.key
# サーバー証明要求書ファイル[server.csr]が作成されたことを確認します
6.サーバー証明要求書に署名
サーバー証明要求書ファイルに書名を行い、サーバー証明書を作成します。
Using configuration from ./openssl.cnf
Enter pass phrase for ./cakey.pem: cakey.pemのパスフレーズを入力します
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Jun 22 03:23:28 2011 GMT
Not After : Jun 19 03:23:28 2021 GMT
Subject:
countryName = JP
stateOrProvinceName = chiba
organizationName = sa-sa-ki.jp
commonName = www.sa-sa-ki.jp
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
X509v3 Authority Key Identifier:
keyid:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
Certificate is to be certified until Jun 19 03:23:28 2021 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 60
drwxr-xr-x. 2 root root 4096 6月 22 12:23 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-rw-r--r--. 1 root root 3039 6月 22 12:23 2011 01.pem
-rw-r--r--. 1 root root 944 6月 22 12:21 2011 cacert.pem
-rw-r--r--. 1 root root 963 6月 22 12:19 2011 cakey.pem
-rw-r--r--. 1 root root 76 6月 22 12:23 2011 index.txt
-rw-r--r--. 1 root root 21 6月 22 12:23 2011 index.txt.attr
-rw-r--r--. 1 root root 0 6月 22 12:18 2011 index.txt.old
-rw-r--r--. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-rw-r--r--. 1 root root 3 6月 22 12:23 2011 serial
-rw-r--r--. 1 root root 3 6月 22 12:18 2011 serial.old
-rw-r--r--. 1 root root 3039 6月 22 12:23 2011 server.cer
-rw-r--r--. 1 root root 639 6月 22 12:22 2011 server.csr
-rw-r--r--. 1 root root 887 6月 22 12:21 2011 server.key
# サーバー証明書ファイル[server.cer]が作成されたことを確認します
# 各ファイルをrootユーザ読み取り専用に権限を変更します
[root@sl6 www]# chmod 400 *
# 作業用ディレクトリの内容を確認しておきます
[root@sl6 www]# ls -la
合計 60
drwxr-xr-x. 2 root root 4096 6月 22 12:23 2011 .
drwxr-xr-x. 7 root root 4096 6月 22 12:16 2011 ..
-r--------. 1 root root 3039 6月 22 12:23 2011 01.pem
-r--------. 1 root root 944 6月 22 12:21 2011 cacert.pem
-r--------. 1 root root 963 6月 22 12:19 2011 cakey.pem
-r--------. 1 root root 76 6月 22 12:23 2011 index.txt
-r--------. 1 root root 21 6月 22 12:23 2011 index.txt.attr
-r--------. 1 root root 0 6月 22 12:18 2011 index.txt.old
-r--------. 1 root root 10867 6月 22 12:18 2011 openssl.cnf
-r--------. 1 root root 3 6月 22 12:23 2011 serial
-r--------. 1 root root 3 6月 22 12:18 2011 serial.old
-r--------. 1 root root 3039 6月 22 12:23 2011 server.cer
-r--------. 1 root root 639 6月 22 12:22 2011 server.csr
-r--------. 1 root root 887 6月 22 12:21 2011 server.key
# 全ファイルの権限が読み取りのみになっていることを確認しておきます
7.証明書の設定
作成したサーバー証明書ファイル使ってSSL通信できるようにApacheの設定ファイルを変更します。
##
## SSL Virtual Host Context
##
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html" # コメント解除
ServerName www.sa-sa-ki.jp:443 # コメント解除とドメイン名をwww.example.comからwww.sa-sa-ki.jpに変更
**************** 以下追加 ****************
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog logs/ssl_access_log combined
**************** 以下追加終わり ****************
# 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/www/server.cer #/etc/pki/tls/certs/localhost.crtから/etc/pki/tls/www/server.cerに変更
# 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/www/server.key # /etc/pki/tls/private/localhost.keyから/etc/pki/tls/www/server.keyに変更
# 保存してviエディタを終了します
Apacheを再起動して設定ファイルを反映します
[root@sl6 www]# /etc/rc.d/init.d/httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]
8.ファイヤーウォールの設定変更
HTTPSのポート番号のアクセス許可設定を行います。
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 123 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 465 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 993 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 995 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# 保存してviエディタを終了します
# iptablesを再起動して設定を反映します
[root@sl6 www]# /etc/rc.d/init.d/iptables restart
iptables: ファイアウォールルールを消去中: [ OK ]
iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ]
iptables: モジュールを取り外し中: [ OK ]
iptables: ファイアウォールルールを適用中: [ OK ]
9.ルータの設定変更
ルータがない場合は不要な手順になりますが、yasuの家にはCTUとサーバーの間にルータがありますので併せてNAT設定で443番ポートをサーバーに向けます。
設定方法はルータの設定手順に従ってください。
■関連記事
Scientific Linux 6で自宅サーバー構築 その1 サーバー機Express 5800 GT110bのオンボードRAIDでRAID1設定
Scientific Linux 6で自宅サーバー構築 その2 Scientific Linux 6をExpress5800/GT110bにインストール
Scientific Linux 6で自宅サーバー構築 その3 Scientific Linux 6インストール後の初期設定
Scientific Linux 6で自宅サーバー構築 番外編その1 Scientific Linux 6のcronについて
Scientific Linux 6で自宅サーバー構築 その4 Scientific Linux 6 にClamAVをインストールしてウィルス対策
Scientific Linux 6で自宅サーバー構築 その5 Scientific Linux 6 にTripwireをインストールしてファイル改ざんを検知する
Scientific Linux 6で自宅サーバー構築 その6 Scientific Linux 6 にchkrootkitをインストールしてrootkit感染を検知する
Scientific Linux 6で自宅サーバー構築 その7 NTPサーバーで自動時刻合わせ
Scientific Linux 6で自宅サーバー構築 その8 バッファオーバーフロー攻撃対策を行う
Scientific Linux 6で自宅サーバー構築 その9 logwatchでサーバー監視
Scientific Linux 6で自宅サーバー構築 その10 DNSサーバーを構築
Scientific Linux 6で自宅サーバー構築 番外編その2 Scientific Linuxを6.0から6.1にアップグレードする
Scientific Linux 6で自宅サーバー構築 その11 PostfixとDovecotとSMTP-AUTHでメールサーバーを構築する
Scientific Linux 6で自宅サーバー構築 その12 メールサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その13 Apache PHP MySQLをインストール
Scientific Linux 6で自宅サーバー構築 その14 WebサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その15 WordPressを導入する
Scientific Linux 6で自宅サーバー構築 その16 Piwikでアクセスログ集計
Scientific Linux 6で自宅サーバー構築 その17 Squidをインストール
Scientific Linux 6で自宅サーバー構築 その18 sshで鍵認証を導入
Scientific Linux 6で自宅サーバー構築 その19 WebDavの設定
Scientific Linux 6で自宅サーバー構築 その20 lm_sensorをインストール

















































