はじめに
内部管理用サイトでも HTTPS を使いたい為、オレオレ認証局により署名を行ったサーバー証明書を使っている。
認証局の有効期限は 10 年としていたが、昨日その期限が来てしまった。10 年ってほんと速い……
以前、自分でスクリプトを書いて簡単に証明書を発行出来る様にしていたけど、時は流れ、OpenSSL も 3 系が主流になり、使用しているディストリでも OpenSSL 3 がデフォで採用されている。
でもって設定ファイルの記述もちょっと変わっている感じだったんで、改めてスクリプトを―― なんて考えたけど面倒臭さが勝利した。
ここは簡単に EasyRSA を使用してしまおうと。
直ぐ忘れちゃうから備忘録記事とする。
EasyRSA の導入
以下 Github から Release されている物をダウンロードし、任意のパスで展開する。
例えばこんな感じにホーム直に DL してきて展開すると ~/EasyRSA-3.2.4 というディレクトリが出来上がるので、その中で作業出来る。バージョンは 2025/11/25 時点での物。
% cd ~
% wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.2.4/EasyRSA-3.2.4.tgz
% tar xf EasyRSA-3.2.4.tgzEasyRSA の初期設定を行う
~/EasyRSA-3.2.4/vars を以下の内容で作成した。
PROVINCE には都道府県、CITY には市を入れておけば良いと思う。
set_var EASYRSA_REQ_COUNTRY "JP"
set_var EASYRSA_REQ_PROVINCE "Kanagawa"
set_var EASYRSA_REQ_CITY "Yokohama"
set_var EASYRSA_REQ_ORG "任意に"
set_var EASYRSA_REQ_EMAIL "管理者メールアドレス"
set_var EASYRSA_REQ_OU ""
set_var EASYRSA_NO_PASS 1
set_var EASYRSA_CA_EXPIRE 3650
set_var EASYRSA_CERT_EXPIRE 3650
set_var EASYRSA_AUTO_SAN 1
set_var EASYRSA_DIGEST "sha512"EasyRSA の初期化とオレオレ認証局の作成
% cd ~/EasyRSA-3.2.4
% ./easyrsa init-pki
Using Easy-RSA 'vars' configuration:
* ~/EasyRSA-3.2.4/vars
WARNING!!!
You are about to remove the EASYRSA_PKI at:
* ~/EasyRSA-3.2.4/pki
and initialize a fresh PKI here.
Type the word 'yes' to continue, or any other input to abort.
Confirm removal: yes
Notice
------
'init-pki' complete; you may now create a CA or requests.
Your newly created PKI dir is:
* ~/EasyRSA-3.2.4/pki
Using Easy-RSA configuration:
* ~/EasyRSA-3.2.4/vars これで EasyRSA が初期化される。
既に CA やらサーバー証明書を作成している状態でこれを行うと全て消え去るので要注意。
オレオレ認証局を作成する
% ./easyrsa build-ca
Using Easy-RSA 'vars' configuration:
* ~/EasyRSA-3.2.4/vars
......+.+..+............+.+...+.....+++++++++++++++++++++++++++++++++++++++*....+...+..+...+.+..+....+......+...+......+........+.+.....+......+...+.+.........+..+.+..+.....................+....+...+...+...........+...+...+++++++++++++++++++++++++++++++++++++++*...+.....+......+.............+..+.......+........+....+...........+............+.+.....+..........+...........+...............+.+..............+.+..+...+.......+........+..........+...+.....+.+...+...+.........+........+.+............+..+...+...+....+..+.........+..........+..+.........+...+.......+...+...+..+......+................+......+...+.....+.+..............+......+....+..+.......+.....+...+....+.........+..............+.+..+..........+...+............+...+.........+..........................................+.....+....+....................+....+...+........+......+...++++++
....+............+.....+.+........+......+......+.............+++++++++++++++++++++++++++++++++++++++*.+.+..+....+...+........+...+.+.........+.....+....+++++++++++++++++++++++++++++++++++++++*.+....+.....+......+....+..+...+.......+.........+..............+.......+..+............+...+.+..+...+............+..........+..+.............+..+.......+.....+...++++++
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.
-----
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:OreOreCA
Notice
------
CA creation complete. Your new CA certificate is at:
* ~/EasyRSA-3.2.4/pki/ca.crt
Build-ca completed successfully.
これを実行すると Common Name を入力するように促されるが、認証局名として何か入れておくと良いだろう。
サーバー証明書を発行する
単一ホスト向け証明書の場合
まず証明書署名要求を作成。
% ./easyrsa gen-req example.com
Using Easy-RSA 'vars' configuration:
* ~/EasyRSA-3.2.4/vars
....+......+....+.....+............+...+.+...+...........+++++++++++++++++++++++++++++++++++++++*.+.+.....+....+...+..............+...+.+..+.......+...+........+.+...+........+.........+++++++++++++++++++++++++++++++++++++++*...+.....................+...+.
.+...+...............+......+...+..........+..+...+......+.......+...+..++++++
.+......+.........+...+......+.....+++++++++++++++++++++++++++++++++++++++*...............+.....+.......++++++++++++++++++++++++
+++++++++++++++*.+..........+...+........+.+........+.+.........+.....+.......+.........+.....+.......+...+..+.........+..........+......+..++++++
-----
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.
-----
Common Name (eg: your user, host, or server name) [example.com]:
Notice
------
Private-Key and Public-Certificate-Request files created.
Your files are:
* req: ~/EasyRSA-3.2.4/pki/reqs/example.com.req
* key: ~/EasyRSA-3.2.4/pki/private/example.com.keyそしてサーバー用として署名を行う事になる。
% ./easyrsa sign-req server example.com
Using Easy-RSA 'vars' configuration:
* ~/EasyRSA-3.2.4/vars
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.
You are about to sign the following certificate:
Requested CN: 'example.com'
Requested type: 'server'
Valid for: '3650' days
subject=
commonName = example.com
X509v3 Subject Alternative Name:
DNS:example.com
Type the word 'yes' to continue, or any other input to abort.
Confirm requested details: yes
Using configuration from /home/bucci/EasyRSA-3.2.4/pki/9d2e3ea9/temp.02
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'example.com'
Certificate is to be certified until Nov 23 03:05:42 2035 GMT (3650 days)
Write out database with 1 new entries
Database updated
WARNING
=======
INCOMPLETE Inline file created:
* ~/EasyRSA-3.2.4/pki/inline/private/example.com.inline
Notice
------
Certificate created at:
* ~/EasyRSA-3.2.4/pki/issued/example.com.crt
これで example.com.key と example.com.crt が完成したので、Web サーバーの設定に書いてやれば OK。
ワイルドカード証明書とか複数ホスト用としたい場合
EasyRSA に対し --subject-alt-name オプションを用いることで複数ホスト用の証明書を作成することが出来る。
例として example.com と *.example.com で使いたい証明書を発行してみる。
% ./easyrsa --subject-alt-name="DNS:example.com,DNS:*.example.com" gen-req example.comとしてから
% ./easyrsa --subject-alt-name="DNS:example.com,DNS:*.example.com" sign-req server example.com として署名すると SANs に 2 つのホスト名が記載された証明書が作成できる。
もちろん片方はワイルドカードなので任意のサブドメインをこの 1 つの証明書でカバー出来る。
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
77:98:ce:93:27:88:34:3e:93:a3:c3:4a:a8:b6:9a:7d
Signature Algorithm: sha512WithRSAEncryption
Issuer: CN=OreOreCA
Validity
Not Before: Nov 25 03:14:50 2025 GMT
Not After : Nov 23 03:14:50 2035 GMT
Subject: CN=exmaple.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:fd:0f:b9:1b:75:df:cf:cb:52:44:1e:78:0b:ea:
(Snip...
03:3a:90:a3:68:21:5c:6c:23:49:59:f5:13:70:e9:
f8:b9
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Subject Key Identifier:
97:23:28:D0:B2:8F:23:43:8F:FD:D7:2F:39:6F:F6:09:45:34:AE:51
X509v3 Authority Key Identifier:
keyid:02:07:AE:C3:DF:BA:56:E8:29:5B:E5:87:6B:5C:A7:ED:A5:44:1D:4C
DirName:/CN=OreOreCA
serial:69:37:E0:E4:23:E3:76:B4:97:51:D9:52:31:F6:62:B1:28:EC:D8:0B
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Alternative Name:
DNS:example.com, DNS:*.example.com
Signature Algorithm: sha512WithRSAEncryption
Signature Value:
c3:51:6f:43:39:f0:92:b0:0f:69:b2:1b:36:0c:ca:93:aa:ef: これも同様に example.com.key と example.com.crt が出来上がるので、Web サーバーの設定に書いてやれば OK。
おわりに
数ステップでサクーッと証明書が作れてしまうので EasyRSA はとても便利。
内部管理用サイトとか検証用ホストが増えても安心。



コメント