Raspberry Pi 2 Model BでLet's Encrypt!
2015年12月3日からLet's EncryptがPublic Betaとなったので早速ラズベリーパイで試してみました。
細かい説明は色々な方々がされているので、細かい説明は省いて発行までの流れをサラッと書きます。
目次
- Let's Encryptとは
- 前準備
- letsencryptをclone
- virtual envの準備
- 証明書発行
- 発行確認
- 更新時
- 失効
- 終わりに・感想
Let's Encryptとは
Let's Encrypt letsencrypt.org
- SSLサーバ証明書を無料で手軽に発行できるようにし、世の中の通信のSSL/TLS化を促進させるためのプロジェクト
- 従来は発行自体の作業が面倒くさい、お金がかかるという問題があった(有料・数分〜数十分、色々な操作)
- CSR作成、証明書発行、サーバへの設置などの手間を省き全てコマンドベースで作業が完了する(無料・数秒)
- コモンネームにワイルドカードは使えない
- 認証方法はDVのみ
- いくつもサブドメイン切って発行していたら
An unexpected error occurred: There were too many requests of a given type :: Error creating new cert
なるエラーが。。ドメインごとに発行できる枚数に制限があるらしい・・・。発行済の証明書をrevokeして破棄してもダメだった。もしかしたら時間あたりの発行数制限なのかもしれない。
前準備
- http://FQDN でアクセスできるように、DNSやルータ、ファイヤーウォール等の設定を行っておく
- そのうえで、サーバでapacheやnginxなどが動いていて80/TCPをLISTENしている場合は切っておく。【追記】
--webroot -w /var/www/example/
みたいなオプションを指定すれば既存のサーバ上で動く
let's encryptは証明書発行でDV認証を行います。その際のFQDNの所有確認として、HTTPサーバを立ててhttp://FQDNにアクセスすることでドメインの所有者である事を確認するので、すでにHTTPサーバがたっていると競合しエラーとなるため切っておく必要があります。
letsencryptをclone
さっそくletsencryptをインストールしていきます。
コマンド
$ mkdir git_repo $ cd git_repo $ git clone https://github.com/letsencrypt/letsencrypt $ cd letsencrypt/
実行結果
le-user@raspberrypi03 ~ $ mkdir git_repo && cd git_repo le-user@raspberrypi03 ~/git_repo $ git clone https://github.com/letsencrypt/letsencrypt Cloning into 'letsencrypt'... remote: Counting objects: 25257, done. remote: Compressing objects: 100% (30/30), done. remote: Total 25257 (delta 8), reused 0 (delta 0), pack-reused 25227 Receiving objects: 100% (25257/25257), 6.63 MiB | 1.48 MiB/s, done. Resolving deltas: 100% (17699/17699), done. le-user@raspberrypi03 ~/git_repo $ cd letsencrypt/ le-user@raspberrypi03 ~/git_repo/letsencrypt $
virtual envの準備
コマンド
$ virtualenv --no-site-packages -p python2 venv $ ./venv/bin/pip install -r readthedocs.org.requirements.txt acme/ .
実行結果
le-user@raspberrypi03 ~/git_repo/letsencrypt $ virtualenv --no-site-packages -p python2 venv Running virtualenv with interpreter /usr/bin/python2 The --no-site-packages flag is deprecated; it is now the default behavior. New python executable in venv/bin/python2 Also creating executable in venv/bin/python Installing distribute.............................................................................................................................................................................................done. Installing pip...............done. le-user@raspberrypi03 ~/git_repo/letsencrypt $ ./venv/bin/pip install -r readthedocs.org.requirements.txt acme/ . --editable=.[docs] should be formatted with svn+URL, git+URL, hg+URL or bzr+URL Storing complete log in /home/le-user/.pip/pip.log
証明書発行
コマンド
$ ./letsencrypt-auto --email <メールアドレス> \ --domains <証明書コモンネーム> \ --domains <証明書コモンネーム2> \ --authenticator standalone \ --server https://acme-v01.api.letsencrypt.org/directory \ auth
実行結果
le-user@raspberrypi03 ~/git_repo/letsencrypt $ ./letsencrypt-auto --email <メールアドレス> --domains le-test.dothoshirc.com --authenticator standalone --server https://acme-v01.api.letsencrypt.org/directory auth Bootstrapping dependencies for Debian-based OSes... Hit http://mirrordirector.raspbian.org wheezy Release.gpg Hit http://raspberrypi.collabora.com wheezy Release.gpg Hit http://archive.raspberrypi.org wheezy Release.gpg Hit http://mirrordirector.raspbian.org wheezy Release Hit http://raspberrypi.collabora.com wheezy Release Hit http://archive.raspberrypi.org wheezy Release Hit http://mirrordirector.raspbian.org wheezy/main armhf Packages Hit http://raspberrypi.collabora.com wheezy/rpi armhf Packages Hit http://archive.raspberrypi.org wheezy/main armhf Packages Hit http://mirrordirector.raspbian.org wheezy/contrib armhf Packages Hit http://mirrordirector.raspbian.org wheezy/non-free armhf Packages Hit http://mirrordirector.raspbian.org wheezy/rpi armhf Packages Ign http://raspberrypi.collabora.com wheezy/rpi Translation-en_GB Ign http://raspberrypi.collabora.com wheezy/rpi Translation-en Ign http://archive.raspberrypi.org wheezy/main Translation-en_GB Ign http://archive.raspberrypi.org wheezy/main Translation-en Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en_GB Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en Ign http://mirrordirector.raspbian.org wheezy/main Translation-en_GB Ign http://mirrordirector.raspbian.org wheezy/main Translation-en Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en_GB Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en_GB Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en Reading package lists... Done E: No packages found Reading package lists... Done Building dependency tree Reading state information... Done ca-certificates is already the newest version. dialog is already the newest version. gcc is already the newest version. git is already the newest version. libaugeas0 is already the newest version. libffi-dev is already the newest version. libssl-dev is already the newest version. python is already the newest version. python-dev is already the newest version. python-virtualenv is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded. Creating virtual environment... Updating letsencrypt and virtual environment dependencies...../home/le-user/.local/share/letsencrypt/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning ./home/le-user/.local/share/letsencrypt/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning . Running with virtualenv: sudo /home/le-user/.local/share/letsencrypt/bin/letsencrypt --email <メールアドレス> --domains le-test.dothoshirc.com --authenticator standalone --server https://acme-v01.api.letsencrypt.org/directory auth
Running with virtualenv:〜〜って出てるので再トライ
$ sudo /home/le-user/.local/share/letsencrypt/bin/letsencrypt --email <メールアドレス> --domains le-test.dothoshirc.com --authenticator standalone --server https://acme-v01.api.letsencrypt.org/directory auth
なお、すでにHTTPサーバがたっていると以下のようなエラーを吐きます
発行確認
無事発行できました。
/etc/letsencrypt/live/
以下にCommonNameのディレクトリが作成されてそこに各種ファイルが保存されます。
le-user@raspberrypi03 ~/git_repo/letsencrypt $ sudo ls /etc/letsencrypt/live/le-test.dothoshirc.com cert.pem chain.pem fullchain.pem privkey.pem
それぞれ以下の通りです。
- cert.pem 証明書
- chain.pem 中間証明書
- fullchain.pem 証明書 + 中間証明書
- privkey.pem 秘密鍵
nginxの場合はconfigの ssl_certificate でfullchain.pemを指定してください。
更新時
更新時は更新用のオプションを追加して以下のコマンドを叩けば更新されます。
コマンド
$ ./letsencrypt-auto --renew-by-default --email <メールアドレス> --domains <FQDN> --authenticator standalone --server https://acme-v01.api.letsencrypt.org/directory auth
実行結果
le-user@raspberrypi03 ~/git_repo/letsencrypt $ ./letsencrypt-auto --renew-by-default --email <メールアドレス> --domains le-test.dothoshirc.com --authenticator standalone --server https://acme-v01.api.letsencrypt.org/directory auth Updating letsencrypt and virtual environment dependencies....... Running with virtualenv: sudo /home/le-user/.local/share/letsencrypt/bin/letsencrypt --renew-by-default --email <メールアドレス> --domains le-test.dothoshirc.com --authenticator standalone --server https://acme-v01.api.letsencrypt.org/directory auth Failed authorization procedure. le-test.dothoshirc.com (tls-sni-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Correct zName not found for TLS SNI challenge. Found le-test.dothoshirc.com IMPORTANT NOTES: - The following 'urn:acme:error:unauthorized' errors were reported by the server: Domains: le-test.dothoshirc.com Error: The client lacks sufficient authorization le-user@raspberrypi03 ~/git_repo/letsencrypt $
Running with virtualenv: 〜〜〜って出てるので言われた通りに再トライ
$ sudo /home/le-user/.local/share/letsencrypt/bin/letsencrypt --renew-by-default --email <メールアドレス> --domains le-test.dothoshirc.com --authenticator standalone --server https://acme-v01.api.letsencrypt.org/directory auth
失効
コマンド
$ ./letsencrypt-auto revoke --cert-path /etc/letsencrypt/live/<コモンネーム>/cert.pem
もとい
$ sudo /home/le-user/.local/share/letsencrypt/bin/letsencrypt --cert-path /etc/letsencrypt/live/<コモンネーム>/cert.pem
終わりに・感想
便利。個人利用やちょっとした利用だったらどんどん使いたい。
企業サイトや信頼性が重視されるサービス等での利用は一考したほうが良い。提供するサービスのサービスポリシー的に問題ないのであれば良いと思う。
カバレッジは未調査だが基本的にメジャーなブラウザ・スマートフォンデバイスでは問題なく利用できるはず。