certbotを使いLet's EncryptでECDSAな証明書を作る 2022年

鍵
©いらすとや.

5年前に Let's EncryptでECDSAな証明書 を書いたときはまだECDSAな証明書を作るのは少し面倒だった。現在は簡単にECDSA鍵なTLS証明書を発行できるようになっている。
今回「がとらぼ」を https://gato.intaa.net から https://intaa.net にドメイン内移転させるにあたり、メールサービスに使っていた https://intaa.net を別ホストから「がとらぼ」の動いているホストに移すことになった。そこで、別ホストのintaa.net証明書を破棄 (certbot delete)し、「がとらぼ」のホストで再発行することにした。そのついでにECDSAな鍵の証明書を再発行した。

certbotでECDSAな証明書を発行(新規)

# certbot certonly --key-type ecdsa -d example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Requesting a certificate for example.com
Input the webroot for example.com: (Enter 'c' to cancel): /var/www/example.com

Successfully received certificate.
Certificate is saved at: /usr/local/etc/letsencrypt/live/example.com/fullchain.pem
Key is saved at:         /usr/local/etc/letsencrypt/live/example.com/privkey.pem
This certificate expires on 2023-01-16.
These files will be updated when the certificate renews.

NEXT STEPS:
- The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.

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

このように --key-type ecdsa をコマンドに追加するだけでECDSAな証明書が発行される。なお、鍵のタイプだけを指定した場合は P-256 (prime256v1=secp256r1) になるみたい。高めの暗号強度を得たくて P-384 (secp384r1) にしたいのであれば追加で --elliptic-curve secp384r1 を指定する。まぁ普通はsecp256r1で良さそう。
強度的にはECDH256が鍵長3076bitのRSAに少し及ばない程度。ECDH384だと鍵長7680bitのRSAに少し及ばない程度でこれはブログなどの普通のウェブサイトで使うにはオーバーキルだと思う。

設定と更新への影響

以降全ての証明書の発行でECDSAにするとかP-384にしたいということであれば設定ファイル /usr/local/etc/letsencrypt/cli.ini (FreeBSDのPKG/Portsでインストールした場合のPath)に書く。cli.iniはPKG/Portsでインストールした場合は存在しないので過去に設定ファイルを作っていないなら新規作成となる。

key-type = ecdsa
elliptic-curve = secp384r1

設定を書いてしまうとそれがデフォルトになるので以降に例えばRSAな鍵を作りたいなら コマンドで --key-type rsa を指定することになる。RSAの鍵長さを初期値の2048bitではなく4096bitにしたいとなれば --rsa-key-size 4096 を追加指定する。
設定を書くと既存の証明書(発行時にオプション指定なしの証明書)の次回以降の更新に影響が及ぶため十分に注意。証明書発行時に付けたオプションは設定ファイルより優先して更新時にも適用されます。つまり --key-type ecdsa--key-type rsa を付けて発行(更新)した証明書は次回以降の更新でも設定ファイルの指定を無視して発行時と同じ --key-type ecdsa や --key-type rsa を付けたのと同様に更新されます。

ECDSAな証明書に変更して更新

既存のRSAな証明書をただちにECDSAな証明書に「更新」したいということがある筈。

# certbot renew --cert-name example.com --key-type ecdsa --force-renewal
こんな感じでいける。

ハイブリッド証明書

5,6年前はECDSAな証明書を普通のウェブサイトで使用するなら閲覧者のブラウザとの互換性のためにRSAな証明書とのハイブリッドを勧めたが、2022年の今はもうハイブリッドにする必要はないように思う。よほど古いスマホ Android 2.xとか古いゲーム機のブラウザが非対応なくらい。
ECDSAなSSL証明書を作ってみる

RSAな証明書を作成済みとして、ECDSAな証明書を追加発行する。

# certbot certonly --key-type ecdsa --cert-name example.com-ecdsa

5年前と比べると、需要を満たすコマンドが多く追加されたようでとても簡単になってて良い感じ。

関連記事: