0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenSSL 3.0.7によるCA証明書、SSL証明書の作成 (AlmaLinux 9.4)

Last updated at Posted at 2024-08-07

はじめに

OpenSSLを用いてCA証明書、SSL証明書を作成する手順について備忘録として記載する。

環境

AlmaLinux 9.4
OpenSSL 3.0.7

OpenSSLのインストール

$ sudo dnf install openssl
  • OpenSSLのバージョン確認
    • OpenSSL 3.0.7がインストールされている
$ openssl version
OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022)

CA証明書の作成

  • 秘密鍵の作成
    • -algorithm RSA:アルゴリズム RSA
    • -pkeyopt rsa_keygen_bits:2048:鍵長 2048bit
    • -out ca.key:ca.keyとして出力
$ openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out ca.key
  • 証明書(CRT)の作成
    • 上記で作成した秘密鍵(ca.key)を用いてCRTを作成する
    • -x509:自己署名証明書(オレオレ証明書)にする
    • -days 3650:有効期限 3650日(10年)
    • -out ca.crt:ca.crtとして出力
$ openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
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) []:Kanagawa                  // 都道府県
Locality Name (eg, city) [Default City]:Kawasaki                // 市町村
Organization Name (eg, company) [Default Company Ltd]:xxx       // 会社
Organizational Unit Name (eg, section) []:xxx                   // 部門
Common Name (eg, your name or your server's hostname) []:server // コモンネーム
Email Address []:xxx@xxx.com                                    // メールアドレス
  • ファイルの確認
$ ll
-rw-r--r--. 1 xxxx xxxx      1452  8月  7 11:19 ca.crt
-rw-------. 1 xxxx xxxx      1704  8月  7 11:10 ca.key

SSL証明書の作成

  • 秘密鍵の作成
    • -algorithm RSA:アルゴリズム RSA
    • -pkeyopt rsa_keygen_bits:2048:鍵長 2048bit
    • -out server.key:server.keyとして出力
$ openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out server.key
  • 証明書署名要求(CSR)の作成
    • 上記で作成した秘密鍵(server.key)を用いてCSRを作成する
    • -out server.csr:server.csrとして出力
$ 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) [XX]:JP                            // 国
State or Province Name (full name) []:Kanagawa                  // 都道府県
Locality Name (eg, city) [Default City]:Kawasaki                // 市町村
Organization Name (eg, company) [Default Company Ltd]:xxx       // 会社
Organizational Unit Name (eg, section) []:xxx                   // 部門
Common Name (eg, your name or your server's hostname) []:server // コモンネーム
Email Address []:xxx@xxx.com                                    // メールアドレス

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
  • 証明書(CRT)の作成
    • 上記で作成した秘密鍵(server.key)、証明書署名要求(server.csr)を用いてCRTを作成する
    • x509:自己署名証明書(オレオレ証明書)にする
    • -days 365:有効期限 365日(1年)
    • -in server.csr:証明書署名要求
    • -CA ca.crt:認証局のCA証明書
    • -CAkey ca.key:認証局の秘密鍵
    • -CAcreateserial:発行済みシリアルナンバーを保持するファイルca.srlを作成
    • -out server.crt:server.crtとして出力
$ openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt
Certificate request self-signature ok
subject=C = JP, ST = Kanagawa, L = Kawasaki, O = xxx, OU = xxx, CN = server, emailAddress = xxx@xxx.com
  • ファイルの確認
$ ll
-rw-r--r--. 1 xxxx xxxx   41  8月  7 12:20 ca.srl
-rw-r--r--. 1 xxxx xxxx 1269  8月  7 12:20 server.crt
-rw-r--r--. 1 xxxx xxxx 1029  8月  7 12:14 server.csr
-rw-------. 1 xxxx xxxx 1704  8月  7 12:13 server.key
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?