Ubuntu 20.04のapache2で証明書を要求してHTTPSを有効にする

 Ubuntu 20.04、apache2でのhttps有効化方法です。
 まずは公開証明書をシステムの証明書ストアへ導入します。CA構築のときにお世話になったDigitalOceanのページを参考に、CAマシンのca.crtファイルをapacheマシンの/usr/local/share/ca-certificatesディレクトリーにコピーします。そして以下のように実行

# /usr/sbin/update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

 これで/etc/ssl/certsディレクトリーにpemファイルとしてリンクされました。このときファイル名がインポート後の証明書ファイル名にもなりますので、ca.crtのままでなくmydomain-root-ca.crtなどとわかりやすいものに変更しておいたほうがいいと思います。
 次にapacheマシンで証明書要求の作成をします。まずはマシン自体の秘密鍵楕円曲線で作成。

# /usr/bin/openssl ecparam -name prime256v1 -genkey -out ubuntu.key

この秘密鍵のkeyファイルはapacheの設定ファイルにならって/etc/ssl/privateディレクトリーに移動して所有権やパーミンションを変更しておきます。

# mv ubuntu.key /etc/ssl/private
# /usr/bin/chown root:ssl-cert /etc/ssl/private/ubuntu.key
# /usr/bin/chmod 640 /etc/ssl/private/ubuntu.key

 そしてCSRファルの作成です。

# /usr/bin/openssl req -new -key /etc/ssl/private/ubuntu.key -out ubuntu.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:TODOHFUKEN
Locality Name (eg, city) :MACHI
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Company Name
Organizational Unit Name (eg, section)
:My Domain
Common Name (e.g. server FQDN or YOUR name) :ubuntu
Email Address
:mail@mydomain.local

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password : 入力なし
An optional company name
: 入力なし

 これで作成されたubuntu.csrファイルを上記CAサーバーにコピーしてWindowsのときと同様に署名して証明書が完成です。crtファイルをapacheマシンにコピーしてきて、そのまま/etc/ssl/certsディレクトリーにおいてもいいのですが他にならってファイル名をubuntu.pemとしています。
 Ubuntuapachehttps有効化ですが、多くのサイトで解説されていますのでそれらを参考に、

# /usr/sbin/a2enmod ssl
# /usr/sbin/e2ensite default-ssl.conf

を実行後、設定ファイルを各自のサイトに合わせて編集します。まずは/etc/apache2/mods-enabled/ssl.confを

SSLProtocol all -SSLv3

となっているところを

SSLProtocol -all +TLSv1.2 +TLSv1.3

にしました。TLSのv1.2と1.3のみ有効としています。EdgeやChromeはv1.3で問題ないのですがIEモードも含めIE 11でアクセスすることもあるのでv1.2も必要です。IEのオプション設定でTLS v1.3を有効にできるようなのですが、デフォルト無効でグループポリシーも今のところないためv1.2でもアクセスできるようにしています。
 そして/etc/apache2/sites-enabled/default-ssl.confをうちでは

ServerName              ubuntu
SSLCertificateFile      /etc/ssl/certs/ubuntu.pem
SSLCertificateKeyFile   /etc/ssl/private/ubuntu.key

の項目のみ編集しました。ServerNameを改めて指定しているのは、無指定だとFQDNがデフォルトのServerNameになるようで、apacheのerror.logファイルに、起動時

server certificate does NOT include an ID which matches the server name

とワーニングが出るのを回避するためです。もちろん、おおもとの設定ファイルでServerNameを指定してもいいと思います。
 apacheを再起動してhttpsでアクセスできることを確認して完了です。