次のようなGoogleウェブマスター向け公式ブログでの推奨や、リモートか管理の安全性向上の向上のためにSSL(TLS)を有効にする。
概要
Googleさんの考え
- 保護されたウェブの普及を目指して(2018年2月27日):
2018 年 7 月にリリースされる Chrome 68 から、すべての HTTP サイトに「保護されていません」が表示されてしまうとのこと。 - HTTPS ページが優先的にインデックスに登録されるようになります(2015年12月18日):
セキュリティ強化の一環で、HTTPS ページが存在する場合はそちらを優先的にインデックスに登録するそうです。 - HTTPS をランキング シグナルに使用します(2014年8月7日):
検索結果のランキングにhttpsかどうかを考慮する。この判断基準は、良質なコンテンツかどうか?といった判断基準からすると、大きな基準ではなく、全体検索クエリの1%程度の影響でしかない。しなしながら、googleさんとしては、長い時間をかけて強化していくとのこと。
Webサイトのセキュリティレベルと設定をチェックするためにQualys Lab ツールの紹介もある。
サーバ証明書の選定
サーバ証明書の目的は通信の暗号化とそのサイトの実在証明である。
暗号化の強度は基本的に変わらないが、サイトを運営する組織の実在性をどれだけ求めるかによって、使用するサーバ証明書や費用が変わってくる。
その他、モバイルの対応率、複数ドメインの利用予定(ワイルドカード証明書)、サーバ証明書作成までの許容時間等も選定条件になりうる。
お金に余裕があるならEV認証で良いが、そうでないなら目的を踏まえてどの認証レベルのサーバ証明書を使うかを考える必要がある。
この辺の話は別途記載しよう…
設定の方針
個人で使用するサイト用のサーバ証明書なので、必然的にDVのものに限られる。(OV/EVは個人では取得できない。)
Let’s encryptの無料のサーバ証明書を使う方法もあるが、年間1,000円くらいであればいいかぁということで、FujiSSLのサーバ証明書を使います。
FujiSSL-安心・安全の純国産格安SSLサーバ証明書
https://www.fujissl.jp/
設定手順
FujiSSLのサイトの申込手順に沿って実施する。
準備
ドメイン使用権限の確認
ドメインを含むメールアドレスに送られたメール内容に基づいて操作を行って使用権限を確認するメール認証、指定ファイルをWebサイトに配置してクローラで確認してもらうファイル認証がある。申請時にどちらの認証を使用するか選択する必要がある。
当ドメインを含んだメールアドレスは持っていないことと、whoisは代行登録になっておりメールアドレスを公開しておらず、私の場合はメール認証は困難だと判断し、ファイル認証で進めた。
鍵ペア/CSRの生成
当サイトはLinux+Apacheなので、OpenSSLを使って鍵ペアの作成とCSRを作成する。
鍵の作成は”openssl genrsa”、CSRの作成は”openssl req”を使用する。
FujiSSLの手順書では、キーファイルの暗号化として”-des3″が指定されているが、より安全性の高い”-aes256″に変更して手順を実施した。CSR作成の時に入力するCommon Name以外の情報はDV認証の関係で消されてしまうので、適当な値を入れている。
(FujiSSL等のようなDVを使用する場合、ドメイン(Common Name)の検証はできるが、それ以外の組織の情報は検証できないので、ユーザに誤解を与えないよう証明書に表示しないようにしていると思われます。)
# cd /etc/httpd/conf # mkdir ssl # cd ssl/ # umask 0022 # umask 77 # openssl genrsa -aes256 2048 > server.key Generating RSA private key, 2048 bit long modulus ... Enter pass phrase: (パスフレーズ) Verifying - Enter pass phrase: (パスフレーズ) # umask 22 # openssl req -new -key server.key -out server.csr -sha256 Enter pass phrase for server.key: (パスフレーズ) 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) []:xxxx Locality Name (eg, city) [Default City]:xxxx Organization Name (eg, company) [Default Company Ltd]:xxxx Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:www.nextdoorwith.info Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: # openssl req -noout -text -in server.csr Certificate Request: ...
FujiSSLストアフロントから申請
ストアフロントから決済情報やCSR情報を入力し、ドメイン認証の方法(メール認証 or ファイル認証)を指定して、申請を完了させます。
私の場合はファイル認証を選択しました。
FujiSSLからメールで届いたファイルをWebサーバに配置し、5~10分ほどするとFujiSSL側で検証が完了し、サーバ証明書と中間証明書がメールで届きます。
サーバ証明書と中間証明書の内容はメール本文と、zip形式の添付ファイル(サーバ証明書:server.crt、中間証明書:ca-bundle.ca)にあります。コピペは間違いやすいので、ファイルをサーバにscpしました。
httpdへのサーバ証明書の組み込み
- 鍵とサーバ証明書を配置する。
サーバ証明書関連は/etc/pkiの下のようだが、既定のものとは別に管理する意図で、/etc/httpd/conf/ssl下に証明書関連ファイルを配置する。Windows用の余計な改行コード(^M)が付いているので、trコマンドで削除しています。# cd /etc/httpd/conf # mkdir ssl # cd ssl/ # mv /path/to/server.crt ./server.crt.org # mv /path/to/ca-bundle.ca ./ca-bundle.ca.org # tr -d "" < server.crt.org > server.crt # tr -d "" < ca-bundle.ca.org > ca-bundle.ca
- 鍵ファイルをオープンするためにスクリプトを配置する。
鍵ファイルは暗号化されておりオープンするためにはパスフレーズの指定が必要であり、起動時にパスフレーズを入力する必要があります。
現実的にこれは難しい運用になるので鍵ファイルの暗号化を解除するか、起動時にパスフレーズを指定できるような設定が必要になります。せっかく暗号化しているし…ちょっとだけ攻撃に対する耐性を向上するために、後者のパスフレーズを取得できる仕組みを採用します。
これはapacheのSSLPassPhraseDialogディレクティブを使って実現できます。パスフレーズを出力するスクリプトを作成し、このディレクティブでそのスクリプトを指定します。
このスクリプトはhttpd_keypp.shという名前します。# cd /xxxx/ # umask 0022 # umask 77 # vi httpd_keypp.sh # chmod u+x httpd_keypp.sh # ls -l ... -rwx------ 1 root root 256 Jun 24 04:11 httpd_keypp.sh ... # umask 22
#!/bin/sh # # httpd_keypp.sh # # SSL秘密鍵を取得するためのパスフレーズを出力する。 # httpdの起動時に使用する想定である。 # 詳細はapacheのssl.conf(SSLPassPhraseDialog)を参照のこと。 # echo "(パスフレーズ)"
- SSLの設定を追加します。
下記の内容はapache2.4.7以前で有効です。
中間証明書の指定で使用しているSSLCertificateChainFileディレクティブは2.4.8以降では廃止になっています。2.4.8以降の方は、サーバ証明書のファイル(server.crt)の最後に中間証明書のファイル内容(ca-bundle.ca)を追加して、一つのファイルにし、このファイルをSSLCertificateFileディレクティブに指定する必要があるとのこと。# rpm -qa|grep http httpd-2.4.xxx-xxx.xxx.centos.x86_64 ... # cd /etc/httpd/conf.d # cp -p ssl.conf ssl.conf.org # vi ssl.conf
# Pass Phrase Dialog: # Configure the pass phrase gathering process. # The filtering dialog program (`builtin' is a internal # terminal dialog) has to provide the pass phrase on stdout. #SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog SSLPassPhraseDialog exec:/xxxx/httpd_keypp.sh … # 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/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/server.key # Server Certificate Chain: # Point SSLCertificateChainFile at a file containing the # concatenation of PEM encoded CA certificates which form the # certificate chain for the server certificate. Alternatively # the referenced file can be the same as SSLCertificateFile # when the CA certificates are directly appended to the server # certificate for convinience. #SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt SSLCertificateChainFile /etc/httpd/conf/ssl/ca-bundle.ca …
- 設定変更を反映するためにhttpdを再起動します。
# systemctl restart httpd.service # systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2018-06-24 04:43:40 JST; 11s ago ... Jun 24 04:43:40 ipsilon systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.
動作確認
ブラウザでサイトを開き、セキュリティの警告が表示されなければ成功です。
問題がある場合はFujiSSLの確認ツールで問題の切り分けが行えます。