そういうのがいいブログ

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

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

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

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

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

本記事の内容

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

サトナカ (@souiunogaii)

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

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

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

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

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

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

前回までの手順

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

souiunogaii.hatenablog.com

メールサーバの証明書を更新

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

SSLEAY_CONFIG="-config /etc/pki/tls/openssl-req.cnf" /etc/pki/tls/misc/CA -newreq
[root@SV-CERES 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]:SPACE CO., Ltd.
Organizational Unit Name (eg, section) []:SPACE PLANET SYSTEM MAIL
Common Name (eg, your name or your server's hostname) []:sv-ceres.planet.space.com
Email Address []:mailadmin@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

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

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

openssl ca -in /etc/pki/interCA/sv-ceres/newreq.pem \
-out /etc/pki/interCA/sv-ceres/newcert.pem \
-keyfile /etc/pki/interCA/private/interCA_key.pem \
-cert /etc/pki/interCA/interCA_cert.pem \
-config /etc/pki/tls/openssl-sv-ceres.cnf \
-policy policy_anything
[root@SV-IXION sv-ceres]# openssl ca -in /etc/pki/interCA/sv-ceres/newreq.pem \
> -out /etc/pki/interCA/sv-ceres/newcert.pem \
> -keyfile /etc/pki/interCA/private/interCA_key.pem \
> -cert /etc/pki/interCA/interCA_cert.pem \
> -config /etc/pki/tls/openssl-sv-ceres.cnf \
> -policy policy_anything
Using configuration from /etc/pki/tls/openssl-sv-ceres.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 9 (0x9)
        Validity
            Not Before: Dec 18 01:55:54 2021 GMT
            Not After : Dec 18 01:55:54 2022 GMT
        Subject:
            countryName               = JP
            stateOrProvinceName       = Tokyo
            localityName              = Shinagawa-ku
            organizationName          = SPACE CO., Ltd.
            organizationalUnitName    = SPACE PLANET SYSTEM MAIL
            commonName                = sv-ceres.planet.space.com
            emailAddress              = mailadmin@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:
                7B:47:28:AE:70:1E:6E:5F:6C:DF:88:03:1B:12:DB:E7:62:37:82:71
            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-ceres.planet.space.com
Certificate is to be certified until Dec 18 01:55:54 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の証明書とメールサーバの証明書を1ファイルに結合

cat /etc/pki/interCA/sv-ceres/newcert.pem /etc/pki/interCA/interCA_cert.pem >> /etc/pki/interCA/sv-ceres/fullchaincert.pem
[root@SV-IXION sv-ceres]# cat /etc/pki/interCA/sv-ceres/newcert.pem /etc/pki/interCA/interCA_cert.pem >> /etc/pki/interCA/sv-ceres/fullchaincert.pem

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

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

メールサーバの再起動

systemctl restart postfix
systemctl status postfix
[root@SV-CERES certs]# systemctl restart postfix
[root@SV-CERES certs]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-12-18 11:02:01 JST; 7s ago
  Process: 181589 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS)
  Process: 181610 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 181608 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 181606 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 181679 (master)
    Tasks: 3 (limit: 1948)
   Memory: 5.9M
   CGroup: /system.slice/postfix.service
           tq181679 /usr/libexec/postfix/master -w
           tq181680 pickup -l -t unix -u
           mq181681 qmgr -l -t unix -u

1218 11:02:00 SV-CERES systemd[1]: Starting Postfix Mail Transport Agent...
1218 11:02:01 SV-CERES postfix/master[181679]: daemon started -- version 3.5.8, configuration /e>
1218 11:02:01 SV-CERES systemd[1]: Started Postfix Mail Transport Agent.
systemctl restart dovecot
systemctl status dovecot
[root@SV-CERES certs]# systemctl restart dovecot
[root@SV-CERES certs]# systemctl status dovecot
● dovecot.service - Dovecot IMAP/POP3 email server
   Loaded: loaded (/usr/lib/systemd/system/dovecot.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-12-18 11:02:46 JST; 6s ago
     Docs: man:dovecot(1)
           http://wiki2.dovecot.org/
  Process: 181687 ExecStop=/usr/bin/doveadm stop (code=exited, status=0/SUCCESS)
  Process: 181692 ExecStartPre=/usr/libexec/dovecot/prestartscript (code=exited, status=0/SUCCESS)
 Main PID: 181698 (dovecot)
    Tasks: 4 (limit: 1948)
   Memory: 13.3M
   CGroup: /system.slice/dovecot.service
           tq181698 /usr/sbin/dovecot -F
           tq181701 dovecot/anvil
           tq181702 dovecot/log
           mq181703 dovecot/config

1218 11:02:45 SV-CERES systemd[1]: Starting Dovecot IMAP/POP3 email server...
1218 11:02:46 SV-CERES systemd[1]: Started Dovecot IMAP/POP3 email server.
1218 11:02:47 SV-CERES dovecot[181698]: master: Dovecot v2.3.8 (9df20d2db) starting up for imap,>

メールソフト(Thunderbird)で確認

メール送受信しようとすると、以下エラーがでます。

セキュリティ例外を承認

「セキュリティ例外を承認」ボタンをクリックします。

証明書マネージャーにルートCAの自己証明書と中間CAの証明書を追加