絖綛 N@i.jp  昨日:00051060
 今日:00023438
 総計:00126805
keywords
管理者専用
  Post   Add link   Control Panel 































新しいトピック
最新:03/21 19:08


新しいコメント
最新:07/28 16:47






管理人へMAIL

プライバシーポリシー

Let's Encryptで常時SSL化してみた話(Certbotクライアントのインストール編〜)

参照:Let's Encrypt


ここの突破が大変でしたの


2. Certbotクライアントのインストール

 日本語の「Let's Encrypt 総合ポータル (非公式解説サイト)」<https://free-ssl.jp>から辿るのが分かりやすい。

2.1 Certbotクライアントのダウンロード

 「Let's Encrypt 総合ポータル」→「Let's Encrypt の使い方」→「その他のUNIX系OS」を参照し、Certbotクライアントをダウンロードする(とは言え、後にこれは不要になるのだが・・・)。

$ cd ~/tmp
$ wget https://dl.eff.org/certbot-auto
$ chmod a+x certbot-auto

2.2 certbot-autoを編集する

 certbot-auto は単なるシェルスクリプトなので、普通のエディタで修正できる。修正は、

  • sudo の -Eオプションの削除

だけ。これはウチの sudoコマンドには -Eオプションが無いので、それへの対応であり、普通は必要ないはず。

      sudo)
        SUDO="sudo -E"
          ↓
        SUDO="sudo"
〜略〜
      if $EXISTS sudo 1>/dev/null 2>&1; then
        SUDO="sudo -E"
          ↓
        SUDO="sudo"

2.3 インストールする

 certbot-auto を実行すると、OS 標準のパッケージリポジトリ(apt-get や yum など)を使用して、Certbot クライアントの実行に必要な複数のパッケージ(依存関係にあるパッケージ)が自動的にインストールされ、仮想化された Python環境(PyPI からダウンロードしたパッケージを動作させるための環境)が構築されます。

「Certbotクライアントのインストール」より引用

 インストールするには "./certbot-auto" しろとのことだが、Mac OS Xでは「Homebrewを使ってインストールしなさい」と、つれない返事が返ってくる。自慢じゃないが、ウチの Mac OS X(Tiger) には Homebrew なんか無い(厳密には Tigerbrewというのがある事はあるらしいが)。つまり、ビルド済みのパッケージによるお手軽インストールはできないのだった。
 そうなると必然的に「Let's Encrypt ユーザーガイド」の『ソースからインストールする方法』を採ることになる。Developer Guide(英文)によると、GitリポジトリからCertbotクライアントをダウンロードし、

$ cd ~/tmp
$ git clone https://github.com/certbot/certbot
$ cd certbot
$ ./certbot-auto --debug --os-packages-only

でインストールという事になるらしい。"certbot-auto" の実行前に再び 2.2 の修正と、それに加えて OpenSSL を使用するよう CFLAGS, LDFLAGS環境変数を設定する。

set -e  # Work even if somebody does "sh thisscript.sh".

export SSL="/usr/local/ssl"     # ←追加
export CFLAGS="-I${SSL}/include -I/usr/local/include -I/usr/include"      # ←追加
export LDFLAGS="-L${SSL}/lib -lssl -lcrypto -L/usr/local/lib -L/usr/lib"  # ←追加

 certbot-auto を実行すると、ここでも Homebrew を使えと言われた。そこでOSに依存しないインストールと言うのをやってみる。

$ ./certbot-auto --verbose --no-bootstrap
Creating virtual environment...
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in /opt/eff.org/certbot/venv/bin/python
Installing setuptools, pip, wheel...
done.
Installing Python packages...
〜略〜
Requirement already satisfied: setuptools>=1.0 in /opt/eff.org/certbot/venv/lib/python2.7/site-packages (from josepy==1.1.0->-r /tmp/le.rAnHOgVU/letsencrypt-auto-requirements.txt (line 95)) (40.6.3)
Installing collected packages: argparse, pycparser, asn1crypto, cffi, ConfigArgParse, six, configobj, idna, enum34, ipaddress, cryptography, funcsigs, pyOpenSSL, josepy, linecache2, pbr, mock, ordereddict, pyparsing, packaging, parsedatetime, pytz, pyRFC3339, python-augeas, chardet, certifi, urllib3, requests, traceback2, unittest2, zope.interface, zope.event, zope.component, requests-toolbelt, acme, certbot, letsencrypt, certbot-apache, certbot-nginx
  Running setup.py install for pycparser ... done
  Running setup.py install for cffi ... done
  Running setup.py install for ConfigArgParse ... done
  Running setup.py install for configobj ... done
  Running setup.py install for enum34 ... done
  Running setup.py install for cryptography ... done
  Running setup.py install for ordereddict ... done
  Running setup.py install for python-augeas ... done
  Running setup.py install for zope.interface ... done
  Running setup.py install for zope.event ... done
  Running setup.py install for zope.component ... done
