// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
#contents

SSLのためのサーバ証明書の話です。サーバ証明書はVersignなどいわゆるCA局((Certificate Authority。認証局ですね))に対して証明書要求(CSR。署名前の証明書のこと)を提出し、それに署名((署名ってのは証明書のハッシュをCA局の秘密鍵で暗号化したモノ、、ですね。たぶん))をしてもらう必要があります。
ところでそのCA局ですが、自分でCAを名乗って自分で署名を行うこともできます。HTTPを使ったサイトを構築する場合などは、ブラウザがサイトにアクセスした際、ブラウザに組み込まれたCAの公開鍵をつかって、署名を行っているCAが正式なモノであるかを検証をするため、自前の署名だとあまり役に立たない((ブラウザに信用できねえ署名だよって警告される。役に立たないってのは言い過ぎ(´д`;) ))わけですが、テストサイトや社内のサイトを立ち上げる場合や、SSL-VPNなどのInternalな用途の場合は自前の署名で十分ですね。

**OpenSSLのインストール [#gbc84640]
 [root@www conf] yum install openssl

**CA用秘密鍵を作成する [#wa1c64a5]
 [root@www conf]# openssl genrsa -des3 -rand /var/log/maillog -out ca.key 1024
 441467 semi-random bytes loaded
 Generating RSA private key, 1024 bit long modulus
 ......++++++
 .........................++++++
 e is 65537 (0x10001)
 Enter pass phrase for ca.key:
 Verifying - Enter pass phrase for ca.key:
 [root@www conf]#

**CA用証明書を作成する [#o0cd4f10]
先の秘密鍵から、CA用の証明書を作成します
 [root@www conf]#  openssl req -new -x509 -days 365 -key ca.key -out ca.crt
 Enter pass phrase for ca.key:
 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) [GB]:JP
 State or Province Name (full name) [Berkshire]:Tokyo
 Locality Name (eg, city) [Newbury]:Bunkyo
 Organization Name (eg, company) [My Company Ltd]:Private CA
 Organizational Unit Name (eg, section) []:Admin
 Common Name (eg, your name or your server's hostname) []:www.hogehoge.com
 Email Address []:masatomix@hogehoge.com
 [root@www conf]#


**CSRにCAとして署名する。 [#f1d7fd39]
***サイン用shを取得 [#sd7ab6e4]
 [root@www conf]# cd /tmp/
 [root@www tmp]# http://www.modssl.org/source/mod_ssl-2.8.30-1.3.39.tar.gz
 [root@www tmp]# wget http://www.modssl.org/source/mod_ssl-2.8.30-1.3.39.tar.gz
 --23:33:36--  http://www.modssl.org/source/mod_ssl-2.8.30-1.3.39.tar.gz
            => `mod_ssl-2.8.30-1.3.39.tar.gz'
 www.modssl.org をDNSに問いあわせています... 195.30.6.168
 www.modssl.org|195.30.6.168|:80 に接続しています... 接続しました。
 HTTP による接続要求を送信しました、応答を待っています... 200 OK
 長さ: 820,416 (801K) [application/x-gzip]
 
 100%[============================================================================>] 820,416       80.34K/s    ETA 00:00
 
 23:33:47 (79.45 KB/s) - `mod_ssl-2.8.30-1.3.39.tar.gz' を保存しました [820416/820416]
 [root@www tmp]# tar xvzf mod_ssl-2.8.30-1.3.39.tar.gz

***サインする [#nc7b21b5]
 [root@www conf]# /tmp/mod_ssl-2.8.30-1.3.39/pkg.contrib/sign.sh  server.csr
 CA signing: server.csr -> server.crt:
 Using configuration from ca.config
 Enter pass phrase for ./ca.key:
 Check that the request matches the signature
 Signature ok
 The Subject's Distinguished Name is as follows
 countryName           :PRINTABLE:'JP'
 stateOrProvinceName   :PRINTABLE:'Tokyo'
 localityName          :PRINTABLE:'Bunkyo'
 organizationName      :PRINTABLE:'Masatom in'
 organizationalUnitName:PRINTABLE:'self'
 commonName            :PRINTABLE:'www.hogehoge.com'
 emailAddress          :IA5STRING:'root@hogehoge.com'
 Certificate is to be certified until Mar  1 14:35:46 2009 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
 CA verifying: server.crt <-> CA cert
 server.crt: OK
 [root@www conf]#


CSRから証明書が作成されました。
 [root@www conf]# ls -lrt
 合計 308
 -rw-r--r-- 1 root root   887 2008-03-01 23:18 ca.key
 -rw-r--r-- 1 root root  1314 2008-03-01 23:20 ca.crt
 -rw-r--r-- 1 root root   887 2008-03-01 23:28 server.key
 -rw-r--r-- 1 root root  2706 2008-03-01 23:36 server.crt <-これ
 [root@www conf]#





----
この記事は
#vote(おもしろかった,そうでもない)

#comment
#topicpath


SIZE(10){現在のアクセス:&counter;}

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS