以下の内容はhttps://souiunogaii.hatenablog.com/entry/almalinux96-openssl-caより取得しました。


AlmaLinux9.6とOpenSSL3.2でプライベート認証局サーバーを構築

※[PR]当ブログの記事の中にはプロモーションが含まれています。

・AlmaLinux9.6とOpenSSL3.2でプライベート認証局サーバーを構築する方法を知りたい。
・具体的な手順を教えてほしい。

こういった疑問に答えます。

本記事の内容

  1. AlmaLinux9.6とOpenSSL3.2でプライベート認証局サーバーを構築する手順

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

AlmaLinux9.6とOpenSSL3.2でプライベート認証局サーバーを構築

OpenSSL3.2のインストール

dnf install openssl
openssl version
[root@a-prvca01 ~]# dnf install openssl
メタデータの期限切れの最終確認: 3:06:22 前の 20250831191950秒 に実施しました。
パッケージ openssl-1:3.2.2-6.el9_5.1.x86_64 は既にインストールされています。
依存関係が解決しました。
行うべきことはありません。
完了しました!
[root@a-prvca01 ~]# openssl version
OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)

プライベート認証局サーバーの構築(ルートCA)

/etc/pki/ca
[root@a-prvca01 ~]# cd /etc/pki
[root@a-prvca01 pki]# cd ca

CAの秘密鍵ファイルの作成

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out ca.key
[root@a-prvca01 ca]# openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out ca.key
....+..+.......+...............+...........+...+....+...+..+.+.....+......+....+.....+.+...+...+..+.............+..............+++++++++++++++++++++++++++++++++++++++*....+++++++++++++++++++++++++++++++++++++++*........+....+..+.+..+...+...+......+.+............+..+..................+.+......+...+...+..+...............+.............+........++++++
........+.......+...+...+...+..+.......+...............+++++++++++++++++++++++++++++++++++++++*...+.....+....+.........+..+......+...+....+........+...+....+..+.+.....+....+...+...........+.+...+........+.........+.+...+......+......+..+++++++++++++++++++++++++++++++++++++++*.+...+.....+.+.....+...+.+..+....+...+.................+......+.......+.....+.......+...+..+...+.+......+...........+.......+..+.+...............+...+......+.....+.+.....+...+.....................+...+...+....+........+...+...+.......+...+.....+.+.....+.........+.+..............+......+.+..+...+...+....+...+...+.........+.....+...............+......+....+...+.........+......+..+.+......+........+......................+.....+.........+..................................+........+.......+..+.........+.+.....+.+........+....+..+.+..+.......+.....+....+.....+.......+............+.....+...+...+.........+.......+......+...+...........+......+...............+...+....+...+...+..+.........+.+...+.........+..+...+.+............+........+....+..+...+............+.+..+.+......+........+..................+.........+...+..........+............+...........+...+....+..+....+...........+......+...+....+...+.....+...+....+...........+.........+.+..+....+.....+....+..+....+...+...+..+.+..+.......+..+...+.......+......+..+.............+.........+...+...+........+.........+.......+.........+.....+.+........+.+............+..+......+.......+...+......+...............+...+..+......+.......+..+....+..+.............+..+...+....+...+..+......+.........+......+......+.........+.+...+..+.+.....+.......+.................+.+...+......+.........+............+...+..+.........+..........+...........+...+.+........+......+....+..+.+.....+.............+.................+...+..........+.....+......+...+......+...............+.+...+...........+......+...............+.+.....+....+........+.+..+....+...+.....+......+.+........................+..+...+.+......+........+..........+.....+.........+..........+.....+.+......+......+..+...+....+......+..+...............+.+...........+.........+....+...+...+..+.......+...+.....+............+...+....+.........+..+.......+......+......+.....+......+...+....+..+.+..++++++

CAの自己証明書の作成

openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
[root@a-prvca01 ca]# 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) []:Tokyo
Locality Name (eg, city) [Default City]:Shinagawa
Organization Name (eg, company) [Default Company Ltd]:Blue-Planet
Organizational Unit Name (eg, section) []:SYSTEM
Common Name (eg, your name or your server's hostname) []:a-prvca01
Email Address []:root@blue-planet.internal

WEBサーバーで秘密鍵と署名要求ファイルを作成

/etc/pki/tls/certs
[root@a-webap01 ~]# cd /etc/pki/tls/certs

WEBサーバーの秘密鍵ファイルの作成

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out blue-planet.key
[root@a-webap01 certs]# openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out blue-planet.key
...+................+++++++++++++++++++++++++++++++++++++++*..+.........+.+...+++++++++++++++++++++++++++++++++++++++*.........+......+........+....+..+...+...+...............+.........+...+...+.......+............+...+.....+............+...............+....+..+...+.+........+.............+...+..+.......+...+..+..................++++++
.......+........+.......+++++++++++++++++++++++++++++++++++++++*...+...+...+.....+......+.+..+...............+......+.+++++++++++++++++++++++++++++++++++++++*.........+..........+......+...+..+.........+.+.........+..................+......+...........+....+.....+.......+........+.+...+...+.....+...+....+..+.........+......+....+......+.....+......+..........+..+.+.....+................+......+...............+..+.......+.........+..+.......+......+......+...+..+......+...+.+...+.....+................+......+...........+...+......+......+...+..........+.....+....+........++++++

サブジェクト代替名を入れるテキストファイルを作成

/etc/pki/tls/certs/subjectAltName.txt
[root@a-webap01 certs]# vi subjectAltName.txt
subjectAltName = DNS:blue-planet.internal, DNS:*.blue-planet.internal

WEBサーバーの書名要求ファイルを作成

openssl req -new -key blue-planet.key -out blue-planet.csr
[root@a-webap01 certs]# openssl req -new -key blue-planet.key -out blue-planet.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
Locality Name (eg, city) [Default City]:Shinagawa
Organization Name (eg, company) [Default Company Ltd]:Blue-Planet
Organizational Unit Name (eg, section) []:SYSTEM
Common Name (eg, your name or your server's hostname) []:a-webap01
Email Address []:root@blue-planet.internal

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

認証局サーバー(CA)で証明書ファイルを作成

 openssl x509 -req -days 390 -in blue-planet.csr -CA /etc/pki/ca/ca.crt -CAkey /etc/pki/ca/ca.key -out blue-planet.crt -extfile subjectAltName.txt
[root@a-prvca01 certs]# openssl x509 -req -days 390 -in blue-planet.csr -CA /etc/pki/ca/ca.crt -CAke
y /etc/pki/ca/ca.key -out blue-planet.crt -extfile subjectAltName.txt
Certificate request self-signature ok
subject=C=JP, ST=Tokyo, L=Shinagawa, O=Blue-Planet, OU=SYSTEM, CN=a-webap01, emailAddress=root@blue-planet.internal

証明書ファイルの内容の確認

openssl x509 -text -in blue-planet.crt --noout
[root@a-prvca01 certs]# openssl x509 -text -in blue-planet.crt --noout
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            15:8a:96:(中略)6:26:52
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=JP, ST=Tokyo, L=Shinagawa, O=Blue-Planet, OU=SYSTEM, CN=a-prvca01, emailAddress=root@blue-planet.internal
        Validity
            Not Before: Sep  1 00:26:03 2025 GMT
            Not After : Sep 26 00:26:03 2026 GMT
        Subject: C=JP, ST=Tokyo, L=Shinagawa, O=Blue-Planet, OU=SYSTEM, CN=a-webap01, emailAddress=root@blue-planet.internal
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:e4:af:3f:7e:d1:1f:27:97:ee:c4:86:e7:81:1f:
                    ac:55:1d:c1:6c:5c:5a:cc:95:ee:e3:a4:49:db:34:
      (中略)
                    b8:d6:77:6d:a7:4d:c3:ff:da:60:fd:76:d9:bd:a9:
                    cd:dd
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Alternative Name:
                DNS:blue-planet.internal, DNS:*.blue-planet.internal
            X509v3 Subject Key Identifier:
                36:72:(中略)D:43:59
            X509v3 Authority Key Identifier:
                DF:70:(中略)D:3B:39:FA
    Signature Algorithm: sha256WithRSAEncryption
    Signature Value:
        5b:ee:c4:57:01:28:53:76:01:f0:93:68:fb:ba:cd:0a:19:fe:
        1b:3a:6b:26:33:ef:6c:f4:44:6d:2f:3e:e2:d1:ea:81:0f:ed:
      (中略)
        ff:cc:44:bb:6f:83:a2:83:14:a7:91:74:fa:70:9c:0c:b7:f7:
        ae:3b:f0:cc

Windows端末にルートCAの証明書ファイルをインポート

作成したWEBサーバーの証明書の表示確認




以上の内容はhttps://souiunogaii.hatenablog.com/entry/almalinux96-openssl-caより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14