クライアント証明書(mTLS用)発行
ALBにて実施するクライアント証明で利用するCAとクライアント証明書を作成する。 (ALB用のサーバ証明書はACMにて別途step4で作成)
1. CA作成
ローカル端末にて、
bash
# CA用の秘密鍵
openssl genrsa -out ca.key 2048
# CAの自己署名の証明書
# -key: 利用する秘密鍵
# -sha256: ハッシュアルゴリズム
# -days: 有効期限 10年
# -out: 生成するCA証明書のファイル名
openssl req -x509 -new -nodes \
-key ca.key \
-sha256 \
-days 3650 \
-out ca.crt2. クライアント用証明書
ローカル端末にて、
bash
# クライアントの秘密鍵
openssl genrsa -out client.key 2048
# 証明書申請(CSR)
openssl req -new \
-key client.key \
-out client.csr
# クライアント証明書に属性情報をつけるための設定ファイル
cat <<EOF > client_ext.cnf
[ v3_req ]
extendedKeyUsage = clientAuth
keyUsage = digitalSignature
EOF
# CAで署名してクライアント証明書を発行
openssl x509 -req \
-in client.csr \
-CA ca.crt \
-CAkey ca.key \
-CAcreateserial \
-out client.crt \
-days 365 \
-sha256 \
-extfile client_ext.cnf \
-extensions v3_reqクライアント証明書の確認
bash
openssl x509 -in client.crt -text -noout | grep -A5 "Extended Key Usage"Webクライアント証明の記載があればOK
text
X509v3 Extended Key Usage:
TLS Web Client Authentication3. 生成できたものの取り扱い
| ファイル名 | 役割 | 取り扱い |
|---|---|---|
ca.key | CAの秘密鍵 | 公開NG(ファイルサーバ保管) |
ca.crt | CAの証明書 | ALBに登録 |
client.key | クライアント秘密鍵 | 公開NG(ファイルサーバ保管) |
client.crt | クライアント証明書 | 接続許可するPCのブラウザに入れる |
client.csr | 申請書 | 不要(client.crt作成できたらもう要らない) |