【OpenSSL】Windowsで Openssl を使って認証局を立てる

 ■ はじめに

 * 以下で、Windows での Openssl を設定したが、
   今回は、CA の開設について書く

https://dk521123.hatenablog.com/entry/2013/12/07/103903

 【1】設定

1)Openssl のインストールと設定

以下の関連記事を参照のこと。

https://dk521123.hatenablog.com/entry/2013/12/07/103903

2)ActivePerlの設定

 ActivePerlの設定

http://www.perlplus.jp/perlinstall/

を参考に。

[2-1] ActivePerlを以下からダウンロードする
http://www.activestate.com/activeperl/downloads

[2-2] ActivePerlをインストールする

結構長い

[2-3] 環境変数「Path」に、ActivePerlのexeファイルの場所を追加する

[スタート]で[マイコンピュータ]を右クリックし、[プロパティ]-[詳細設定]-[環境変数]を選択し
環境変数「Path」に「;C:\Perl\bin」を追加する

[2-4] 確認

コマンドプロンプトを立ち上げ、「perl -v」を入力し、
ActivePerlが正常にインストールされているか確認する

 【2】認証局を立てる

 ``` 以下は、主にコマンドプロンプトで実行する

** [1] 認証局関連の作業用フォルダーを作る **  

ここでは C:\Openssl-Win32\workに作成する

cd C:\OpenSSL-Win64 md work

cd work

** [2] CA.pl と openssl.cfg ファイルを bin フォルダーからコピー **  

copy ..\bin\CA.pl .\ copy ..\bin\openssl.cfg .\

** [3] CA.pl をテキストエディタで開き、以下を変更 **  

$SSLEAY_CONFIG=$ENV{"SSLEAY_CONFIG"};

$SSLEAY_CONFIG="-config C:\OpenSSL-Win32\work\openssl.cfg";

** [4] 認証局を立てるために以下のコマンドを入力 **  

(このために、ActivePerlをインストールした)

perl CA.pl -newca

=> 証明書要求(CSR)を作成し、demoCAにて署名することで証明書を作成

** 出力ファイル **  

demoCA\careq.pem : 証明書の発行要求(CSR) openssl req -in demoCA\careq.pem -text demoCA\cacert.pem : careq.pemに自らがCA局として署名し、証明書を作成した証明書 openssl x509 -in demoCA\cacert.pem -text demoCA\private\cakey.pem : 秘密鍵 rsa -in demoCA\private\cakey.pem -text

# 【3】証明書の作成(サーバ認証)
** [1] サーバ証明書を作成する **  

perl CA.pl -newreq

** [2] newreq.pemにdemoCAの秘密鍵(demoCA/private/cakey.pem)で署名し、newcert.pemを生成する **  

perl CA.pl -sign

** 出力ファイル **  

newkey.pem : 秘密鍵 openssl rsa -in newkey.pem -text

newreq.pem : 証明書発行要求(CSR) openssl req -in newreq.pem -text

newcert.pem : demoCAの秘密鍵で署名した証明書 openssl x509 -in newcert.pem -text

## 1)クライアント認証
** [1] サーバ証明書を作成する **  

perl CA.pl -newreq

** [2] newreq.pemにdemoCAの秘密鍵で署名し、newcert.pemを生成する **  

perl CA.pl -sign

** [3] 証明書をPKCS12形式に変換 **  

openssl pkcs12 -export -clcerts -inkey newkey.pem -in newcert.pem -out eigy-taro.p12

# 参考文献
** 参考になった **  
http://msmania.wordpress.com/tag/%E8%A8%BC%E6%98%8E%E6%9B%B8/  
** 長いが一見の価値あり **  
http://homepage2.nifty.com/protocol/openssl/  
** これらも参考になる **  
http://www.ksgmt.com/article/java/javassl_clientcert.html  
http://apis.jpn.ph/fswiki/wiki.cgi?page=Java%2Fkeytool  

# 関連記事
** Windows上での Opensslの設定と自己証明書作成 **  
https://dk521123.hatenablog.com/entry/2013/12/07/103903  
** OpenSSL ~ Linux / 初期設定編 ~ **  
https://dk521123.hatenablog.com/entry/2014/08/21/001440  
** OpenSSL ~ 証明書作成 ~ **  
https://dk521123.hatenablog.com/entry/2016/11/12/011536