MENU

溶けかけてるうさぎ HP GALLERY BLOG TOP RECENT ARTICLES POPULAR ARTICLES ABOUT THIS BLOG

CATEGORY

大学 (140) 仕事 (17) 航空宇宙 (104) 写真 (77) 旅行 (32) 飯・酒 (17) コンピュータ (118) その他 (44)

TAG

ARCHIVE

RECENT

【カメラ】X100 シリーズが好きすぎる(主にリーフシャッタ) 【カメラ】X100V から X100VI に買い替えました 【自宅サーバー】Google Domains から Cloudflare にドメインを移管 【カメラ】FUJIFILM XF レンズのサイズ比較ができるようにしてみた 【写真】自作写真閲覧ページにてフィルムシミュレーションで写真をフィルタできるようにした

【HPのURL変更】Let’s encryptでホームページのSSL化

事象発生日:2018-07-04

記事公開日:2018-07-04

アクセス数:5496

Ubuntu ServerのWebサーバーをSSL化する.

 

などにあるように,今年の夏にリリースされるChrome 68以降,SSL証明書のないWebサイトに対して警告を出すことが決まっている.

HPのURLを変えたついでに,この手続をしてしまおう,と思いSSL証明書を導入しようとしたが,思わぬところで2度つまずいた.

 

右往左往しているため見にくいが,時系列にログを残す.

 

トップ画像の出典はこちら

0.はじめに

この記事は,「」の続きである.

前記事ではURL変更のためDNS設定などを行った.

1.動作環境

Ubuntu Server 16.04.2 LTS

Apache 2.4.18(インストール済み)

2.ポートマッピング設定

TCP 80だけでなく,TCP 443もWebサーバーに転送されるようにポートマッピング.

3.SSL証明書の発行(途中まで)

Certbotクライアント(Ubuntuではまだ古いletsencryptという名称),Apache用のプラグインをインストール.
$ sudo apt install letsencrypt python-letsencrypt-apache
Apache用の設定.
$ sudo letsencrypt run --apache

TUIが出てきたのだが,Apacheで設定しているホスト名を選択する画面が出てきてしまった.

先にApache側のホスト名の更新をかける必要がありそう.

4.Apacheの設定(途中まで)

ホスト名を変更した.

$ cd /etc/apache2/sites-available/

$ sudo nano 000-default.conf

$ diff -c0 000-default.conf 000-default.conf_2018.07.04
*** 000-default.conf    2018-07-04 17:25:13.036238773 +0900
--- 000-default.conf_2018.07.04 2018-07-04 17:24:40.557269212 +0900
***************
*** 10 ****
!       ServerName meltingrabbit.com
--- 10 ----
!       ServerName meltingrabbit.dip.jp

$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.

5.SSL証明書の発行(途中まで)

Apache用の設定.
$ sudo letsencrypt run --apache


Client does not support any combination of challenges that will satisfy the CA.

IMPORTANT NOTES:
 - If you lose your account credentials, you can recover through
   e-mails sent to ******@***.
 - Your account credentials have been saved in your Let's Encrypt
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Let's
   Encrypt so making regular backups of this folder is ideal.

あれ?普通に証明書発行失敗してね...?

6.Apacheの設定(途中まで)

$ cd /etc/apache2/

$ sudo a2enmod ssl
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  service apache2 restart

$ sudo a2ensite default-ssl
Enabling site default-ssl.
To activate the new configuration, you need to run:
  service apache2 reload

$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.

$ cd sites-available/

$ sudo nano default-ssl.conf

$ diff -c0 default-ssl.conf default-ssl.conf_2018.07.04
*** default-ssl.conf    2018-07-04 18:08:12.414479377 +0900
--- default-ssl.conf_2018.07.04 2018-07-04 18:05:46.583110104 +0900
***************
*** 3,5 ****
!               ServerName meltingrabbit.com
!               # ServerAdmin webmaster@localhost
!               ServerAdmin melting.rabbit.mr@gmail.com
--- 3 ----
!               ServerAdmin webmaster@localhost

$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.

すると,httpでもつながらなくなったw

 

設定を戻す.

$ sudo a2dissite default-ssl
$ sudo a2dismod ssl
$ sudo /etc/init.d/apache2 restart 

7.不具合原因

に本質情報があった....

