最終更新日: 2019年6月16日

自己証明書の作成方法


1) サーバー・プライベートキー作成

HAProxy用の電子証明書の基となるプライベートキーを作成します。 ここでは鍵の長さを2048として作成します。(以前は、1024の長さが推奨されていたが、現在は2048より短いものは推奨されていない)
# openssl genrsa 2048 > /etc/haproxy/haproxy_server.key


2. 証明書署名要求(CSR)の作成

プライベートキーに対応する電子証明書をつくってもらうための要求書を作成する。コマンド入力後に証明書に記録する情報を求めてくるので、Common Name以外は適当に入力してください。
Common Nameにはワイルドカードと証明書を作るので "*.ドメイン名" の形式で指定します。
# openssl req -new -key /etc/haproxy/haproxy_server.key > haproxy_server.csr
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) [XX]:JP
State or Province Name (full name) []:Tokyo-to
Locality Name (eg, city) [Default City]:Minato-ku
Organization Name (eg, company) [Default Company Ltd]:Example
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:*.example.jp
Email Address []:webmaster@example.jp

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

3. 証明書署名要求(CSR)から証明書を作成

CSRから電子証明書を作成します。 なお今回は自己証明書なので、自分のサーバキーを使い署名します。
# openssl x509 -days 1826 -req -signkey /etc/haproxy/haproxy_server.key < haproxy_server.csr > haproxy_server.crt


4. プライベートキーと証明書をマージしてpem形式の証明書を作成

# cat /etc/haproxy/haproxy_server.key haproxy_server.crt > /etc/haproxy/haproxy_server.pem
ここで作成された haproxy_server.pem ファイルをHAProxy用の電子証明書証明書として使用します。



参考: