Cerbot使ってますか?めっちゃ使いますよね。手軽なHTTPS通信には不可欠です。
なんと、CertBotがワイルドカード対応ですって。ツイートは2018-05-02だから半年前には対応してた模様。知らんかった。最近は情報密度薄くて、こういう情報を手に入れるのが難しくて困る。
該当のツイート
早速やってみる。
Certbot最新版しか対応してないので、debなどのパッケージでは追いつけない。んあのでgithub から最新版のCertbotを持ってくる。
git clone https://github.com/certbot/certbot.git
cd certbot
そのうち最新版がLinuxディストリから配布されるとは思いますが、いまはgithubからダウンロード。
発行してみる。
手順は、通常のCertbotとほとんど同じです。
./certbot-auto \
certonly \
--manual \
-d example.com \
-d \*.example.com \
--agree-tos --manual-public-ip-logging-ok \
--preferred-challenges dns-01 \
--server https://acme-v02.api.letsencrypt.org/directory
コレを実行するとドメインの所有者確認をTXTレコードで要求される。
dns-01 からの指令が来る
_acme-challenge サブドメインのTXTレコードを書き換えてくださいねって。
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:
yAXjSm2yF1n-9ZHlWWTQ-PFP_PHvI6Yy6YzpHqitKeQ
Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to ContinueCleaning up challenges
TXTレコード登録のためにDNSを書き換えに行く。
DNSサーバーに書き換えに言ってあとは結果待ち
ちょっと待ってれば、すぐに終わる。
Press Enter to Continue
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
Your cert will expire on 2019-01-23. 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
http サーバに組み込んで通信する。
うおーーーやったね。
あこがれのワイルドカード証明書だ。一度は使ってみたかったワイルドカード証明書。
しかもタダって良いんですかね。LetsEncryptには感謝です。
発行時の注意
ワイルドカード証明書なので
*.example.com
で発行した場合 aaa.example.com
はワイルドカード対象になるんだが、 サブドメインなしの example.com
は対象にならない。
当たり前と言っちゃ当たり前なのですが、証明書エラーを出したのは私です。
なので、発行する場合は、ドメイン指定を使って、次のようにしました。
-d example.com \
-d \*.example.com \
これで、1枚の証明書で、example.com と、*.example.com のどちらも使える証明書になる。サブドメインのサブドメインなども同じなると思う。
すでにドメインの証明書を持っている場合。
すでに発行済であれば、発行済のドメインの証明書をrevoke すると良い。
./certbot-auto revoke --cert-path=/etc/letsencrypt/live/example.com/cert.pem
または削除コマンドで削除する。
削除する
./certbot-auto delete
これで、新規で証明書を作れるようになるのでめでたし。
参考資料
Let's Encrypt (certbot) でワイルドカード証明書できた!