背景

サーバ証明書を作って欲しいという依頼があり、まずはCSRを作りました。

この記事はその備忘録です。

手順

自宅サーバのUbuntu22.04で作成しました。あまり知られてないですが、秘密鍵やCSRはどこで作成してもOKです。会社名はぼやかしてます。

サーバの秘密鍵作成

以下で作成します。セキュリティの強度をどこまで確保するかによりますが、運用としては秘密鍵のパスフレーズはない方が良いと思います。

openssl genrsa -aes256 2048 > company.co.jp.key

CSRの作成

上で作成した秘密鍵を使用して、CSRを作成します。

openssl req -new -key company.co.jp.key -out company.co.jp.csr -sha256
Enter pass phrase for company.co.jp.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) [AU]:JP
State or Province Name (full name) [Some-State]:osaka
Locality Name (eg, city) []:osaka
Organization Name (eg, company) [Internet Widgits Pty Ltd]:COMPANY ELECTRIC CORPORATION
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:company.co.jp
Email Address []:

確認

確認します。

openssl req -noout -text -in company.co.jp.csr 

以下のように表示されます。こんな感じで出力されると、CSR作成完了です。

Certificate Request:
    Data:
        Version: 1 (0x0)
        Subject: C = JP, ST = osaka, L = osaka, O = COMPANY ELECTRIC CORPORATION, CN = company.co.jp
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:d3:73:5f:c8:35:0d:96:09:4b:47:67:9b:5f:f9:
                    cc:d3:44:eb:98:7d:92:6e:26:7c:e8:e3:33:08:9f:
                    c2:e3:dc:6e:b8:0d:76:ff:cf:97:65:c1:19:71:c4:
                    69:65:e1:c3:12:c0:4a:f0:13:ca:b0:78:80:71:b4:
                    97:50:4e:e3:a3:b5:e8:7e:8c:50:ef:17:f8:99:59:
                    2e:3d:51:82:bf:ce:10:a2:96:82:0d:3f:1c:f2:3b:
                    d9:ce:cf:ad:c1:7b:90:5d:20:29:56:02:52:cf:f7:
                    65:bc:0b:b6:da:a6:75:3b:34:ee:7b:40:a0:f7:e6:
                    77:7e:4e:22:fa:94:4f:a0:5c:3e:1c:8e:60:6b:dc:
                    cd:af:89:7b:ea:a8:f3:73:44:c7:34:fc:02:e8:cf:
                    25:1a:5b:11:42:ad:58:1f:d8:04:a7:61:11:be:f0:
                    ee:b7
                Exponent: 65537 (0x10001)
        Attributes:
            (none)
            Requested Extensions:
    Signature Algorithm: sha256WithRSAEncryption
    Signature Value:
        ba:4d:5b:7a:a3:c2:e7:db:e8:af:97:9f:72:b1:11:4a:14:f2:
        4d:77:95:82:60:55:f6:fc:eb:fb:06:44:d3:29:55:db:10:d2:
        af:a5:51:d3:50:64:91:fe:b2:79:87:16:04:11:a7:f6:03:e1:
        46:b2:b1:4e:c6:e6:71:d3:3b:8b:5e:6e:d3:59:9a:52:4c:65:
        74:2e:df:5d:23:11:64:33:2b:77:10:7f:c4:93:1c:bc:b1:5c:
        cb:cb:26:cf:2b:09:52:c1:ae:be:0f:a4:1f:67:b1:53:fd:eb:
        d5:86:03:b5:9b:19:b6:bc:de:7a:e3:97:b1:53:20:80:e2:3f:
        a2:47:12:db:b4:b2:4c:db:b8:27:56:4e:2a:fc:80:ec:f5:a7:
        d0:bd:db:a3:e8:74:14:a3:90:1f:68:b0:b5:f6:99:ca:ec:55:
        54:7b:bd:f2

参考にしたURL

CSR作成時、参考にしたURLはこれです。

https://jprs.jp/pubcert/service/manual/