最近Lets encryptを思考停止しながらsudo apt install letsencryptしたら Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA っていう感じでエラーが出てきた。

 

どうやらUbuntuのレポジトリに入っているものは若干古いバージョンの模様。ちなみにこのエラーは1/9にTLS-SNI-01による申請(?)が禁止されたことによる模様。

 

やり直す.

8.SSL証明書の発行

必要な環境構築
$ sudo apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
取得:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
取得:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [803 kB]
取得:6 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [733 kB]
取得:7 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [331 kB]
取得:8 http://jp.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [640 kB]
取得:9 http://jp.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [584 kB]
取得:10 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [518 kB]
取得:11 http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages [456 kB]
取得:12 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [222 kB]
4,610 kB を 3秒 で取得しました (1,526 kB/s)
パッケージリストを読み込んでいます... 完了

$ sudo apt-get install software-properties-common
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
software-properties-common はすでに最新バージョン (0.96.20.7) です。
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  linux-headers-4.4.0-127 linux-headers-4.4.0-127-generic linux-image-4.4.0-127-generic
  linux-image-extra-4.4.0-127-generic
これを削除するには 'sudo apt autoremove' を利用してください。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。

$ sudo add-apt-repository ppa:certbot/certbot             # 専用レポジトリの追加
 This is the PPA for packages prepared by Debian Let's Encrypt Team and backported for Ubuntu(s).
 詳しい情報: https://launchpad.net/~certbot/+archive/ubuntu/certbot
[ENTER] を押すと続行します。ctrl-c で追加をキャンセルできます

gpg: 鍵リング「/tmp/tmpk6l2ya9o/secring.gpg」ができました
gpg: 鍵リング「/tmp/tmpk6l2ya9o/pubring.gpg」ができました
gpg: 鍵75BCA694をhkpからサーバkeyserver.ubuntu.comに要求
gpg: /tmp/tmpk6l2ya9o/trustdb.gpg: 信用データベースができました
gpg: 鍵75BCA694: 公開鍵"Launchpad PPA for certbot"をインポートしました
gpg: 処理数の合計: 1
gpg:               インポート: 1  (RSA: 1)
OK

$ sudo apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease
ヒット:3 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease
ヒット:4 http://security.ubuntu.com/ubuntu xenial-security InRelease
取得:5 http://ppa.launchpad.net/certbot/certbot/ubuntu xenial InRelease [24.3 kB]
取得:6 http://ppa.launchpad.net/certbot/certbot/ubuntu xenial/main amd64 Packages [15.3 kB]
取得:7 http://ppa.launchpad.net/certbot/certbot/ubuntu xenial/main i386 Packages [15.3 kB]
取得:8 http://ppa.launchpad.net/certbot/certbot/ubuntu xenial/main Translation-en [9,516 B]
64.5 kB を 3秒 で取得しました (21.4 kB/s)
パッケージリストを読み込んでいます... 完了

$ sudo apt-get install python-certbot-apache
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  letsencrypt linux-headers-4.4.0-127 linux-headers-4.4.0-127-generic linux-image-4.4.0-127-generic
  linux-image-extra-4.4.0-127-generic python-acme python-augeas python-chardet python-configargparse python-configobj
  python-dialog python-funcsigs python-mock python-ndg-httpsclient python-parsedatetime python-pbr python-psutil
  python-pyicu python-requests python-rfc3339 python-tz python-urllib3 python-zope.component python-zope.event
  python-zope.hookable python-zope.interface
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  certbot letsencrypt python3-acme python3-asn1crypto python3-augeas python3-certbot python3-certbot-apache
  python3-cffi-backend python3-configargparse python3-configobj python3-cryptography python3-funcsigs python3-future
  python3-icu python3-idna python3-josepy python3-mock python3-ndg-httpsclient python3-openssl python3-parsedatetime
  python3-pbr python3-pyasn1 python3-requests-toolbelt python3-rfc3339 python3-tz python3-zope.component
  python3-zope.event python3-zope.hookable python3-zope.interface
提案パッケージ:
  python3-certbot-nginx python-certbot-doc python-acme-doc python-certbot-apache-doc python-configobj-doc
  python-cryptography-doc python3-cryptography-vectors python-funcsigs-doc python-future-doc python-mock-doc
  python-openssl-doc python3-openssl-dbg doc-base
