Luma

tech.luma.dev by Luma

VPN内のEC2 Amazon Linuxで自己署名署名書を作成して配る

tailscaleでEC2上にあれこれ立てるようにしたものの、HTTPSでないと困る場面も出てきました。Caddyを使います。やってみるとわかりますが、直接入れるとトラブルになりやすいので、docker-composeを利用してdocker内で起動して利用します。

自己署名証明書(ルート証明書)を作成します。

openssl req -newkey rsa:4096 -nodes -keyout caddy.key.pem -x509 -days 10000 -out caddy.cert.pem
openssl x509 -text -noout -in caddy.cert.pem
openssl pkcs12 -inkey caddy.key.pem -in caddy.cert.pem -export -out caddy.cert.p12
shell

完全にノンインタラクティブにやるなら以下が参考になります。

Create SSL certificate non-interactively
I want to silently, non interactively, create an SSL certificate. I.e., without get prompted for any data. The normal way I create the certificate would be: openssl req -x509 -nodes -days 7300 -n...
Create SSL certificate non-interactively

p12はこちら

Export a PKCS#12 file without an export password?
I am generating exporting some pkcs#12 files for testing purposes. These files are not being used in production and only exist temporary during automated testing. I am using the following command:
Export a PKCS#12 file without an export password?

上記をまとめると以下のようになる。

openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
    -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" \
    -keyout caddy.key.pem -out caddy.cert.pem
# openssl pkcs12 -keypbe NONE -certpbe NONE -nomaciter -passout pass: \
#     -inkey caddy.key.pem -in caddy.cert.pem -export -out caddy.cert.p12
openssl pkcs12 -passout pass:caddy \
    -inkey caddy.key.pem -in caddy.cert.pem -export -out caddy.cert.p12
shell

p12はインストールすれば、winであればcertmgrでpersonal>certificatesなどで確認できるかと思います。

次にサーバー証明書を作成します。

OpenSSL create Client Certificate & Server Certificate with Example | GoLinuxCloud
Steps to create client certificate and server certificate using your own Certificate Authority chain (CA bundle) and configure Apache with SSL (HTTPS)
OpenSSL create Client Certificate & Server Certificate with Example | GoLinuxCloud
openssl genrsa -out server.key.pem 4096
openssl req -new -key server.key.pem -out server.csr -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com"
openssl x509 -req -in server.csr -CA space.cert.pem -CAkey space.key.pem -out server.cert.pem -CAcreateserial -days 10000 -sha256 -extfile ../server_cert_ext.cnf
shell

コード全体の例は以下。

dotfiles/lumaspace/regenerate-certs.sh at master · LumaKernel/dotfiles
⭐ My own world. Contribute to LumaKernel/dotfiles development by creating an account on GitHub.
dotfiles/lumaspace/regenerate-certs.sh at master · LumaKernel/dotfiles
← ホームに戻る