0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TLS/SSLのルート/サーバー/クライアント証明書の作成手順

Posted at

1. ルート証明書の作成

環境変数の設定
CA_NAMEcc
SUBJECT=/C=JP/ST=***/L=***/O=***/OU=${CA_NAME}/CN=${CA_NAME}
秘密鍵の作成
openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:4096 -out ${CA_NAME}.key
ルート証明書の作成
openssl req -new -x509 \
    -out ${CA_NAME}.crt -key ${CA_NAME}.key \
    -days `expr 365 \* 3` \
    -subj ${SUBJECT}

2. サーバー署名リクエストの作成

環境変数の設定
SERVER=*******
SUBJECT=/C=JP/ST=***/L=***/O=***/OU=${SERVER}/CN=${SERVER}
サーバー秘密鍵の作成
openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:4096 -out ${SERVER}.key
サーバー署名リクエストの作成
openssl req -new \
    -out ${SERVER}.csr \
    -key ${SERVER}.key \
    -subj ${SUBJECT}

3. サーバー証明書の作成

Extention Fileの作成
cat << 'EOS' > san.txt
> subjectAltName = DNS:***, IP:*.*.*.*
> EOS
インデックスファイルの作成
mkdir /etc/pki/CA
touch /etc/pki/CA/index.txt
サーバー証明書の作成
openssl ca \
    -in ${SERVER}.csr \
    -out ${SERVER}.crt \
    -outdir . \
    -cert ${CA_NAME}.crt \
    -keyfile ${CA_NAME}.key \
    -days `expr 365 \* 3` \
    -extfile san.txt \
    -create_serial -rand_serial

4. クライアント署名リクエストの作成

環境変数の設定
CLIENT=*******
SUBJECT=/C=JP/ST=KANAGAWA/L=KAWASAKI/O=mabe/OU=${CLIENT}/CN=${CLIENT}
クライアント秘密鍵の作成
openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:4096 -out ${CLIENT}.key
クライアント署名リクエストの作成
openssl req -new\
    -out ${CLIENT}.csr \
    -key ${CLIENT}.key \
    -subj ${SUBJECT}

5. クライアント証明書の作成

クライアント証明書の作成
openssl ca \
    -outdir . \
    -cert ${CA_NAME}.crt \
    -keyfile ${CA_NAME}.key \
    -out ${CLIENT}.crt \
    -days `expr 365 \* 3` \
    -create_serial -rand_serial \
    -infiles ${CLIENT}.csr

6. クライアント証明書と秘密鍵の格納

クライアント証明書と秘密鍵の格納
openssl pkcs12 \
    -export -in ${CLIENT}.crt \
    -inkey ${CLIENT}.key \
    -out ${CLIENT}.pfx \
    -name ${CLIENT}

インポートする環境によっては -legacy が必要かも。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?