#contents *Let's Encrypt [#ub447e03] -https://letsencrypt.org/ --%%人類補完計画%% HTTPS デフォルト化計画 --スポンサー Cisco, Akamai, Electronic Frontier Foundation, Mozilla --2016-04-12 サービスイン -有効期間 90 日の SSL サーバー証明書を無料で発効 -この記事の前提 [Cent OS 6.7 on Sakura VPS] *Let's Encrypt (certbot) のインストール [#r6e42e3e] # yum install -y git openssl mod_ssl # cd /opt # git clone https://github.com/certbot/certbot # cd certbot # ls # ./certbot-auto --help 最後の help 表示(certbotの初回起動)で、certbot が依存ライブラリをワシワシ取ってくる *証明書発行 [#p850e856] -plugin |plugin|note|Apache一時停止|h |apache |Debian ベースの Linux OS 上の Apache2.4 に対して証明書を自動設定|必要| |webroot |現在稼働中の Apache サーバを利用して、Let's Encrypt サーバが存在確認|不必要| |standalone|簡易Webサーバを起動して、Let's Encrypt サーバが存在確認|必要| |manual |手動で証明書を発行|不必要| |nginx |開発中|必要| 証明書を発効する Let's Encrypt 側では、証明書を置く Apache サーバがあるのかを実際に 80/443 にアクセスして検証する。&br; 現時点では webroot が簡単そう。証明書発行は一度のことではなくて、90 日ごと必要ですし -webroot (練習) <本番の証明書の発行は1週間に5回まで!> # /opt/certbot/certbot-auto certonly --webroot -w /var/www/html/ -d hondou.homedns.org --test-cert /etc/letsencrypt/live/hondou.homedns.org/ 以下に鍵ができていたら成功 &br; "--test-cert" で作られた証明書は認証局に裏書されていない -webroot (本番) # /opt/certbot/certbot-auto certonly --webroot -w /var/www/html/ -d hondou.homedns.org ... IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/hondou.homedns.org/fullchain.pem. Your cert will expire on 2016-08-15. To obtain a new version of the certificate in the future, simply run Certbot again. - If you like Certbot, please consider supporting our work by: acme-challenge (Let's Encrypt からの存在確認) # cat /var/log/httpd/access_log | grep acme-challenge 66.133.109.36 - - [17/May/2016:23:23:51 +0900] "GET /.well-known/acme-challenge/***** HTTP/1.1" 200 107 "-" "Mozilla/5.0 (compatible; Let's Encrypt validation server; +https://www.letsencrypt.org)" *Apache への組み込み [#r7321506] -/etc/httpd/conf.d/ssl.conf に証明書を登録 SSLCertificateFile /etc/letsencrypt/live/hondou.homedns.org/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/hondou.homedns.org/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/hondou.homedns.org/chain.pem -Apache 再起動 # service httpd restart -https でアクセスできるようになった #ref(cert.png) -jQuery や MathJax などの Javascript や web-font などを CDN で参照している場合、参照 URL も HTTPS にする必要あり。ブラウザが HTTPS のサイトから HTTP で外部サイトを参照している場合、読み込みを中断してしまう。 *SSL設定を妥当にする [#ud79139f] -チェック https://www.ssllabs.com/ -推奨設定生成 https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=apache-2.2.15&openssl=1.0.1e&hsts=yes&profile=intermediate -→ ちょい古めのブラウザまで対応で、評価 A の設定 -Oldest compatible clients : Firefox 1, Chrome 1, IE 7, Opera 5, Safari 1, Windows XP IE8, Android 2.3, Java 7 *証明書の自動更新 [#ia61f9d9] -"certbot-auto renew" は、証明書が期限切れ間近だったとき、証明書を更新する。 --何回呼んでもいい --/etc/letsencrypt/live/ 以下のシンボリックリンクが最新版に差し替えられる --Apache の再起動は不要 ... なはず -/etc/cron.weekly/01-certbot #code(bash){{{ #!/bin/bash /bin/date >> /var/log/certbot.log /opt/certbot/certbot-auto renew >> /var/log/certbot.log 2>&1 }}} --chmod +x 01-certbot を忘れずに --アルファベット順に実行される。証明書の更新は 99-backup よりも前に実行したい -/etc/logrotate.d/certbot #code(plain){{{ /var/log/certbot.log { monthly # 月初に100kを超えていたらローテート minsize 100k rotate 5 # 5 世代 missingok # ログファイルがなくてもエラーにしない notifempty # 空ファイルの場合はローテートしない compress # 古いログは圧縮 } }}} *HTTP アクセスを HTTPS にリダイレクト [#w9e53172] -/etc/httpd/conf.d/rewrite.conf #code(plain){{{ RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] }}} -HTTPS でないリクエストは https:// にリダイレクト -ステータスコードは 301 (Moved Permanently) *CentOS6 で Let's Encrypt 実行環境の Python を 2.6 から 2.7 にアップグレード [#veefbc3d] -ログを見ると、最近こんなメッセージが出るようになった Had a problem while installing Python packages: DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6 -つーことで、Let's Encrypt の certbot-auto コマンドが動く環境を Python 2.7 にアップグレードする -どこをアップグレードするか? --certbot-auto コマンドは /root/.local/share/letsencrypt 以下にある python で動く --ここの python は、初回の certbot-auto コマンド実行時に有効になっている python がコピーされる -ということで ++SCL と Python 2.7 をインストールする。cf.「[[Sakura CentOS6 で SCL を使って Python2.7 を使う]]」 ++現在の実行環境を退避する # mv /root/.local/share/letsencrypt /root/.local/share/~letsencrypt ++Python 2.7 を有効化する # scl enable python27 bash # python -V Python 2.7.8 ++certbot-auto コマンドを実行する # /opt/certbot/certbot-auto renew Python2.7 が /root/.local/share/letsencrypt にコピーされる # ls /root/.local/share/letsencrypt/bin/ activate activate_this.py easy_install-2.7 ndg_httpclient pip2 python-config unit2 activate.csh certbot jws pbr pip2.7 python2 wheel activate.fish easy_install letsencrypt pip python python2.7 ++SCL から抜けて certbot-auto が件の警告メッセージを出さないことを確認 # exit # python -V Python 2.6.6 # /opt/certbot/certbot-auto renew ------------------------------------------------------------------------------- Processing /etc/letsencrypt/renewal/hondou.homedns.org.conf ------------------------------------------------------------------------------- The following certs are not due for renewal yet: /etc/letsencrypt/live/hondou.homedns.org/fullchain.pem (skipped) No renewals were attempted. ++退避した実行環境を削除 # rm -rf /root/.local/share/~letsencrypt *2021追記 : Certbotが使えなくなったので、GetSSLで代替 [#m11c476c] -Certbot は snap でしか更新されず、旧版からのアクセスは拒絶される様になった -bashで完結している GetSSL で代替えする --https://github.com/srvrco/getssl ---- [[CentOS 6 on さくらVPS]]