前準備
ドメインについて
| 対象ドメイン名 | hoge.ml | 
|---|---|
| フリードメインを取得→このあたりして、Route53に設定しておく。 | |
| 無料でかつ、お手軽な割に長期間特に問題なく使えているので良い。 | 
証明書設定方法の調査
EC2にOpenVPNサーバに証明書を入れようとして、久々にLet's Encriptを調査
以前はサブドメインまで指定して、開けたくもない80番ポートを開けてやった記憶があるが
もうちょっとスマートにできないものか。。
が課題。
1、DNS認証ができそう
  証明書発行者は、「Route53にTXTレコードを設定することでドメイン保有者だと確認できる。」
  という意味なので、非常に良い。この方式を使う
2、ワイルドカードができるようになった様子
  !!!!いちいちサブドメイン単位で作らなくてもよい!!!!
  どうせ、ぁゃしぃ証明書だし楽であることに越したことはない
やってみた
Ubuntu 16.04
certbotを入れる
git clone https://github.com/certbot/certbot
cd certbot
certbotを実行
sudo ./certbot-auto certonly --manual --domain *.hoge.ml --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
| パラメータ | 内容 | 
|---|---|
| certonly | SSL/TLS サーバ証明書の取得のみを行う | 
| --manual | ドメイン名の認証を手動で行う | 
| --domain *.hoge.ml | 対象ドメイン名。今回はワイルドカードなので *.hoge.ml | 
| --preferred-challenges dns-01 | 認証方法の選択:dns-01 DNSのTXTレコードによる確認 | 
| --server https://acme-v02.api.letsencrypt.org/directory | Certbotの認証サーバをワイルドカード対応のサーバに変える | 
何やら出てくるので、メアドを入れて、License Agreement をAgree(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.
翻訳:お前ら英語わからないだろう?だったらとりあえずYESにしときなよ(嘘)
→お断りします。NOにした。
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?
このマシンのIPは、要求したものとして公開されますがOK?
→DHCPだしOKとする
_acme-challenge.hoge.ml with the following value:
OaHOGEHOGE4RRfHOGE0ao3PQmkHogEoHoGEzPgCWrVYI
DNSのTXTレコードにこうやって書け!が出てくる。
おそらくDNS書き換えは即反映するので、処理は止めておく。
Route53でレコードを作る
続き
Enterを押して進める
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/hoge.ml/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/hoge.ml/privkey.pem
   Your cert will expire on 2018-09-19. 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
/etc/letsencrypt/live/hoge.ml/
このあたりに保存されてます的な感じです
# ls -l /etc/letsencrypt/live/hoge.ml
total 8
-rw-r--r-- 1 root root 2139 Jun 21 06:34 cert1.pem
lrwxrwxrwx 1 root root   31 Jun 21 06:11 cert.pem -> ../../archive/hoge.ml/cert1.pem
lrwxrwxrwx 1 root root   32 Jun 21 06:11 chain.pem -> ../../archive/hoge.ml/chain1.pem
lrwxrwxrwx 1 root root   36 Jun 21 06:11 fullchain.pem -> ../../archive/hoge.ml/fullchain1.pem
lrwxrwxrwx 1 root root   34 Jun 21 06:11 privkey.pem -> ../../archive/hoge.ml/privkey1.pem
-rw-r--r-- 1 root root  682 Jun 21 06:11 README
証明書の更新
3か月で切れるが、メールで教えてくれるので都度下記コマンド実施でよいと思われる
./certbot-auto renew
まとめ
下手に自己証明書を作るよりは全然良い