Successfully installed ConfigArgParse-0.12.0 acme-0.30.0 argparse-1.4.0 asn1crypto-0.22.0 certbot-0.30.0 certbot-apache-0.30.0 certbot-nginx-0.30.0 certifi-2017.4.17 cffi-1.11.5 chardet-3.0.2 configobj-5.0.6 cryptography-2.2.2 enum34-1.1.2 funcsigs-1.0.2 idna-2.5 ipaddress-1.0.16 josepy-1.1.0 letsencrypt-0.7.0 linecache2-1.0.0 mock-1.3.0 ordereddict-1.1 packaging-16.8 parsedatetime-2.1 pbr-1.8.1 pyOpenSSL-16.2.0 pyRFC3339-1.0 pycparser-2.14 pyparsing-2.1.8 python-augeas-0.5.0 pytz-2015.7 requests-2.20.0 requests-toolbelt-0.8.0 six-1.10.0 traceback2-1.4.0 unittest2-1.1.0 urllib3-1.24.1 zope.component-4.2.2 zope.event-4.1.0 zope.interface-4.1.3
Installation succeeded.
Root logging level set at 10
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requested authenticator None and installer None
No installation (PluginEntryPoint#apache): Problem in Augeas installation
Traceback (most recent call last):
  File "/opt/eff.org/certbot/venv/lib/python2.7/site-packages/certbot/plugins/disco.py", line 132, in prepare
    self._initialized.prepare()
  File "/opt/eff.org/certbot/venv/lib/python2.7/site-packages/certbot_apache/configurator.py", line 227, in prepare
    raise errors.NoInstallationError("Problem in Augeas installation")
NoInstallationError: Problem in Augeas installation
No installation (PluginEntryPoint#nginx): Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.
Traceback (most recent call last):
  File "/opt/eff.org/certbot/venv/lib/python2.7/site-packages/certbot/plugins/disco.py", line 132, in prepare
    self._initialized.prepare()
  File "/opt/eff.org/certbot/venv/lib/python2.7/site-packages/certbot_nginx/configurator.py", line 145, in prepare
    "Could not find a usable 'nginx' binary. Ensure nginx exists, "
NoInstallationError: Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.
No candidate plugin
Selected authenticator None and installer None
Certbot doesn't know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run "certbot-auto certonly" to do so. You'll need to manually configure your web server to use the resulting certificate.

何やらエラーが出ている(Webサーバ(Apache, Nginx)のプラグインをインストールしようとして失敗している感じ)が、一応Certbotクライアントのインストールは成功している様子(↓)。

$ sudo ./certbot-auto --debug --os-packages-only
OS packages installed.
$ ls -l /opt/eff.org/certbot/venv/bin/
-rw-r--r--   1 root  wheel  2101  1 20 20:40 activate
-rw-r--r--   1 root  wheel  1111  1 20 20:40 activate.csh
-rw-r--r--   1 root  wheel  3057  1 20 20:40 activate.fish
-rw-r--r--   1 root  wheel  1540  1 20 20:40 activate.ps1
-rw-r--r--   1 root  wheel  1512  1 20 20:40 activate_this.py
-rwxr-xr-x   1 root  wheel   235  1 20 20:45 certbot
-rwxr-xr-x   1 root  wheel   245  1 20 20:44 chardetect
-rwxr-xr-x   1 root  wheel   254  1 20 20:40 easy_install
-rwxr-xr-x   1 root  wheel   254  1 20 20:40 easy_install-2.7
-rwxr-xr-x   1 root  wheel   235  1 20 20:44 jws
-rwxr-xr-x   1 root  wheel   235  1 20 20:45 letsencrypt
-rwxr-xr-x   1 root  wheel   235  1 20 20:44 pbr
-rwxr-xr-x   1 root  wheel   236  1 20 20:40 pip
-rwxr-xr-x   1 root  wheel   236  1 20 20:40 pip2
-rwxr-xr-x   1 root  wheel   236  1 20 20:40 pip2.7
-rwxr-xr-x   1 root  wheel  9132  1 20 20:40 python
-rwxr-xr-x   1 root  wheel  2343  1 20 20:40 python-config
lrwxr-xr-x   1 root  wheel     6  1 20 20:40 python2 -> python
lrwxr-xr-x   1 root  wheel     6  1 20 20:40 python2.7 -> python
-rwxr-xr-x   1 root  wheel   243  1 20 20:45 unit2
-rwxr-xr-x   1 root  wheel   232  1 20 20:40 wheel

3. マニュアル操作でドメイン証明書を取得

 Python仮想環境に Certbotクライアントをインストールできた。この仮想環境に切り替えて certbotコマンド使えば良いのかと思ったが、証明書を発行してもらったり更新したりするのには、引き続き"certbot-auto"を使用すれば良いようだ。そのため、"certbot-auto"はパスの通ったディレクトリ("/usr/local/bin"等)にコピーしておいた方が良いだろう。
 とにかく今はドメイン証明書を発行してもらおう。証明書の取得方法にも色々あって、Webサーバが動作していて CertbotのWebrootプラグインが入っている場合(--webroot)や、Webサーバが動作していない環境でCertbotクライアントが持っている簡易Webサーバ機能を使う場合(--standalone)などある。しかし、CertbotのWebrootプラグインはインストールが失敗しとるし、Webサーバを一旦止めてWebサーバが動作していない環境で取得すると、今後の証明書更新の度にWebサーバを止めねばならなくなるようだ。そのため、ここでは全部手動(--manual)で証明書を取得する。(以下の赤枠内は自分が適当に訳したもので実際には出力されない。また、Webサーバのポート80, 443が開いていること、PROXY経由の場合は http_proxy, https_proxy環境変数を設定しておく必要がある。)

$ ./certbot-auto certonly --manual -d y-naito.ddo.jp
Requesting to rerun ./certbot-auto with root privileges...
WARNING: unable to check for updates.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): mail-address@xxxx.yyy.ne.jp ←メールアドレスを入力

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory

以下の利用規約(Terms of Service)をお読みください。
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf
ACMEサーバー https://acme-v02.api.letsencrypt.org/directory に登録するため、同意していただく必要があります。
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A ←ここは必ずA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom.
あなたの電子メールアドレスを、Electronic Frontier財団、Let's Encryptプロジェクトの創設パートナー、およびCertbotを開発している非営利団体と共有しても良いでしょうか?
私達は Webの暗号化、EFFニュース、キャンペーン、およびデジタルの自由をサポートする方法と言った私達の活動についてあなたに電子メールを送りたいと思います。
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for y-naito.ddo.jp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that.
注意:このマシンのIPは、この証明書を要求したものとして公に記録されることになります。
もしあなたのサーバーではないマシン上でcertbotを手動モードで実行している場合は、それでも問題がないことを確認してください。
Are you OK with your IP being logged?
あなたのIPが記録されても良いですか?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y ←ここは必ずY - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create a file containing just this data: Wh*****-***********************************.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_xxxxx-xxxx (token(認証コード)) And make it available on your web server at this URL: http://y-naito.ddo.jp/.well-known/acme-challenge/Wh*****-*********************************** (認証ファイル名) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue

ここで、Enterキーの入力待ちになるので、もう一枚ターミナルの画面を開いて、

1) ディレクトリ"http://y-naito.ddo.jp/.well-known/acme-challenge"を作成

