









[blog]
[ML]
[todo]
[CVS]
[bug]
[apache log]
[swiki log]
[statistics]
[map]
[man]
[info]
[アンテナ]
SSL(TLS)
Secure Sockets Layerのこと。
ブラウザに鍵がかかるあれ(↑)のことだ。
Netscape社が提唱してきて、IETFで標準化されTLS1.0となる。
RFCは、RFC2246だ。

Apache+mod_sslでセキュアなコンテンツを
管理者向けページを、認証に加えてSSL化することにしました。
こうすることで、パスワードも暗号化されて送信されますので。
Kondara-2.1の場合、mod_sslやopenSSL、Apacheが既にインストールされて
いますので、これらのインストールはしません。
他のディストリをお使いの方は、それなりにインストールしてください。

mod_sslをapacheにインストールする。
Kondara-2.1の場合、/etc/httpd/conf/httpd.confに下記の行を追加します。
LoadModule ssl_module modules/libssl.so

独自の認証局をしょうがないので作る。
Kondaraの場合、認証局用のシェルが、/var/ssl/misc/CA.shにインストール
されます。
このシェルを書き換えて、認証局を運営します。
私の場合、/usr/local/etc/ssl配下にCA.shをコピーしました。
# mkdir -p /usr/local/etc/ssl
# cp /var/ssl/misc/CA.sh /usr/local/etc/ssl
次に、コピーしたCA.shに -newcaをオプションとして起動します。
このオプションは、認証局の新規作成を意味します。
/usr/local/etc/ssl/CA.sh -newca
CA certificate filename (or enter to create)
[すでにCAの証明書をもっている場合、そのファイル名を入力。新規の場合、リターンのみ]
Making CA certificate ...
Using configuration from /var/ssl/openssl.cnf
Generating a 1024 bit RSA private key
....................................................................................................++++++
....++++++
writing new private key to './demoCA/private/./cakey.pem'
Enter PEM pass phrase: [ パスフレーズを入力 ]
Verifying password - Enter PEM pass phrase: [ パスフレーズを再入力 ]
—–
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) [AU]:JP [ 国別コードを入力 ]
State or Province Name (full name) [Some-State]:Kanagawa [州 or 都道府県]
Locality Name (eg, city) []:Kawasaki [ 都市名 ]
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ma2tak.dyndns.org [ 組織名称 ]
Organizational Unit Name (eg, section) []:ma2tak [ 組織内部門名称 ]
Common Name (eg, YOUR name) []:ma2tak [ 管理者名 or サーバー名 ]
Email Address []:ma2tak@ma2tak.dyndns.org [ 管理者のメールアドレス ]
そうすると、カレントディレクトリ内にdemoCAなるディレクトリが作成され、各種ファイルがそこに配置されます。
でこのdemoCAを/usr/local/etc/sslの配下にmvします。

鍵を作る
次に鍵を作ります。
/usr/bin/openssl genrsa -rand /var/log/httpd/error_log -des3 -out /usr/local/etc/ssl/serverkey.pem 1024
31079 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
......................................................................++++++
......++++++
e is 65537 (0x10001)
Enter PEM pass phrase: [パスフレーズを入力する]
Verifying password - Enter PEM pass phrase:[パスフレーズを再入力する]
-randオプションは、乱数の元になるファイルですので、read権限のあるフ
ァイルならなんでもよいとのこと。
最後の1024というのは、鍵のbit数です。512 か 1024を指定しておけばよろ
し。(っていうか、暗号強度の程度によりけりです)
これによって、鍵が/usr/local/etc/ssl/serverkey.pemにできます。
-des3は暗号方式で、これが一番強いので、des3形式をお勧めします。
で、この鍵をapacheに組み込むとapache起動時に毎回パスフレーズの入力
を要求されるようになるらしい。
ですので、ここでは鍵のパスフレーズを解除する。
(但し、こうすると当然ですが鍵のセキュリティが低下します)
/usr/bin/openssl rsa < /usr/local/etc/ssl/serverkey.pem > /usr/local/etc/ssl/serverkey.pem.no_pass
cp serverkey.pem.no_pass serverkey.pem