以下のパッケージは「削除」されます:
  python-letsencrypt python-letsencrypt-apache
以下のパッケージが新たにインストールされます:
  certbot python-certbot-apache python3-acme python3-asn1crypto python3-augeas python3-certbot python3-certbot-apache
  python3-cffi-backend python3-configargparse python3-configobj python3-cryptography python3-funcsigs python3-future
  python3-icu python3-idna python3-josepy python3-mock python3-ndg-httpsclient python3-openssl python3-parsedatetime
  python3-pbr python3-pyasn1 python3-requests-toolbelt python3-rfc3339 python3-tz python3-zope.component
  python3-zope.event python3-zope.hookable python3-zope.interface
以下のパッケージはアップグレードされます:
  letsencrypt
アップグレード: 1 個、新規インストール: 29 個、削除: 2 個、保留: 30 個。
1,765 kB のアーカイブを取得する必要があります。
この操作後に追加で 8,872 kB のディスク容量が消費されます。
続行しますか? [Y/n] y
... [以下略]
SSL証明書の発行と,ApacheでのSSL有効化
$ sudo certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: meltingrabbit.com
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for meltingrabbit.com
Waiting for verification...
Cleaning up challenges
Could not reverse map the HTTPS VirtualHost to the original

IMPORTANT NOTES:
 - Unable to install the certificate
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/meltingrabbit.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/meltingrabbit.com/privkey.pem
   Your cert will expire on 2018-10-02. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"

$ cd /etc/apache2/sites-available

$ sudo nano default-ssl.conf

$ diff -c0 default-ssl.conf default-ssl.conf_2018.07.04
*** default-ssl.conf    2018-07-04 22:32:04.498174187 +0900
--- default-ssl.conf_2018.07.04 2018-07-04 18:05:46.583110104 +0900
***************
*** 2,5 ****
!       
!               ServerName meltingrabbit.com
!               # ServerAdmin webmaster@localhost
!               ServerAdmin melting.rabbit.mr@gmail.com
--- 2,3 ----
!       
!               ServerAdmin webmaster@localhost
***************
*** 34,37 ****
!               # SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
!               # SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
!               SSLCertificateFile    /etc/letsencrypt/live/meltingrabbit.com/fullchain.pem
!               SSLCertificateKeyFile /etc/letsencrypt/live/meltingrabbit.com/privkey.pem
--- 32,33 ----
!               SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
!               SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
***************

$ sudo a2enmod ssl
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  service apache2 restart


$ sudo a2ensite default-ssl
Enabling site default-ssl.
To activate the new configuration, you need to run:
  service apache2 reload

$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.

 

またhttpでの接続ができなくなった.

Could not reverse map the HTTPS VirtualHost to the originalが問題か.

 

 

いろいろ調査すると,vpnサーバーと443のListenポートがかぶっていることが判明.

ss -lntsudo lsof -i:443などでどのプロセスがListenしているのか確認できる.

 

vpnサーバーの設定を変更後,Apacheを再起動すると,無事SSLでの接続が確立できた.

9.もろもろの残作業

DoS攻撃対策をSSL通信にも適用(過去記事「」参照)
ダイジェスト認証の設定
リダイレクト設定(過去記事「」参照)
アクセス解析ツールの設定(過去記事「」参照)

10.出典・参考サイト

Let's Encrypt - Free SSL/TLS Certificates. Retrieved July 4, 2018, from https://letsencrypt.org/
Let's Encrypt 総合ポータル. Retrieved July 4, 2018, from https://letsencrypt.jp/
HRENDOH'S TECH MEMO. Let's encryptでUbuntu 16.04のApacheをhttps化するには. Retrieved July 4, 2018, from https://blog.hrendoh.com/how-to-secure-apache-with-lets-encrypt-on-ubuntu-16-04/
Qiita. Apache 2.4 on Ubuntu 16.04でSSL. Retrieved July 4, 2018, from https://qiita.com/tontan9616/items/bd8b2f1f360f26c7bb46
Raspi日記. Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA と言われた時の解決法. Retrieved July 4, 2018, from https://raspi-diary.com/post-1708/
さくらのSSL. Chromeの強制的な警告表示が2018年7月から開始. Retrieved July 4, 2018, from https://ssl.sakura.ad.jp/column/https-not-valid3/

関連記事

コメントを投稿

名前

Email (※公開されることはありません)

コメント