$ cd /usr/local/apache2/htdocs    # Apache2 の DocumentRoot 配下に移動
$ sudo mkdir .well-known
$ sudo mkdir .well-known/acme-challenge
$ sudo chown apache:www .well-known
$ sudo chown apache:www .well-known/acme-challenge

注)".well-known/acme-challenge"のオーナー、グループは自分のWebサーバーが参照できる適切なものに設定すること

2) ./well-known/acme-challenge/配下に認証ファイルを作成する

$ cd .well-known/acme-challenge
$ sudo echo "Wh*****-***********************************.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_xxxxx-xxxx" >Wh*****-***********************************
$ sudo chown apache:www Wh*****-***********************************

3) 最初のターミナル画面に戻ってEnterキーを押下

Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/y-naito.ddo.jp/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/y-naito.ddo.jp/privkey.pem
   Your cert will expire on 2019-04-20. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

このようなメッセージが表示されれば、証明書の発行・取得は成功したと思って良いだろう。
ちなみに、今回のように認証コードを発行して、それを認証局がWeb(HTTP)経由で確認することで認証する方式のことをhttp-01チャレンジ・レスポンス方式と呼ぶらしく、certbot-autoのマニュアル操作の場合はこの方式がデフォルトになっている。

4. 作成された証明書を確認

$ sudo ls -l /etc/letsencrypt/live/y-naito.ddo.jp
-rw-r--r--   1 root  wheel  692  1 20 19:55 README
lrwxr-xr-x   1 root  wheel   38  1 20 19:55 cert.pem -> ../../archive/y-naito.ddo.jp/cert1.pem
lrwxr-xr-x   1 root  wheel   39  1 20 19:55 chain.pem -> ../../archive/y-naito.ddo.jp/chain1.pem
lrwxr-xr-x   1 root  wheel   43  1 20 19:55 fullchain.pem -> ../../archive/y-naito.ddo.jp/fullchain1.pem
lrwxr-xr-x   1 root  wheel   41  1 20 19:55 privkey.pem -> ../../archive/y-naito.ddo.jp/privkey1.pem

無事に証明書が発行されて取得できたようだ。
fullchain.pem がサーバー証明書(厳密にはサーバー証明書(cert.pem)と中間CA証明書(chain.pem)を合わせたもの)
privkey.pem が秘密鍵である。


< 過去の記事 [ 1月の 全てのカテゴリ リスト ] 新しい記事 >

2019 calendar
1月
12345
6789101112
13141516171819
20212223242526
2728293031


掲示板
最新:08/15 17:19


GsBlog was developed by GUSTAV, Copyright(C) 2003, Web Application Factory All Rights Reserved.