Okada Hiroshi の blog

typo が多いです

ローカルで開発中のコンテンツも初期の段階から https (ssl) で配信する (その3) Let's Encrypt を使ってワイルドカード証明書を取得しました。

5. Let's Encrypt のクライアントソフト Certbot をインストールしました。

PPA を追加して certbot をインストールしました。

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt update
$ sudo apt install certbot

6. certbot を使って証明書を取得しました。

証明書を要求するために次のようなコマンドを入力しました。

sudo certbot certonly --manual --preferred-challenges=dns-01 --server=https://acme-v02.api.letsencrypt.org/directory --agree-tos -m okadahiroshi@mibox.jp -d '*.local.toycode.com'

すると以下のように表示されます。途中で Are you OK with your IP being logged? 「あなたのIPアドレスを記録しますがよろしいですか?」と聞かれるので y と答えました。

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 local.toycode.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.local.toycode.com with the following value:

1QjY1MdTuF1gjGmJexopl7N9DosUTaSyGz7gDCGlck0

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

ここで、DNS の TXT フィールドに貼り付ける認証用の文字列 が表示されました。

ここでもう一つ別なターミナルを開いて zone ファイル /etc/nsd/local.toycode.com.zone に TXT フィールドを加えました。 もちろん serial も増やしました。

$TTL 1m
local.toycode.com. IN SOA ns-local.toycode.com. postmaster.toycode.com. (
  2  ; serial
  5m ; refresh
  2m ; retry
  6h ; expire
  1m ; minimum
  )

@ IN NS ns-local.toycode.com.

ns-local IN A 35.199.184.64 

_acme-challenge.local.toycode.com. IN TXT "1QjY1MdTuF1gjGmJexopl7N9DosUTaSyGz7gDCGlck0"

a192-168-1-1 IN A 192.168.1.1
a192-168-1-2 IN A 192.168.1.2
以下略

/etc/nsd/local.toycode.com.zone を編集し終わったら、$ sudo nsd-control reloadで zone ファイルを読み込ませました。 そして、$ dig txt _acme-challenge.local.toycode.com +noedns +short"1QjY1MdTuF1gjGmJexopl7N9DosUTaSyGz7gDCGlck0" が返ってくることを確認しました。

zone ファイルの更新が終わったので、もとのターミナルに戻って、enter キーを押しました。すると

Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/local.toycode.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/local.toycode.com/privkey.pem
   Your cert will expire on 2019-04-15. 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"
 - 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

と表示され、/etc/letsencrypt/live/local.toycode.com/fullchain.pemドメインの証明書と中間認証局の証明書の連結されたものが、 /etc/letsencrypt/live/local.toycode.com/privkey.pem秘密鍵ファイルが保存されました。(実際にはこれらはシンボリックリンクで実体は別な場所に保管されています。)

なお上には表示されていませんが。/etc/letsencrypt/live/local.toycode.com/ ディレクトリには

ファイル名 内容
cert.pem ドメインの証明書
chain.pem 中間認証局の証明書
fullchain.pem ドメインの証明書と中間認証局の証明書の連結されたもの
privkey.pem 秘密鍵

の4個のファイルが保存されていました。

以上でワイルドカード証明書の取得ができました。