(仮)阿弥太郎 備忘録Wiki
自己認証局の設定
最終更新:
amitaro
個人利用でサーバーを設置したが、わざわざ証明書を購入することができない。
そんな時に有効なのが、自分で自分を証明する方法。
CA認証局
1.電子証明書の設置場所 どこでもいいので、とりあえず設置場所を決めます。
$ cd /etc/ssl $ sudo mkdir CA
2.OpenSSLのデフォルト値を変更しておく
デフォルト値の変更の前に、設定ファイルはコピーする。
$>sudo cp /etc/ssl/openssl.cnf /etc/ssl/openssl.cnf.orig
同じ様な質問を何回も聞かれるのでデフォルト値を変更しておく。/etc/ssl/openssl.cnf
: dir = /etc/ssl/CA ← ディレクトリを変更 : default_days = 3650 ← 10年に変更 : countryName_default = JP ← JPに変更 : stateOrProvinceName_default = Yamaguchi ← 変更 : localityName_default = Yamaguchi ← 追加しました 0.organizationName_default = Private ← 変更 organizationalUnitName_default = amitaro ← コメントアウトを外して追加 commonName_default = amitaro.home.net ← 追加します emailAddress_default = 管理者のメールアドレス ← 追加します
3.必要なディレクトリの作成
$>cat /dev/null | sudo tee index.txt $>echo '01' | sudo tee serial $>echo '01' | sudo tee crlnumber $>sudo mkdir private $>sudo chmod 700 private $>mkdir newcerts $>mkdir crl $>mkdir certs
4.秘密鍵の作成
$>sudo openssl genrsa -out private/cakey.pem 1024
5.秘密鍵を使って個人的認証局を作成 有効期限は10年にする
$>sudo openssl req -new -x509 -days 3560 -key private/cakey.pem -out cacert.pem You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [JP]: State or Province Name (full name) [Yamaguchi]: Locality Name (eg, city) [Yamaguchi]: Organization Name (eg, company) [Private]: Organizational Unit Name (eg, section) [amitaro.home]: Common Name (eg, YOUR name) [amitaro]: Email Address [amitaro@amitaro.home.net]:
6.サーバ証明書と署名リクエスト(CSR)を作成する準備をします。
$>sudo mkdir /etc/ssl/Server $>cd /etc/ssl/Server
秘密鍵の作成
$>sudo openssl genrsa -out private.pem 1024
7.認証局に署名してもらう為リクエストを作成する
$>sudo openssl req -new -key private.pem -out request.pem You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [JP]: State or Province Name (full name) [Yamaguchi]: Locality Name (eg, city) [Yamaguchi]: Organization Name (eg, company) [Private]: Organizational Unit Name (eg, section) [amitaro.home]: Common Name (eg, YOUR name) [amitaro]: Email Address [amitaro@amitaro.home.net]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: ←何も入力せずEnter An optional company name []: ←何も入力せずEnter
8.CAで署名する $>sudo cp /etc/ssl/openssl.cnf ./. $>sudo openssl ca -config openssl.cnf -policy policy_anything -out ./cert-ca.pem -infiles request.pem
以下の2つの質問は y で良い Certificate is to be certified until Apr 17 11:03:37 2019 GMT (3650 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated
9.サーバ証明書だけ抜き取る
$>sudo openssl x509 -in cert-ca.pem -out cert.pem
10.作成した鍵の確認
$>openssl verify -CAfile /etc/ssl/CA/cacert.pem cert-ca.pem cert-ca.pem: OK $>openssl verify -CAfile /etc/ssl/CA/cacert.pem cert.pem cert.pem: OK
11.Windows用の証明書の作成
$>cd /etc/ssl/CA $>openssl x509 -inform pem -in cacert.pem -out ca.der -outform der
12.Windows側へ証明書をインストールする