2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

プライベートCAを構築する

Last updated at Posted at 2018-11-03

プライベートCAを構築する

証明書は本来,正式なルートCAまたは中間CAに依頼して発行してもらいます。
ここでは,開発用途で自前でルートCA(プライベートCA)を構築する方法を紹介します。

確認環境

  • CentOS 7
  • OpenSSL 1.0.2k-fips

OpenSSL投入

yum install コマンドでOpenSSLを投入します。
ここではOpenSSLの設定ファイルはいじりませんが,念のために設定ファイルをバックアップしておきます。

$ sudo yum -y install openssl
$ sudo cp /etc/pki/tls/openssl.cnf /etc/pki/tls/openssl.cnf.org

OpenSSLの設定ファイルを確認

設定ファイルの一部を,次に抜粋します。
プライベートCAの構築にあたり,最低限,知っておくべき部分です。

/etc/pki/tls/openssl.cnf
[ ca ]
default_ca      = CA_default            # The default ca section

[ CA_default ]
dir             = /etc/pki/CA           # Where everything is kept
database        = $dir/index.txt        # database index file.
certificate     = $dir/cacert.pem       # The CA certificate
serial          = $dir/serial           # The current serial number
private_key     = $dir/private/cakey.pem# The private key

プライベートCA構築

CA_default セクションがデフォルトの設定です。
今までに証明書を発行したことがない場合,この設定に従って,次のファイルを作成していきます。

  • /etc/pki/CA/serial
    • CAが証明書を発行するたびに,自動的にこのファイル内の数字がインクリメントされる
  • /etc/pki/CA/index.txt
    • CAが証明書を発行するたびに,自動的にこのファイルに証明書の情報が追加される
  • /etc/pki/CA/private/cakey.pem
    • CA自身の秘密鍵ファイル(漏洩しないように管理する)
  • /etc/pki/CA/cacert.pem
    • CA自身の証明書ファイル

まず, serialindex.txt ファイルを作成します。

$ sudo su -c 'echo "0001" > /etc/pki/CA/serial'
$ sudo su -c 'touch /etc/pki/CA/index.txt'

今回は, 「ルートCA」 として使用するので自己署名で証明書を作成します。次のコマンドで,自己署名済みの証明書ファイル cacey.pem と秘密鍵 cakey.pem を作成します。

コマンドのオプションでは,暗号方式はRSA(2048ビット),公開鍵証明書の形式はX.509,ルートCAの国名として C=JP ,組織名として O=Example Company ,部署名として OU=Example Cerificate Authority を指定しています。

$ sudo su -c 'openssl req \
    -new -x509 -newkey rsa:2048 \
    -out /etc/pki/CA/cacert.pem \
    -keyout /etc/pki/CA/private/cakey.pem \
    -subj "/C=JP/O=Example Company/OU=Example Cerificate Authority"'

コマンドを実行すると,パスフレーズ(pass phrase)を聞かれるので,パスフレーズを入力します。プライベートCAで openssl ca コマンドで証明書を発行する際にこのパスフレーズの入力が必要になります。

最後に,作成した証明書を確認します。

$ openssl x509 -text -noout -in /etc/pki/CA/cacert.pem

以上で,プライベートCAの構築は終わりです。

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?