< CSS | Server Gated Cryptography >

October 27, 2003

IIS + OpenSSL

OpenSSLを使って、httpsを使用するために必要になる証明書を作成する方法です。
パラメータは結構適当です。大まかな手順のみです。以下のものを作成します。

  • CAの秘密鍵
  • CAの証明書(ルート証明書)
  • Webサーバの証明書

参考にしたサイト:IIS+OpenSSLでhttpsを[Yonetani A.'s Home Page !]

まず。設定ファイルを編集。openssl.cnfがopensslディレクトリの\apps辺りにあるので、作業するディレクトリにコピーして、IIS-5.1(WindowsXP Professional)の設定[BitLINK]を参考に、以下のような感じにしました。

#openssl.cnf
[ CA_default ]
dir = .
certs = $dir
crl_dir = $dir
database = $dir/index.txt
new_certs_dir = $dir
certificate = $dir/cacert.pem
serial = $dir/serial
crl = $dir/server.crl
private_key = $dir/cakey.pem
RANDFILE = $dir/.rand

作業ディレクトリはC:\caとしました。ここには、IISで作成した証明書要求(CSR,ここではcertreq.txt)と、新規にindex.txt、serialの二つのファイルを作成しておきます。serialの中身は01とだけ入力して保存します。

C:\ca
    +--openssl.cnf	#設定ファイル
    +--certreq.txt	#IISで作成した証明書要求
    +--index.txt	#空ファイル
    +--serial	#01とだけ書いておく

次に、コマンドプロンプトを起動します。最初に、認証局の秘密鍵を作成します。

C:\>cd ca

C:\ca>openssl genrsa -out .\cakey.pem 1024
Loading 'screen' into random state - done
Generating RSA private key, 1024 bit long modulus
..++++++
....................................................................++++++
e is 65537 (0x10001)

cakey.pemというファイルが作成されます。これが認証局の秘密鍵です。
次に、認証局の証明書を作成します。

C:\ca>openssl req -new -x509 -config .\openssl.cnf -key .\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]:JP
State or Province Name (full name) [Some-State]:Kyoto
Locality Name (eg, city) []:Kameoka
Organization Name (eg, company) [Internet Widgits Pty Ltd]:raindrop company
Organizational Unit Name (eg, section) []:knowledge section
Common Name (eg, YOUR name) []:frog.raindrop.jp Certification Server
Email Address []:frog@zk.raindrop.jp

cacert.pemというファイルが作成されます。認証局の公開鍵を含む証明書です。認証局のルート証明書としてクライアントにインストールする形式に変換します。

C:\ca>openssl x509 -inform pem -outform der -in .\cacert.pem -out raindrop.der

raindrop.derが生成されます。

次に、Webサーバの証明書要求に署名します。

C:\ca>openssl ca -config .\openssl.cnf -days 365 -out .\server_.cer -infiles .\certreq.txt
Using configuration from .\openssl.cnf
Loading 'screen' into random state - done
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :PRINTABLE:'frog.raindrop.jp'
organizationalUnitName:PRINTABLE:'knowledge section'
organizationName      :PRINTABLE:'raindrop company'
localityName          :PRINTABLE:'Kameoka'
stateOrProvinceName   :PRINTABLE:'Kyoto'
countryName           :PRINTABLE:'JP'
Certificate is to be certified until Oct 26 11:10:26 2004 GMT (365 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

C:\ca>openssl x509 -in .\server_.cer -out .\server.cer

C:\ca>

server_.cerが作成されますが、そのままではゴミデータが付いているので、それをのぞいたものがserver.cerらしいです。これはIISにインストールします。

トラックバック

このエントリーにトラックバック:
http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/85

コメント

コメントする

※ コメントスパム対策のため、コメント本文はおはよう、こんにちわ、こんばんわのいずれかより始めるようにしてください。

name:
email:

※ 必要ですが、表示しません。

url:
情報を保存する ?