FreeBSD 14
Sponsored Link

SSL 証明書を作成する (自己署名)2023/12/20

  SSL/TLS を用いた信頼性の高い暗号化通信を構築するために必要な証明書を作成します。
当例では自己署名の独自証明書を作成します。 ただし、自己署名の証明書はアクセス時に警告が出るため、一般的にはその先には進んでもらえないでしょう。 よって、自己署名の証明書は、開発やテスト目的での内部ネットワーク利用に限り、 不特定多数からアクセスされるネットワーク上で利用する場合は、正規の認証局が発行する証明書を利用した方がよいでしょう。
root@dlp:~ #
vi /etc/ssl/openssl.cnf
# 最終行に追記
# セクション名は任意
# DNS:(自身のホスト名)
# DNS を複数指定する場合はカンマ区切り
# ⇒ DNS:dlp.srv.world, DNS:www.srv.world

[ srv.world ]
subjectAltName = DNS:dlp.srv.world

root@dlp:~ #
mkdir /usr/local/etc/ssl

root@dlp:~ #
cd /usr/local/etc/ssl

root@dlp:/usr/local/etc/ssl #
openssl ecparam -name prime256v1 -genkey -out server.key

root@dlp:/usr/local/etc/ssl #
openssl req -new -key server.key -out 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) [AU]:JP                            # 国
State or Province Name (full name) [Some-State]:Hiroshima       # 地域(県)
Locality Name (eg, city) []:Hiroshima                           # 都市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:GTS  # 組織名
Organizational Unit Name (eg, section) []:Server World          # 組織の部門名
Common Name (e.g. server FQDN or YOUR name) []:dlp.srv.world    # サーバーの FQDN
Email Address []:root@srv.world                                 # 管理者アドレス

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

# 有効期限が 10 年の自己署名証明書を作成
# -extensions (セクション名) ⇒ [openssl.cnf] に追記したセクション名

root@dlp:/usr/local/etc/ssl #
openssl x509 -in server.csr -out server.crt -req -signkey server.key -extfile /etc/ssl/openssl.cnf -extensions srv.world -days 3650

Certificate request self-signature ok
subject=C = JP, ST = Hiroshima, L = Hiroshima, O = GTS, OU = Server World, CN = dlp.srv.world, emailAddress = root@srv.world

root@dlp:/usr/local/etc/ssl #
ls -l

-rw-r--r--  1 root wheel 1424 Dec 20 15:21 server.crt
-rw-r--r--  1 root wheel 1062 Dec 20 15:21 server.csr
-rw-------  1 root wheel 1704 Dec 20 15:20 server.key
関連コンテンツ