2018年8月11日土曜日

Mac の certbot を使って証明書を取得する (with DNS challenge)

概要

過去に Ubuntu で証明書を取得してみました
今回は Mac の certbot を使って証明書を取得してみました
また、認証の方式を DNS サーバを使った方式にしてみました

環境

  • macOS 10.13.6
  • certbot 0.26.1
  • DNS サービス (お名前.com のドメイン Navi 2018/08/07 時点)

certbot のインストール

  • brew install certbot

証明書発行依頼

  • sudo certbot certonly --manual --preferred-challenges=dns -d your-site-domain.com -m user1@your-site-domain.com

--manual --preferred-challenges=dns とすることで DNS のテキストレコード認証にすることができます
ドメインおよび連絡用のメールアドレスを指定して実行します

また Mac の場合 sudo 権限が必要になります

内容確認

いろいろと確認されます

  • 規約に同意する
  • メールアドレスの流用はやめていただく
  • certbot を実行しているサーバの IP のロギングを許可する

という感じです

Saving debug log to /var/log/letsencrypt/letsencrypt.log  
Plugins selected: Authenticator manual, 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: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: N
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for your-site-domain.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.your-site-domain.com with the following value:

sngcfRCi5xgy_neCo6kCR4T4k-fVt_6EYdCu2v_fnhk

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

最後に表示された TXT レコードの情報を DNS サーバに登録します

DNS にテキストレコード追加

今回はお名前.com のドメイン Navi に対してテキストレコードを追加します
当然 DNS プロバイダに応じて操作内容は異なるので注意してください
やりたいことは指定のテキストレコードを指定のサブドメインで追加することです

  • ホスト名・・・_acme-challenge.your-site-domain.com
  • TYPE・・・TXT
  • VALUE・・・sngcfRCi5xgy_neCo6kCR4T4k-fVt_6EYdCu2v_fnhk

dns_challenge1.png

こんな感じで入力して追加しましょう

レコード反映確認

5 分ほど待ってレコードが問題なく引けることを確認しましょう
以下のようなコマンドを実行して結果が返ってくれば OK です

  • dig -t txt _acme-challenge.your-site-domain.com

dig の結果の一部抜粋

;; ANSWER SECTION:
_acme-challenge.your-site-domain.com. 2371 IN TXT   "sngcfRCi5xgy_neCo6kCR4T4k-fVt_6EYdCu2v_fnhk"

証明書取得

あとは Enter を押して取得するだけです
問題なくレコードが引ければ必要なファイルが /etc/letsencrypt/live/your-site-domain.com に保存されています

Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/your-site-domain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/your-site-domain.com/privkey.pem
   Your cert will expire on 2018-11-06. 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"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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
  • sudo ls -1 /etc/letsencrypt/live/your-site-domain.com
README
cert.pem
chain.pem
fullchain.pem
privkey.pem

証明書の取得が完了したら DNS の設定した TXT レコードは削除してもらって大丈夫です

最後に

Mac に certbot をインストールして DNS 認証を使って証明書を取得してみました
サイトのルートディレクトリに指定のファイルを配置するよりかは簡単かなと思います

少し気になったのはメールアドレスです
DNS 認証の場合実はメールアドレスの指定は必須ではありません
今回は指定しましたが無くてもコマンドは通ります
もしかすると DNS 認証の場合指定のドメインの whois 情報から管理者のメールアドレスを算出して、そのアドレスに期限切れの連絡をしているのかもしれません
もしそうであれば whois 代行などを行っている場合は DNS プロバイダが提供するダミーのメールアドレスに連絡が行ってしまうため通知を受け取ることができません

なので今回は意図的にメールアドレスを指定しました
もしかするとそれでも通知が届かないかもしれません (指定はしたが結局 whois 側を参照している可能性があるということ)
この辺は 90 日後に期限切れになるのでわかったら追記しようかなと思います

参考サイト

0 件のコメント:

コメントを投稿