そういうのがいいブログ

SIerで働く30代サラリーマンSEがインフラエンジニアに憧れてLinux・クラウド・AWSの勉強をするブログ

有効期限が切れたサーバ証明書の更新手順(その2)WEBサーバ

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

有効期限が切れたサーバ証明書の更新手順を知りたい。

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

本記事の内容

  1. 有効期限が切れたサーバ証明書の更新手順

サトナカ (@souiunogaii)

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

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

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

有効期限が切れたサーバ証明書の更新手順

社内ローカルの環境のWEBサーバ、メールサーバ、GitLabサーバの各サーバの証明書が有効期限切れになりました。
毎年、12月に更新をしています。

毎年の作業なので、自分のメモ用に作業手順を記事にておきます。

前回までの手順

前回の手順で、ルートCAの自己証明書と、中間CAの証明書を更新しました。

souiunogaii.hatenablog.com

WEBサーバの証明書を更新

WEBサーバの秘密鍵と署名要求CSRファイルを同時に作成

SSLEAY_CONFIG="-config /etc/pki/tls/openssl-req.cnf" /etc/pki/tls/misc/CA -newreq
[root@sv-neptune certs]# SSLEAY_CONFIG="-config /etc/pki/tls/openssl-req.cnf" /etc/pki/tls/misc/CA -newreq
Ignoring -days; not generating a certificate
Generating a RSA private key
...+++++
................................................+++++
writing new private key to 'newkey.pem'
Enter PEM pass phrase: ★★★秘密鍵のパスワード★★★
Verifying - Enter PEM pass phrase: ★★★秘密鍵のパスワード★★★
-----
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-ku
Organization Name (eg, company) [Default Company Ltd]:NEPTUNE Inc.
Organizational Unit Name (eg, section) []:NEPTUNE SYSTEM WEB1
Common Name (eg, your name or your server's hostname) []:*.sv-neptune.planet.space.com
Email Address []:webadmin@space.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: ☆☆☆何も入力せず[Enter]☆☆☆
An optional company name []: ☆☆☆何も入力せず[Enter]☆☆☆
Request is in newreq.pem, private key is in newkey.pem

WEBサーバの署名要求ファイルを、認証局サーバにアップロード

中間CAがWEBサーバからの署名要求CSRファイルに署名し、サーバ証明書を作成

 openssl ca -in /etc/pki/interCA/sv-neptune/newreq.pem \
-out /etc/pki/interCA/sv-neptune/newcert.pem \
-keyfile /etc/pki/interCA/private/interCA_key.pem \
-cert /etc/pki/interCA/interCA_cert.pem \
-config /etc/pki/tls/openssl-sv-neptune.cnf \
-policy policy_anything
[root@SV-IXION interCA]# openssl ca -in /etc/pki/interCA/sv-neptune/newreq.pem \
> -out /etc/pki/interCA/sv-neptune/newcert.pem \
> -keyfile /etc/pki/interCA/private/interCA_key.pem \
> -cert /etc/pki/interCA/interCA_cert.pem \
> -config /etc/pki/tls/openssl-sv-neptune.cnf \
> -policy policy_anything
Using configuration from /etc/pki/tls/openssl-sv-neptune.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 7 (0x7)
        Validity
            Not Before: Dec 18 00:39:00 2021 GMT
            Not After : Dec 18 00:39:00 2022 GMT
        Subject:
            countryName               = JP
            stateOrProvinceName       = Tokyo
            localityName              = Shinagawa-ku
            organizationName          = NEPTUNE Inc.
            organizationalUnitName    = NEPTUNE SYSTEM WEB1
            commonName                = *.sv-neptune.planet.space.com
            emailAddress              = webadmin@space.com
        X509v3 extensions:
            X509v3 Basic Constraints: critical
                CA:FALSE
            Netscape Cert Type:
                SSL Server
            X509v3 Key Usage: critical
                Digital Signature
            X509v3 Extended Key Usage:
                TLS Web Server Authentication, TLS Web Client Authentication
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                02:20:2F:FC:4A:FE:EE:E1:B3:C4:F4:A5:4A:2A:90:B8:B3:5B:05:D7
            X509v3 Authority Key Identifier:
                keyid:E1:27:D2:7C:8A:39:86:AA:51:44:CB:D5:B0:CF:16:34:A0:9A:94:77

            X509v3 Subject Alternative Name:
                DNS:*.sv-neptune.planet.space.com, DNS:takeuchiblog.space.com, DNS:*.takeuchiblog.space.com
Certificate is to be certified until Dec 18 00:39:00 2022 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

中間CAで作成した証明書ファイルをWEBサーバにアップロード

WEBサーバのApache再起動

テスト

[root@sv-neptune certs]# httpd -t
Syntax OK

秘密鍵ファイルのパスワード除去

 openssl rsa -in /etc/pki/tls/certs/newkey.pem -out /etc/pki/tls/certs/newkey.pem
[root@sv-neptune certs]# openssl rsa -in /etc/pki/tls/certs/newkey.pem -out /etc/pki/tls/certs/newkey.pem
Enter pass phrase for /etc/pki/tls/certs/newkey.pem: ★★★秘密鍵のパスワード★★★
writing RSA key

Apache再起動

systemctl restart httpd
systemctl status httpd
[root@sv-neptune certs]# systemctl restart httpd
[root@sv-neptune certs]#
[root@sv-neptune certs]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           mqphp-fpm.conf
   Active: active (running) since Sat 2021-12-18 09:44:42 JST; 13s ago
     Docs: man:httpd.service(8)
  Process: 358903 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 415613 (httpd)
   Status: "Running, listening on: port 443, port 80"
    Tasks: 213 (limit: 6565)
   Memory: 25.5M
   CGroup: /system.slice/httpd.service
           tq415613 /usr/sbin/httpd -DFOREGROUND
           tq415614 /usr/sbin/httpd -DFOREGROUND
           tq415615 /usr/sbin/httpd -DFOREGROUND
           tq415616 /usr/sbin/httpd -DFOREGROUND
           mq415617 /usr/sbin/httpd -DFOREGROUND

1218 09:44:42 sv-neptune systemd[1]: Starting The Apache HTTP Server...
1218 09:44:42 sv-neptune systemd[1]: Started The Apache HTTP Server.
1218 09:44:42 sv-neptune httpd[415613]: Server configured, listening on: port 443, port 80

WindowsPCの証明書ストアの更新

ルートCAの自己証明書をインポート

中間CAの証明書をインポート

ブラウザで表示確認