【脱オレオレ証明】Lest's EncryptでSSL証明書を取得してみた

オレオレ証明書のWebサイトにアクセスするたびに危険のあるWebサイト警告画面がうるさいのでLest's Encryptの証明書でその警告からおさらばしたいと思います。

参考にさせていただいた記事です。ありがとうございます。
qiita.com

証明書作成環境

- CentOS7.8

パッケージのインストール

# yum install certbot -y

証明書発行コマンドの実行

ドメイン名、Eメールは適当な文言にしています。適宜変更し実行してください。
実行コマンド:certbot certonly --manual --domain hogehoge.com --email hogehoge@example.jp --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns

# certbot certonly --manual --domain hogehoge.com --email hogehoge@example.jp --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns
email hogehoge@example.jp --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns
Use of --manual-public-ip-logging-ok is deprecated.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Requesting a certificate for hogehoge.com
Performing the following challenges:
dns-01 challenge for hogehoge.com

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

8kRbsero3l3o38B_PT864ZwNUEcXCm2x0gOy5tFpYVQ

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

実行コマンドを打鍵すると「Before continuing, verify the record is deployed.」で一旦止まります。
この状態で何もキーを実行しないでください。
その間に「hogehoge.com」の「TXT」レコードに「8kRbsero3l3o38B_PT864ZwNUEcXCm2x0gOy5tFpYVQ」を設定する。
f:id:kyamisama:20210201110033j:plain

「TXT」レコードの反映が完了したら止まっていた「Before continuing, verify the record is deployed.」からエンターを実行する。
「TXT」レコード反映は下記コマンドで確認する。

$ dig -t txt _acme-challenge.hogehoge.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.3 <<>> -t txt _acme-challenge.hogehoge.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60439
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1372
;; QUESTION SECTION:
;_acme-challenge.hogehoge.com. IN TXT

;; ANSWER SECTION:
_acme-challenge.hogehoge.com. 30 IN TXT "NPRp4OkoUrFVQHLKO6WP8EFvF**************"

;; Query time: 219 msec
;; SERVER: 169.***.***.***#53(169.***.***.***)
;; WHEN: Fri Feb 05 11:08:12 JST 2021
;; MSG SIZE  rcvd: 122
# certbot certonly --manual --domain hogehoge.com --email hogehoge@example.jp --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns
email hogehoge@example.jp --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns
Use of --manual-public-ip-logging-ok is deprecated.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Requesting a certificate for hogehoge.com
Performing the following challenges:
dns-01 challenge for hogehoge.com

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

8kRbsero3l3o38B_PT864ZwNUEcXCm2x0gOy5tFpYVQ

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ★先ほどの続きでここでエンター実行
Press Enter to Continue
Waiting for verification...
Cleaning up challenges
Use of --manual-public-ip-logging-ok is deprecated.

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/hogehoge.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/hogehoge.com/privkey.pem
   Your certificate will expire on 2021-05-01. 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

[root@localhost ~]#

取得した証明書を確認してみる

全部で5つのファイルが作成されているはずです。
これで証明書作成は完了です。

# ls /etc/letsencrypt/live/hogehoge.com/
README  cert.pem  chain.pem  fullchain.pem  privkey.pem
#

おまけ

WindowsIISようにPFX形式の証明書を作成します。

# openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out auth.pfx
Enter Export Password:
Verifying - Enter Export Password:
#