ディストリビューション : CentOS7
アプリケーション : Apache2.4(IUS) mod_ssl(IUS)
SSL証明書ファイルは、比較的安い場所でも全く問題はありません。
よく勘違いされている方がいるが、有名であれば安全と先入観を持たれている方達が多いのは不思議でたまりません。ま、企業の宣伝内容もそうですが。。
また、有名な認証機関は安心 = 高額 ← この考え方も理解に苦しみます。やっていることは全く同じで、管理体制はどうなっているのか?その違いだけであまりにも高額すぎるからSSLが普及しない、高額すぎるからSSLの普及に弊害を及ぼしています。大手SSL発行会社はいい加減気づいたらどうだろうか?レンタルサーバを運営する方がよっぽど運営費用も専門技術者の人件費もかかります、なのに大手SSL発行会社はあまりにも高額するぎる。1000円前後が妥当ではないだろうか、そもそも通信を暗号化するのに費用が発生する理由が分かりません。それなら独自のDNSサーバはどうなるのか?、これに関してはブラウザーの開発会社は警告を出すことはないが、独自の認証局(ドメイン認証)だけはあたかも何かあるかのように表示をブロックして表示をさせません。独自であればどちらも信頼されるべきサーバではないはずだと思います。
高額な金額を設定をしている認証局はSSLを普及するためにもそのような会社は淘汰されるべきである、がしかし、インターネットの社会は独裁政権なのかもしれない。
また、実在証明型(OV)、EVタイプ(EV)等、色々といかにお金を取るか?認証局の運営会社は色々と仕掛けてきますが、全く不必要。大手認証局の運営会社とブラウザーの開発元の策略に従うのはどう考えてもおかしな話だ、IPv6も同じ事が言えるのかもしれない。SSLの普及、インターネットの技術進歩を妨げたいのかとも思えてしまう。
前置きが長くなりましたが、よほど怪しい認証局でない限り自前で認証局を作るよりも手間が省ける、ブラウザーからブロックされないので比較的安い場所で発行してもらうのが簡単です。
最近は無料のLet’s Encryptの認証局もありますが、無料ほど今の時代何をされるのか分からないのでここでは利用しません。「SSL 発行 安い」で検索してみてください。年間1000円〜2000円程度の発行会社はそれなりにあります。
インストールの説明のためにKingSSLの認証局を前提にすすめます。
mod_sslのインストール
yum --disablerepo=base,extras,updates --enablerepo=ius install httpd24u-mod_ssl
証明書等保存フォルダの作成
mkdir /etc/httpd/ssl/ cd /etc/httpd/ssl/
秘密鍵の作成(2048bit)
openssl genrsa -des3 2048 > server.key
CSRの作成
openssl req -new -key server.key -out server.csr
個人であれば、Country NameとCommon Nameだけでいいのでは?入力したい方は入力してください。
Country Name (2 letter code) [XX]: JP State or Province Name (full name) []: Locality Name (eg, city) [Default City]: Organization Name (eg, company) [Default Company Ltd]: Common Name (eg, your name or your server's hostname) []: xxx.xxx.com Email Address []: A challenge password []: An optional company name []:
パスフレーズの埋込
openssl rsa < server.key > server_withpass.key
以上完了すると、3つのファイルが生成される。
・server.csr
・server.key
・server_withpass.key
運用に利用されるファイルは「*.keyファイル」だが、server.keyを利用するとApache起動時にパスフレーズを聞かれて面倒なので、ここではserver_withpass.keyを利用する前提で話を進める。
認証局にserver.csrの中身をコピペして提出して申請が完了すると、メールで証明書ファイルが3つ送られてくる。
証明書ファイルを「server.crt」
中間証明書ファイルを「server-chain.crt」
として先ほど作成したSSLフォルダに保存をする。
/etc/httpd/conf.d/ssl.conf
# # When we also provide SSL we have to listen to the # standard HTTPS port in addition. # Listen 443 https ## ## SSL Global Context ## ## All SSL configuration in this context applies both to ## the main server and all SSL-enabled virtual hosts. ## # Pass Phrase Dialog: # Configure the pass phrase gathering process. # The filtering dialog program (`builtin' is an internal # terminal dialog) has to provide the pass phrase on stdout. SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog # Inter-Process Session Cache: # Configure the SSL Session Cache: First the mechanism # to use and second the expiring timeout (in seconds). SSLSessionCache shmcb:/run/httpd/sslcache(512000) #SSLSessionCacheTimeout 300 SSLSessionCacheTimeout 3600 # Pseudo Random Number Generator (PRNG): # Configure one or more sources to seed the PRNG of the # SSL library. The seed data should be of good random quality. # WARNING! On some platforms /dev/random blocks if not enough entropy # is available. This means you then cannot use the /dev/random device # because it would lead to very long connection times (as long as # it requires to make more entropy available). But usually those # platforms additionally provide a /dev/urandom device which doesn't # block. So, if available, use this one instead. Read the mod_ssl User # Manual for more details. SSLRandomSeed startup file:/dev/urandom 256 SSLRandomSeed connect builtin #SSLRandomSeed startup file:/dev/random 512 #SSLRandomSeed connect file:/dev/random 512 #SSLRandomSeed connect file:/dev/urandom 512 # # Use "SSLCryptoDevice" to enable any supported hardware # accelerators. Use "openssl engine -v" to list supported # engine names. NOTE: If you enable an accelerator and the # server does not start, consult the error logs and ensure # your accelerator is functioning properly. # SSLCryptoDevice builtin #SSLCryptoDevice ubsec ## ## SSL Virtual Host Context ## SSLStaplingCache shmcb:/run/httpd/stapling_cache(128000) <VirtualHost _default_:443> ProtocolsHonorOrder On Protocols h2 http/1.1 # General setup for the virtual host, inherited from global configuration #DocumentRoot "/var/www/html" #ServerName www.example.com:443 # Use separate log files for the SSL virtual host; note that LogLevel # is not inherited from httpd.conf. LogFormat "%h - - %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" ErrorLog logs/ssl_error_log TransferLog logs/ssl_access_log LogLevel warn # SSL Engine Switch: # Enable/Disable SSL for this virtual host. SSLEngine on SSLUseStapling On # List the protocol versions which clients are allowed to connect with. # Disable SSLv3 by default (cf. RFC 7525 3.1.1). TLSv1 (1.0) should be # disabled as quickly as practical. #SSLProtocol all -SSLv3 #SSLProxyProtocol all -SSLv3 #SSLProtocol all -SSLv2 -SSLv3 #SSLProxyProtocol all -SSLv2 -SSLv3 SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLProxyProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 # User agents such as web browsers are not configured for the user's # own preference of either security or performance, therefore this # must be the prerogative of the web server administrator who manages # cpu load versus confidentiality, so enforce the server's cipher order. SSLHonorCipherOrder on # SSL Cipher Suite: # List the ciphers that the client is permitted to negotiate. # See the mod_ssl documentation for a complete list. # httpd 2.2.30, 2.4.13 and later force-disable aNULL, eNULL and EXP ciphers. #SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4 #SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4 SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256 SSLProxyCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256 # 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.) # Some ECC cipher suites (http://www.ietf.org/rfc/rfc4492.txt) # require an ECC certificate which can also be configured in # parallel. #SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateFile /etc/httpd/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.) # ECC keys, when in use, can also be configured in parallel #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key SSLCertificateKeyFile /etc/httpd/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 convenience. #SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt SSLCertificateChainFile /etc/httpd/ssl/server-chain.crt
Apache MPMの挙動をevent MPMに変更
mod_phpを利用してる場合はFastCGIに変更する必要があるので注意
/etc/httpd/conf.modules.d/00-mpm.conf
# Select the MPM module which should be used by uncommenting exactly # one of the following LoadModule lines: # prefork MPM: Implements a non-threaded, pre-forking web server # See: http://httpd.apache.org/docs/2.4/mod/prefork.html #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so # worker MPM: Multi-Processing Module implementing a hybrid # multi-threaded multi-process web server # See: http://httpd.apache.org/docs/2.4/mod/worker.html # #LoadModule mpm_worker_module modules/mod_mpm_worker.so # event MPM: A variant of the worker MPM with the goal of consuming # threads only for connections with active processing # See: http://httpd.apache.org/docs/2.4/mod/event.html # LoadModule mpm_event_module modules/mod_mpm_event.so
セキュリティー設定 1を設定していない方は設定してください。終わりましたら、下記の内容を最後に追加してください。
/etc/httpd/conf.d/security.conf
Header always set Strict-Transport-Security "max-age=31536000"
上記設定ではHTTPで接続した際に強制的にHTTPSへリダイレクト(365日間有効)しますが、最初の接続はHTTP接続になるのでApacheのrewrite機能を併用します、rewrite.confのファイルを作成してください。
/etc/httpd/conf.d/rewrite.conf
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>
再起動
systemctl restart httpd.service
読み込まれた設定ファイルの確認
httpd -t -D DUMP_CONFIG 2>/dev/null | grep '# In'
動作確認
1.rewrite.conf、ssl.confが読み込まれていることを確認
2.ログファイルに「HTTP/2.0」と記載されていることを確認
3.設定内容をテストするために、https://www.ssllabs.comのサービスを使って確認
(A+で評価されたら無事完了です)
もし動かない場合は、/etc/httpd/conf.modules.d/00-base.conf の下記モジュールが無効にされていないか確認してください。
LoadModule http2_module modules/mod_http2.so