認証機関への証明書(CSR)を作成する。
本来なら第三者機関に認証をしてもらうわけであるが、個人用の受け付けは
しないし(ベリサインの場合)、有料ですので、ここではとりあえずローカル
認証局用のCSRを作成します。
/usr/bin/openssl req -new -days 365 -key /usr/local/etc/ssl/serverkey.pem -out /usr/local/etc/ssl/csr.pem
Using configuration from /var/ssl/openssl.cnf
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) [AU]:JP
State or Province Name (full name) [Some-State]:Kanagawa
Locality Name (eg, city) []:Kawasaki
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ma2tak.dyndns.org
Organizational Unit Name (eg, section) []:ma2tak
Common Name (eg, YOUR name) []:ma2tak
Email Address []:ma2tak@ma2tak.dyndns.org
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:XXXXXXXXXXXX
An optional company name []:
[root@comm ssl]# /usr/bin/openssl req -new -days 365 -key /usr/local/etc/ssl/serverkey.pem -out /usr/local/e
tc/ssl/csr.pem
Using configuration from /var/ssl/openssl.cnf
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) [AU]:JP
State or Province Name (full name) [Some-State]:Kanagawa
Locality Name (eg, city) []:Kawasaki
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ma2tak.dyndns.org
Organizational Unit Name (eg, section) []:ma2tak
Common Name (eg, YOUR name) []:ma2tak
Email Address []:ma2tak@ma2tak.dyndns.org
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

証明書の作成
作成した申請書を用いて、認証局から証明書を発行してもらいます。
本来は、第三者機関の認証局を使用しますが、ここでは先ほど作成した、
独自認証局より発行してもらいます。
/usr/bin/openssl ca -in /usr/local/etc/ssl/csr.pem -keyfile /usr/local/etc/ssl/demoCA/private/cakey.pem -cert /usr/local/etc/ssl/demoCA/cacert.pem -out /usr/local/etc/ssl/cert.pem
これで基本的な設定は完了であるのだ。

ApacheのSSL用設定
私のところの場合、port80で通常のコンテンツを置いて、port443でSSLをかぶせます。
なので、2重設定をしました。
apacheの設定ファイルの差分を参考までに。
< Port 80
—
> Port 443
> Listen 443
> Listen 80
# Port 443をデフォルトportにして、port80もListenし、後にVirtual HostでPort80側の設定をします。
< LoadModule ssl_module modules/libssl.so
# ssl_moduleを追加します。
> SSLEnable
> SSLVerifyClient 0
> SSLVerifyDepth 10
> SSLCertificateFile /home/hoge/cert/cert.pem
> SSLCertificateKeyFile /home/hoge/cert/serverkey.pem
# SSL用の設定を追加します。
# デフォルトは、Port443の設定となり、ここではSSLEnableでSSLを有効化しています。
> <VirtualHost *:80>
> SSLDisable
> Port 80
> DocumentRoot "/home/www/public_html"
> Alias /icons/ "/home/www/public_html/icons/"
> ScriptAlias /cgi-bin/ "/home/www/public_html/cgi-bin/"
> ErrorLog /var/log/httpd/error_log
> CustomLog /var/log/httpd/access_log combined
>
> <Directory "/home/www/public_html/">
> AllowOverride ALL
> Options ExecCGI MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
> <Limit GET POST OPTIONS PROPFIND>
> Order allow,deny
> Allow from all
> </Limit>
> <LimitExcept GET POST OPTIONS PROPFIND>
> Order deny,allow
> Deny from all
> </LimitExcept>
> </Directory>
>
> <Directory "/home/www/public_html/icons/">
> Options Indexes MultiViews
> AllowOverride None
> Order allow,deny
> Allow from all
> </Directory>
>
> <Directory "/home/www/public_html/cgi-bin/">
> AllowOverride ALL
> Options ExecCGI
> <Limit GET POST OPTIONS PROPFIND>
> Order allow,deny
> Allow from all
> </Limit>
> <LimitExcept GET POST OPTIONS PROPFIND>
> Order deny,allow
> Deny from all
> </LimitExcept>
> </Directory>
> </VirtualHost>

Gentooでの設定(2006年)
/etc/apache2/sslの下で、以下を実行。
openssl req -new -days 365 -key server.key -out server.csr
これで証明書作って、以下で署名。
openssl x509 -req -in server.csr -signkey server.key -out server.crt
それで、apache2を起動しなおす。
但し、/etc/conf.d/apache2に-D SSLを忘れずにつける。

関連サイト

Links to this Page