PHPki で簡単証明書運用 (1)

PHPki

この記事は phpki-0.83.tar.gz を元に書きましたが,不具合多数の為最新のソースコードを取得して導入する方法に切り替えました.「PHPki で簡単証明書運用 (1) 【修正版】」に更新した記事を掲載していますのでそちらを参照ください.

以下はログとしておいてありますが,まったく参考になりません…

証明書を管理するのって大変ですよね.openssl のコマンドってよく使うコマンド群ではないので覚えづらいのと,作った物の管理もしづらかったり.
そんな怠惰な人にぴったりなのが「PHPki (PHPki Digital Certificate Authority)」です.PHPki は PHP で作成されている OpenSSL の Web フロントエンドです.
リンクしている大本のサイトにライブデモがありますので,どんなもんかちらっと見て頂ければと.
今回は,PHPki の導入と使い方を纏めたいと思います.利用開始までの手順がちょっと面倒なので備忘録を兼ねて…

ダウンロードとインストール

PHPki は Sourceforge で配布されています.「http://sourceforge.net/projects/phpki/」にアクセスし,最新の tarball を取得してください.
# 最新のといっても,phpki-0.83.tar.gz が最新だと思いますし,0.83 は 2011/12 に公開されたようですので,だいぶ経っちゃっていますが…

取得したら Web サーバ上で展開します.Seichan の環境だと Ports で導入した Apache が動いていて,こういった物は /usr/local/www 以下において httpd.confAlias を設定する感じですので,例はそのような形で書きます.
RHEL 系の Linux だと /var/www とかだったと思いますが,そのあたり配置は自由です.

# cd /usr/local/www
# tar xvf /home/seichan/phpki-0.83.tar.gz

Seichan の環境の場合は,先に書いたとおり Apache の Alais 設定ファイルとして /usr/local/etc/apache22/Includes 以下にファイルを作成します.
AllowOverride all は PHPki の Readme に記載されていますのでその通り追加しています.

Alias /phpki083 "/usr/local/www/phpki-0.83"
<Directory "/usr/local/www/phpki-0.83">
  Options none
  AllowOverride all
  Order Deny,Allow
  Allow from all
</Directory>

よくある PHP 関連のソフトウェアは,この後ブラウザでアクセスして設定.という形なのですが,残念ながらこのままアクセスしてもうまく動作しませんので,以下の作業を続けて行います.

php.ini を修正する

PHPki は POST メソッドで結構大きいデータを流します.その為,register_long_arrays が有効である必要がありますので必要に応じて register_long_arraysOn にしてください.

register_long_arrays = On

.htaccess を正しく修正する

展開したディレクトリ直下に .htaccess ファイルが作成されていますが,このファイルの書式が正しくありません.
元のファイルはこの様な形で記述されていると思います.

-e Options FollowSymLinks
-e php_flag register_globals off
-e php_flag register_long_arrays on
-e AddType application/x-x509-ca-cert .crt  .pem
-e AddType application/pkix-crl    .crl
-e AddType application/pkix-cert   .cer .der

上述の設定を下の記述に修正してください.

Options FollowSymLinks
php_flag register_globals off
php_flag register_long_arrays on
AddType application/x-x509-ca-cert .crt  .pem
AddType application/pkix-crl    .crl
AddType application/pkix-cert   .cer .der

PHP ファイル群を修正する

良い/悪いの判断はおいておいて,PHP 開始タグが <?php ではなく <? と,short_open_tag が有効なことを想定した記述があちこちにあります.ですので,実行する環境で short_open_tag が有効であれば問題はありませんが,無効な環境の場合,各ファイルを書き換えるか short_open_tag を有効にしてあげてください.先に修正した .htaccess に次の一文を追加してあげれば対応が完了となります.

php_flag short_open_tag on

root ユーザで secure.sh を実行

展開したディレクトリ直下に secure.sh というファイルがありますので,これを実行します.残念ながら(?) /bin/bash と先頭行に記載されています.ただ,/bin/bash ではなく /bin/sh でも動作しますので,bash が未導入の環境の場合は先頭行を /bin/sh に変更して実行してください

実行すると以下のような表示とともに,次の確認・入力項目が現れます.それぞれ環境に合わせて入力してください.

  • Enter the location of your PHPki password (i.e. /etc/phpkipasswd):

パスワードファイルをどこに作るか聞かれますので,パスを指定します.本環境の場合,Apache の DocumentRoot 以外に展開して Alias で設定する流れにしていますので,展開したディレクトリ (/usr/local/www/phpki-0.83/phpkipasswd) 以下にパスワードファイルを作成しています.

  • Enter a user id:
  • New password:
  • Re-type new password:

管理者アカウント名を入力します.普段使いの管理者ユーザ名を指定してください.Seichan はとりあえず admin としています…
また,パスワードの入力も聞かれますので,2回入力してください.

  • See the README file for more information about the ‘pkiadmin’ user.
  • New password:
  • Re-type new password:

いまいち理由がわからないのですが,デフォルトで pkiadmin というユーザも作成されます.これのパスワードも設定してください.

  • Enter the user ID your web server runs as [apache]:
  • Enter the group ID your web server runs as [apache]:

Apache Web Server が動作するユーザID/グループID の指定が促されます.FreeBSD だと www というアカウントが Web Server 用アカウントですので www と指定していますが,これは環境に合わせてください.

  • Enter the IP or subnet address [192.168.0.0/16] which will be allowed access to the user admin module in under ./admin:

admin という URL/ディレクトリ以下へのアクセスを許可するネットワークを指定してください.admin 以下の URL にアクセスして証明書の作成等を行いますので,許可している所からのアクセスに留めることが必要です.

通しで実行した結果を以下に貼り付けます.

# ./secure.sh

This application is designed to be an easy to use "certificate factory"
requiring minimum human intervention to administer.  It is intended for
use within a trusted INTRAnet for the creation and management of x.509
e-mail digital certificates by departmental managers.  IT IS NOT INTENDED
FOR USE OVER THE INTERNET.

This application stores private keys within a sub-directory, making them
potentially susceptible to compromise.  Extra care has been taken in the
design of this application to protect the security of your certificates,
on the condition that you INSTALL IT AS THE ROOT USER.  However, no
software is 100% secure.

Enter the location of your PHPki password (i.e. /etc/phpkipasswd): /usr/local/www/phpki-0.83/phpkipasswd

The file you specified does not yet exist.
Let's create it and add your first user.
Enter a user id: admin
Creating the admin user account...
New password:
Re-type new password:
Adding password for user admin
Creating the administrator account...
See the README file for more information about the
'pkiadmin' user.
New password:
Re-type new password:
Adding password for user pkiadmin

Enter the user ID your web server runs as [apache]: www

Enter the group ID your web server runs as [apache]: www

Enter the IP or subnet address [192.168.0.0/16] which will be allowed access
to the user admin module in under ./admin: 192.168.0.0/16

Working...
Done.

ベタな設定はこれで完了で,以降は Web アクセスして実施可能となります.キリが良いところになったので,次回にまわします…

コメント

タイトルとURLをコピーしました