# Generate 4096-bit RSA CA private key
openssl genrsa -aes256 -out ca.key 4096
The -aes256 flag encrypts the private key with a passphrase. Always protect CA keys.
ルートCA証明書を作成する
openssl req -x509 -new -nodes -key ca.key \
-sha256 -days 3650 \
-out ca.crt \
-subj '/C=US/O=My CA/CN=My Root CA'
-x509 makes it self-signed. -days 3650 = 10 years.
サーバー鍵を生成する
# Generate 2048-bit RSA server key (no passphrase for web servers)
openssl genrsa -out server.key 2048
Server keys should not have passphrases (web servers can't prompt during startup).
証明書署名要求(CSR)を作成する
openssl req -new -key server.key \
-out server.csr \
-subj '/C=US/O=My App/CN=localhost'
The CSR contains the public key and requested subject. It is signed by the applicant's private key.
openssl verify -CAfile ca.crt server.crt
# server.crt: OK
This confirms the server certificate was correctly signed by our CA. Any modification to the cert would fail verification.
curlでテストする
# Start a Python server with the cert:
# python3 -m http.server --bind 127.0.0.1 8443 # (simplified)
# Test with our CA cert:
curl --cacert ca.crt https://localhost:8443
# Without --cacert, curl would reject the self-signed CA