やりたいこと
GUIにちゃんとした証明書が欲しかった
参考にしたもの
参考というよりもズバリそのものです。
404になりませんように。
作業
ubnt-letsencrypt のインストール
EdgerouterのCUI上で行います。ワンライナーでGitすら使いません。
$ curl https://raw.githubusercontent.com/j-c-m/ubnt-letsencrypt/master/install.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 342 100 342 0 0 646 0 --:--:-- --:--:-- --:--:-- 646
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 216k 100 216k 0 0 389k 0 --:--:-- --:--:-- --:--:-- 389k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3479 100 3479 0 0 7001 0 --:--:-- --:--:-- --:--:-- 7014
何をしているか
install.sh
を見てみます。
#!/bin/bash
mkdir -p /config/.acme.sh /config/scripts
curl -o /config/.acme.sh/acme.sh https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh
curl -o /config/scripts/renew.acme.sh https://raw.githubusercontent.com/j-c-m/ubnt-letsencrypt/master/renew.acme.sh
chmod 755 /config/.acme.sh/acme.sh /config/scripts/renew.acme.sh
- ACMEクライアントのacme.shをACMEリポジトリから
/config/.acme.sh/acme.sh
に転送 -
ubnt-letsencrypt独自の更新用スクリプトを
/config/scripts/renew.acme.sh
に転送
acme.sh
、EdgeOSでもしっかり動くのすごい。
取得(更新)
これも sudo /config/scripts/renew.acme.sh -d ドメイン
だけです。複数のサブドメインがある場合は -d サブドメイン
の形で追記するようです。
$ sudo /config/scripts/renew.acme.sh -d ドメイン
[日付時刻] Stopping GUI service.
[日付時刻] Starting temporary ACME challenge service.
[日付時刻] Using CA: https://acme-v02.api.letsencrypt.org/directory
[日付時刻] Create account key ok.
[日付時刻] Registering account: https://acme-v02.api.letsencrypt.org/directory
[日付時刻] Registered
[日付時刻] ACCOUNT_THUMBPRINT='略'
[日付時刻] Creating domain key
[日付時刻] The domain key is here: /config/.acme.sh/ドメイン_ecc/ドメイン.key
[日付時刻] Single domain='ドメイン'
[日付時刻] Getting domain auth token for each domain
[日付時刻] Getting webroot for domain='ドメイン'
[日付時刻] Verifying: ドメイン
[日付時刻] Pending, The CA is processing your order, please just wait. (1/30)
[日付時刻] Success
[日付時刻] Verify finished, start to sign.
[日付時刻] Lets finalize the order.
[日付時刻] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/略'
[日付時刻] Downloading cert.
[日付時刻] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/略'
[日付時刻] Cert success.
-----BEGIN CERTIFICATE-----
略
-----END CERTIFICATE-----
[日付時刻] Your cert is in: /config/.acme.sh/ドメイン_ecc/ドメイン.cer
[日付時刻] Your cert key is in: /config/.acme.sh/ドメイン_ecc/ドメイン.key
[日付時刻] The intermediate CA cert is in: /config/.acme.sh/ドメイン_ecc/ca.cer
[日付時刻] And the full chain certs is there: /config/.acme.sh/ドメイン_ecc/fullchain.cer
[日付時刻] Run reload cmd: cat $CERT_PATH $CERT_KEY_PATH > /config/ssl/server.pem; cp $CA_CERT_PATH /config/ssl/ca.pem
[日付時刻] Reload success
[日付時刻] Stopping temporary ACME challenge service.
[日付時刻] Starting GUI service.
出来上がったもの
もの | 場所 |
---|---|
サーバー証明書 | /config/.acme.sh/ドメイン_ecc/ドメイン.cer |
秘密鍵 | /config/.acme.sh/ドメイン_ecc/ドメイン.key |
中間CA証明書 | /config/.acme.sh/ドメイン_ecc/ca.cer |
サーバー証明書+中間CA証明書 | /config/.acme.sh/ドメイン_ecc/fullchain.cer |
サーバー証明書のコピー | /config/ssl/server.pem |
中間CA証明書のコピー | /config/ssl/ca.pem |
ルート証明書
server.pemの中身
$ cat /config/ssl/server.pem
-----BEGIN CERTIFICATE-----
略
-----END CERTIFICATE-----
-----BEGIN EC PRIVATE KEY-----
略
-----END EC PRIVATE KEY-----
サーバー証明書+秘密鍵のようです
付随する設定
設定モードに入ります
$ configure
[edit]
ホスト名の静的マッピング
# set system static-host-mapping host-name ドメイン inet 192.168.10.254
[edit]
更新タスクをスケジューラーに登録
# set system task-scheduler task renew.acme executable path /config/scripts/renew.acme.sh
[edit]
# set system task-scheduler task renew.acme interval 1d
[edit]
# set system task-scheduler task renew.acme executable arguments '-d ドメイン'
[edit]
コミット、保存
# commit
[ system task-scheduler ]
Restarting cron (via systemctl): cron.service.
[edit]
# save
Saving configuration to '/config/config.boot'...
Done
GUIへの割り当て
# set service gui cert-file /config/ssl/server.pem
[edit]
# set service gui ca-file /config/ssl/ca.pem
[edit]
# commit
[edit]
# save
Saving configuration to '/config/config.boot'...
Done
感想
簡単、素晴らしい。
あとは私がVPNなど他のところで証明書をちゃんと使えるかですが、さて。