この記事は CentOS 6 を前提にした古いサーバー構築・保守手順の記録です。CentOS 6 は既にサポートが終了しているため、新規構築では現行の Linux ディストリビューションを利用してください。ここでは、当時の環境を保守・確認するための資料として整理しています。
参考書籍
暗号技術入門 第3版 秘密の国のアリス
公開鍵暗号、電子署名、証明書など、TLS や内部 PKI の前提になる暗号技術を確認したい場合の参考書籍です。価格や在庫はリンク先で確認してください。
Amazon で見るこのリンクは Amazon アソシエイトリンクです。
概要
easy-rsa を使用して自己署名証明書を作成します。
インストール
easy-rsa は、CentOS 6 の標準リポジトリでは提供されていないため、個別に入手する必要があります。
wget https://github.com/OpenVPN/easy-rsa/archive/master.zip展開します。
unzip master作業ディレクトリ
以下を実行します。
- easy-rsa を ~/easy-rsa になるように再配置します。
- ~/easy-rsa ディレクトリに移動します。
- ~/easy-rsa ディレクトリ内のファイルに実行権限を付与します。
- ~/easy-rsa ディレクトリを初期化します。
以降、~/easy-rsa 内で操作を行います。
mv ~/easy-rsa-master/easy-rsa/2.0 ~/easy-rsa
cd ~/easy-rsa
chmod +x *
./clean-allvars
varsvars を環境に合わせて作成します。
cat > vars <<'EOF'
export KEY_COUNTRY="JP"
export KEY_PROVINCE="PROVINCE"
export KEY_CITY="CITY"
export KEY_ORG="si1230.com"
export KEY_OU="si1230.com"
export KEY_EMAIL="myadmin@si1230.com"
EOF環境変数をシステムに反映します。
source vars認証局の作成
認証局 (CA) を作成します。これによりルート証明書(自己署名証明書に署名する証明書)が作成されます。
./build-ca
Generating a 2048 bit RSA private key
.................................+++
........................................................................................................+++
writing new private key to '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) [JP]:
State or Province Name (full name) [PROVINCE]:
Locality Name (eg, city) [CITY]:
Organization Name (eg, company) [si1230.com]:
Organizational Unit Name (eg, section) [si1230.com]:
Common Name (eg, your name or your server's hostname) [si1230.com CA]:
Name [EasyRSA]:
Email Address [myadmin@si1230.com]:サーバー証明書の作成
サーバー証明書を作成します。
./build-key-server server
Generating a 2048 bit RSA private key
.............................+++
..........................................................................................................+++
writing new private key to 'server.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) [JP]:
State or Province Name (full name) [PROVINCE]:
Locality Name (eg, city) [CITY]:
Organization Name (eg, company) [si1230.com]:
Organizational Unit Name (eg, section) [si1230.com]:
Common Name (eg, your name or your server's hostname) [server]:
Name [EasyRSA]:
Email Address [myadmin@si1230.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'JP'
stateOrProvinceName :PRINTABLE:'PROVINCE'
localityName :PRINTABLE:'CITY'
organizationName :PRINTABLE:'si1230.com'
organizationalUnitName:PRINTABLE:'si1230.com'
commonName :PRINTABLE:'server'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'myadmin@si1230.com'
Certificate is to be certified until Apr 12 16:45:11 2023 GMT (3650 days)
Sign the certificate? [y/n]:
1 out of 1 certificate requests certified, commit? [y/n]
Write out database with 1 new entries
Data Base UpdatedDH パラメータの作成
DH パラメータを作成します。
./build-dh証明書廃止リストの作成
証明書廃止リストを作成するために、ダミーのクライアント証明書を作成します。
./build-key dummy
Generating a 2048 bit RSA private key
..............................................................................................................+++
...................+++
writing new private key to 'dummy.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) [JP]:
State or Province Name (full name) [PROVINCE]:
Locality Name (eg, city) [CITY]:
Organization Name (eg, company) [si1230.com]:
Organizational Unit Name (eg, section) [si1230.com]:
Common Name (eg, your name or your server's hostname) [dummy]:
Name [EasyRSA]:
Email Address [myadmin@si1230.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'JP'
stateOrProvinceName :PRINTABLE:'PROVINCE'
localityName :PRINTABLE:'CITY'
organizationName :PRINTABLE:'si1230.com'
organizationalUnitName:PRINTABLE:'si1230.com'
commonName :PRINTABLE:'dummy'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'myadmin@si1230.com'
Certificate is to be certified until Apr 12 17:10:46 2023 GMT (3650 days)
Sign the certificate? [y/n]:
1 out of 1 certificate requests certified, commit? [y/n]
Write out database with 1 new entries
Data Base Updatedダミーのクライアント証明書を作成します。
./build-key dummyクライアント証明書の作成
クライアント証明書を作成します。この例では build-key-pass を使用してパスフレーズを設定していますが、パスフレーズに対応していないクライアントの場合は build-key を使用します。
./build-key-pass client
Generating a 2048 bit RSA private key
......+++
.............................+++
writing new private key to 'client.key'
Enter PEM pass phrase:xxxxxxxx
Verifying - Enter PEM pass phrase:xxxxxxxx
-----
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]:
State or Province Name (full name) [PROVINCE]:
Locality Name (eg, city) [CITY]:
Organization Name (eg, company) [si1230.com]:
Organizational Unit Name (eg, section) [si1230.com]:
Common Name (eg, your name or your server's hostname) [client]:
Name [EasyRSA]:
Email Address [myadmin@si1230.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'JP'
stateOrProvinceName :PRINTABLE:'PROVINCE'
localityName :PRINTABLE:'CITY'
organizationName :PRINTABLE:'si1230.com'
organizationalUnitName:PRINTABLE:'si1230.com'
commonName :PRINTABLE:'client'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'myadmin@si1230.com'
Certificate is to be certified until Apr 12 18:08:47 2023 GMT (3650 days)
Sign the certificate? [y/n]:
1 out of 1 certificate requests certified, commit? [y/n]
Write out database with 1 new entries
Data Base Updated主要な各ファイルのパス
ここまでに作成した主要な各ファイルのパスは以下の通りです。
| 項目 | ファイルパス |
|---|---|
| ルート証明書 | ~/easy-rsa/keys/ca.crt |
| サーバー証明書 | ~/easy-rsa/keys/server.crt |
| サーバー証明書(秘密鍵) | ~/easy-rsa/keys/server.key |
| DH パラメータ | ~/easy-rsa/keys/dh2048.pem |
| 証明書廃止リスト | ~/easy-rsa/keys/crl.pem |
| クライアント証明書 | ~/easy-rsa/keys/client.crt |
| クライアント証明書(秘密鍵) | ~/easy-rsa/keys/client.key |
関連記事
- CentOS 6 OpenVPN サーバー構築 – 証明書とルーティングを含めた古い手順
- CentOS 6 OpenVPN クライアント設定 – 証明書配置と接続設定
- CentOS 6 OpenVPN と Quagga のルーティング問題 – OSPF と VPN 経路の注意点
- CentOS 6 Squid SSL 対応の透過型プロキシを断念した理由
CentOS 6 easy-rsa で自己署名証明書を作成する – OpenVPN 用 PKI の基本



