独自CA環境構築と証明書作成手順(Debian / openssl コマンド編)
背景
CA.sh を使用して、CSR や秘密鍵、証明書の出力先を指定するには CA.sh への追記が必要。追記するためには、各コマンドのオプションとかを調べる必要がある。でも、ここまでやるなら最初から自分でコマンド打ち込んでもいいのでは?ということで、openssl のコマンドを実行する手順を整理。
Directory 構成
以下のようにする。
OpenSSL_DIR
MyRootCA
MiddleCA
Servers
MyRootCA の手順
openssl.cnf ファイルの編集内容は独自CA環境構築と証明書作成手順(Debian / CA.sh 編) - Shammerismと同じ。
- mkdir $OPENSSL_DIR
- cd $OPENSSL_DIR
- mkdir $RootCA_DIR(MyRootCA)
- cd $RootCA_DIR
- mkdir newcerts certs crl private
- touch index.txt
- echo 00 > serial
- cp -p $OpenSSL_ConfigFile(Debian:/etc/ssl/openssl.cnf) $OpenSSL_ConfigFile.default
- Edit $OpenSSL_ConfigFile
- The default dir value of [ CA_default ] is "./demoCA", rename this to "./MyRootCA".
- The default_md value of [ CA_default ] is "default_md", change this value to "sha256".
- The default_bits of [ req ] is 1024, change this value to 2048.
- The basicConstraints of [ v3_ca ] is "CA:true" only, comment out this line and delete # at the line of "basicConstraints = critical,CA:true".
- openssl genrsa -out ./private/cakey.pem 2048
- openssl req -new -x509 -key ./private/cakey.pem -outform PEM -out cacert.pem -days 3650
MiddleCA(中間認証局)の手順
- cd $OPENSSL_DIR
- mkdir $MiddleCA
- cd $MiddleCA
- mkdir private newcerts certs cry
- touch index.txt
- echo 00 > serial
- copy -p /etc/ssl/openssl.cnf .
- Edit ./openssl.cnf
- Change the dir value of [ CA_default ] to $MiddleCA
- Change stateOrProvinceName of [ policy_match ] to optional
- Change organizationName of [ policy_match ] to optional
- Copy [ v3_ca ] section as [ v3_middle_ca ] section
- Enable basicConstraints of [ v3_middle_ca ] is "CA:true" only.
- openssl genrsa -out ./private/cakey.pem 2048
- openssl req -new -key ./private/cakey.pem -out middleca.csr
- cd $OPENSSL_DIR
- openssl ca -create_serial -batch -extensions v3_middle_ca -in $MiddleCA/middleca.csr -out $MiddleCA/cacert.pem