Let’s EncryptでSSLサーバ証明書を取得

OS: Ubuntu 18.04.1 LTS
Apache 2.4.34
certbot 0.23.0-1

HTTPによる通信の暗号化をせっせと進めてゆこうという世論の高まりにおされてLet’s Encryptが発行する無料のSSLサーバ証明書の取得を試みるものである。

SSLサーバ証明書の発行にはACME(Automated Certificate Management Environment) clientであるCertbotというツールがLet’s Encryptによって薦められているようである。

図1. certbot

CertbotはGitHubからも取得できるけれども、Ubuntu Server 18.04.1にはcertbotパッケージが用意されているから此れを用いる。

$ sudo apt install certbot

多数のpythonパッケージを巻き添えにcertbotがインストールされる。そうしたら早速certbotの実行をする。サブコマンドはデフォルトで run が指定されて、此れは証明書の取得からインストールまでこなしてくれる。けれども一先ず証明書だけ取得したいから certonly を指定した。

--webroot--webroot-pathwebrootプラグインで以って証明書を発行するという注文である。--webroot-pathで指定したパスに一時ファイルが作成され、此れをLet’s Encryptが検証の為にアクセスするからくりのようである。

あとは--emailでメールアドレスを、--domainでCommon Nameを指定してコマンドを実行するばかりであるけれども最初は如何な落ち度が潜んでいるか知れないから --dry-runを追加してテストをした。

$ sudo certbot certonly --webroot --webroot-path /home/guro/public_html/ --email www7390uo@gmail.com --domain www7390uo.sakura.ne.jp --dry-run

IMPORTANT NOTES:
 - The dry run was successful.

問題が無いようであれば--dry-runを外して実行する。最初はサービスの利用規約に同意するか否かを問われる。常に合意する心持ちがあれば --agree-tos オプションで以ってこの問いかけをスキップできるようである。

$ sudo certbot certonly --webroot --webroot-path /home/guro/public_html/ --email www7390uo@gmail.com --domian www7390uo.sakura.ne.jp
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel:

次は登録するメールアドレスをElectronic Frontier Foundation(EFF、電子フロンティア財団)と分かち合って良いか尋ねられる。分かち合えば登録したメールアドレス宛にEFFからのニュースやキャンペーンの報せが届くという。

図2. EFF

Let’s Encryptプロジェクトの共同創設者でありCertbotを開発する非営利組織たるEFFからのお誘いであるけれどもNoと返答した。これは --no-eff-email オプションで予めNoを突きつけることができるし --eff-email オプションでYesと答える手間を省ける。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:

するとこうである。証明書の発行数制限に抵触した模様であってこうなるとどうも為す術がない。ドメインあたり週に50までと云う規制が課されているから今週分の注文については一足遅かったようである。なんて日だとおもう。

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www7390uo.sakura.ne.jp
Using the webroot path /home/guro/public_html for all unmatched domains.
Waiting for verification...
Cleaning up challenges
An unexpected error occurred:
There were too many requests of a given type :: Error finalizing order :: too many certificates already issued for: sakura.ne.jp: see https://letsencrypt.org/docs/rate-limits/
Please see the logfiles in /var/log/letsencrypt for more details.

翌週までじっと堪えてから改めてコマンドを実行するとまだ発行数の上限には達していなかったものと見られ、恙無く証明書が発行された。証明書と中間証明書が一体になったfullchain.pemと秘密鍵privkey.pemだけでなく証明書単体cert.pemと中間証明書単体chain.pemも併せて/etc/letsencrypt/archive/www7390uo.sakura.ne.jpディレクトリに作成されるからサーバの環境に合わせて用いると良さそうな風情である。

$ sudo certbot certonly --webroot --webroot-path /home/guro/public_html/ --email www7390uo@gmail.com --domian www7390uo.sakura.ne.jp
(snip)
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www7390uo.sakura.ne.jp/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www7390uo.sakura.ne.jp/privkey.pem
   Your cert will expire on 2019-01-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew" 

証明書の内容を覗いてみればこうである。有効期限は90日間であるから期限切れの前に更新する段取りを立てておく必要がある。

# openssl x509 -text -in /etc/letsencrypt/live/www7390uo.sakura.ne.jp/cert.pem
Certificate:
(snip)
        Issuer: C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3
        Validity
            Not Before: Oct 15 16:41:16 2018 GMT
            Not After : Jan 13 16:41:16 2019 GMT
        Subject: CN=www7390uo.sakura.ne.jp
(snip)

なおアクセスログを眺めていると証明書発行の申請時にLet’s Encrypt validation serverからアクセスがあって /.well-known/acme-challenge/ 内に生成された一時ファイルを読み取っている模様である。

Let’s Encrypt validation serverには13.58.30.69、34.213.106.112、52.29.173.72、66.133.109.36の少なくとも4つIPアドレスがあった。これらの接続を妨げないようファイアウォールやWebサーバの設定をよしなに改める必要があるけれどもIPアドレスは変更される可能性もあるから油断ならない。

$ tail -f /usr/local/apache2/logs/access_log.guro
66.133.109.36 - - [13/Oct/2018:15:23:28 +0900] "GET /.well-known/acme-challenge/ab4cOkLSd034tdoxftVHDpgrLVsC4oz5N_8H5ySX7_3 HTTP/1.1" 200 87 "-" "Mozilla/5.0 (compatible; Let's Encrypt validation server; +https://www.letsencrypt.org)" 267 361

コメントする

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください