LoginSignup
5
8

More than 5 years have passed since last update.

Let's Encrypt で acme.sh を使って ACME v2 でワイルドカード証明書を取得する

Last updated at Posted at 2018-03-29

ググると日本語の記事もいくつも出てきて、最新のだと 1 ヶ月ほど前の記事(2018年2月末とかの記事)なので倣ってやってみたらうまくいきませんでした。この記事もすぐに古くなる可能性があります。

最初、普段使っている getssl.sh でやろうとしたけど、まだワイルドカード証明書に対応してないらしくしばらくハマってました(ACME v2 には対応済み)。

acme.sh というのが対応してるらしいので、こちらで(certbot は嫌いw)。

curl https://get.acme.sh | sh

でインストール。ぐぐってやってみたけど、今はマニュアルでの DNS 経由の取得だと --yes-I-know-dns-manual-mode-enough-go-ahead-please というオプションが必要な模様(先月の記事をみる限りは不要だったみたいなのですぐ変わってるかも)。

まずはテストで staging で発行。

$ acme.sh --test --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please --issue -d *.hoge.example.com
  : (snip)
[2018年  3月 29日 木曜日 20:39:29 JST] Add the following TXT record:
[2018年  3月 29日 木曜日 20:39:29 JST] Domain: '_acme-challenge.hoge.example.com'
[2018年  3月 29日 木曜日 20:39:29 JST] TXT value: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  : (snip)

このレコードを DNS サーバに追加します(ここは手動です。手順は省略)。ここだと _acme-challenge.hoge.example.com の TXT レコードの値を XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX に設定します。


$ dig _acme-challenge.hoge.example.com txt
  : (snip)
;; ANSWER SECTION:
_acme-challenge.hoge.example.com. 86008 IN TXT "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

  : (snip)

これを確認してから、-renew で発行します。

$ acme.sh --yes-I-know-dns-manual-mode-enough-go-ahead-please --renew -d *.hoge.example.com
[2018年  3月 29日 木曜日 20:40:34 JST] Renew: '*.hoge.example.com'
[2018年  3月 29日 木曜日 20:40:36 JST] Single domain='*.hoge.example.com'
[2018年  3月 29日 木曜日 20:40:36 JST] Getting domain auth token for each domain
[2018年  3月 29日 木曜日 20:40:36 JST] Verifying:*.hoge.example.com
[2018年  3月 29日 木曜日 20:40:40 JST] Success
[2018年  3月 29日 木曜日 20:40:40 JST] Verify finished, start to sign.
[2018年  3月 29日 木曜日 20:40:42 JST] Cert success.
  : (snip)
[2018年  3月 29日 木曜日 20:40:42 JST] Your cert is in  /home/hoge/.acme.sh/*.hoge.example.com/*.hoge.example.com.cer 
[2018年  3月 29日 木曜日 20:40:42 JST] Your cert key is in  /home/hoge/.acme.sh/*.hoge.example.com/*.hoge.example.com.key 
[2018年  3月 29日 木曜日 20:40:42 JST] The intermediate CA cert is in  /home/hoge/.acme.sh/*.hoge.example.com/ca.cer 
[2018年  3月 29日 木曜日 20:40:42 JST] And the full chain certs is there:  /home/hoge/.acme.sh/*.hoge.example.com/fullchain.cer 
  : (snip)

これで取得できました。で、なぜか軒並み日本語でひっかかる記事はここで終わってるんだけど、これで発行されるのは "Face LE Intermediate X1" とかいうちゃんと使えない Staging の CA 発行の証明書です。なのでちゃんと使おうと思うと、正式なやつを production 環境(っていうのかな?)から取得する必要があります。

Staging で発行していても、Let's 側では発行済とマークされているっぽいので、--force をつけて強制再発行します。

$ acme.sh --force --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please --issue -d *.hoge.example.com
(DNS設定したあと)
$ acme.sh --force --yes-I-know-dns-manual-mode-enough-go-ahead-please --renew -d *.hoge.example.com

これで Issuer が Issuer: C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3 となった正式な証明書が発行されました。

5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8