Table of Contents

ここ数年利用しているFujiSSL、毎年証明書を手作業で更新していたが自動更新に対応したということで実装しました。

本稿では下記前提条件で説明します。

  • FQDN
    • foo.jp
  • クライアントインストール先
    • /var/sslautorenew
  • 証明書パス
    • /etc/pki/tls

SSLストアとFujiSSL

私はこれまでFujiSSLの証明書を「SSLストア」から購入していました。おそらくこれまでは別の購買ルートは無かったと思います。

しかし、自動更新対応により「FujiSSL」からも購入が可能となり自動更新の仕組みもそれぞれ別個に用意されています。また自動更新のツール類は名前が違うだけで両者同じものと見受けられます。ここのところがややこしい点です。私はSSLストアにデポジットを残していたのでその金額をFujiSSLで使えるのかをFujiSSLに質問したら両者で連携はしていないということでした。

「SSLストア」にデポジット金額が残っているので、SSLストアで自動更新を行うこととしました。「FujiSSL」でもツールのファイル名が違うだけで手順は同じだと思われます。自動更新ツールは2社別々ですが証明書発行のやり取りは「FujiSSL」とやることになります。

SSLストアおよびFujiSSLとのやり取り

  • 証明書発行費用支払い(SSLストア)-> 注文コード発行
  • ツールから登録「sslstore-client regist」-> 証明書発行通知メールで証明書が発行
  • ツールからcronにより自動更新「sslstore-client autorenew」 -> 証明書更新完了通知メールが来る

自動更新クライアントのインストール

SSLストアからダウンロードできるFujiSSL自動更新クライアントをインストールディレクトリは下記とします。
/var/sslautorenew

/var/sslautorenew/sslstore-client-tool-0.0.1

# cd /var/sslautorenew
# wget https://www.ssl-store.jp/system/files/sslstore-client-tool-0.0.1.zip
# unzip sslstore-client-tool-0.0.1.zip
# chmod -R 0644 sslstore-client-tool-0.0.1

				
					
[/var/sslautorenew]
├ [sslstore-client-tool-0.0.1]
│ ├ [bin]
│ │ ├ sslstore-client
│ ├ [conf]
│ │ ├ default.conf.master
│ │ ├ foo.conf ※この後の処理で作成
│ ├ [lib]
│ │ ├ Cache.php
│ │ ├ CmdClear.php
│ │ ├ CmdCreate.php
│ │ ├ CmdHelp.php
│ │ ├ Config.php
│ │ ├ Fhandle.php
│ │ ├ Log.php
│ │ ├ Openssl.php
│ ├ [src]
│ ├ Application.php
│ ├ Constant.php
│ ├ Directory.php
│ ├ Request.php
│ ├ Router.php
├ [backup] ※この後の処理で作成
				
			

設定ファイルの作成

				
					# cd /var/sslautorenew/sslstore-client-tool-0.0.1
# php ./bin/sslstore-client create foo
Created the /var/sslautorenew/sslstore-client-tool-0.0.1/.lock directory.
Created the /var/sslautorenew/sslstore-client-tool-0.0.1/.logs directory.
設定ファイルを作成しました。(/var/sslautorenew/sslstore-client-tool-0.0.1/conf/foo.conf)

				
			

設定ファイルの編集

./conf/foo.conf

変更前

				
					
config:
  appid:  <契約コード(APP-XXXXXXXXXXXXXXX)>
  ordid:  <注文コード(ORD-XXXXXXXXXXXXXXX)>
  fqdn: <コモンネーム>
  document_root: <ドキュメントルート>
  backup_dir: <バックアップディレクトリ>
  private_key:  <秘密鍵ファイル名>
  certificate:  <証明書ファイル名>
  ca_bundle:  <中間証明書ファイル名>


				
			

変更後

証明書の登録

				
					
config:
  appid: APP-Tcs8Yxxxxx..
  ordid: ORD-TBCdyxxxxx..
  fqdn: www.foo.jp
  document_root: /var/www/html/3.0.14/html
  backup_dir: /var/sslautorenew/backup
  private_key: /etc/pki/tls/private/localhost.key
  certificate: /etc/pki/tls/certs/localhost.crt
  ca_bundle: /etc/pki/tls/certs/ca-bundle.crt


				
			

※ コマンド実行前の設定
FujiSSLの制約で、wwwありとwwwなしの両方で存在確認ファイルにアクセスできなければならない。最初はwwwありURLからのアクセスができない状態だったのでエラーとなる。

失敗例

				
					# php ./bin/sslstore-client regist -c www.foo.jp -f ./conf/foo.conf
PHP Fatal error: (E2001) Can not access the authentication URL. '(http|https)://foo.jp/.well-known/pki-validation/fileauth.txt' in /var/sslautorenew/sslstore-client-tool-0.0.1/bin/sslstore-client on line 61

				
			

その後、SSLストアにエラーを報告したところ、wwwありURLのアクセスを有効にしなければならないということだったので、httpdのconfigを修正して再度チャレンジ。

成功例

				
					
# php ./bin/sslstore-client regist -c www.foo.jp -f ./conf/foo.conf
Create /var/www/html/3.0.14/html/.well-known/pki-validation/fileauth.txt file.
Create /var/sslautorenew/backup/localhost.key file.
The certificate registed was successful.
Register the following command in cron:
/usr/bin/php /var/sslautorenew/sslstore-client-tool-0.0.1/bin/sslstore-client autorenew -c www.foo.jp -f ./conf/foo.conf


				
			

SSLストアの管理画面で「注文番号」がブランクから証明書番号が登録されたことが確認できた。

ファイル認証

sslstore-client registコマンドによる証明書の登録が失敗したときはwell-known/pki-validation/fileauth.txtに認証ファイルが以下の内容で作成された。このような単純な文字列でよいのかと疑問だったが・・

				
					fujissl-acme-auth-text
				
			

証明書の登録が成功すると次のように正しい認証コード(?)に置き換わっていた。

				
					2021xxxxxx(中略)xxxxxxxx488F
				
			

証明書発行メール受領

証明書の登録が完了するとほどなく、FujiSSLから証明書発行メールが届く。

このメールに「SSLサーバ証明書」と「中間CA証明書」が添付されているが、この後設定するcronによるautorenew処理でサーバー内の証明書が自動更新されるのでそのまま放置。

定期実行(CRON)にコマンドを登録

SSLストアのマニュアルには下記のように例示されている。

				
					/usr/bin/php /var/sslautorenew/sslstore-client-tool-0.0.1/bin/sslstore-client autorenew -c www.foo.jp -f /var/sslautorenew/sslstore-client-tool-0.0.1/conf/foo.conf > /dev/null 2>&1 <サーバ再起動コマンド>
				
			

この設定では毎回httpdサーバの再起動が指定されているが、そのようなことはしたくないので再起動は手作業で行うこととしました。

なお、Let’s Encryptで使用されるcerbotコマンドには証明書を更新したときだけ再起動コマンドを実行するように指定できるようです。FujiSSLのツールにもそのようなオプションが欲しいです。

参考までに私のcron設定です。

/etc/crontab

				
					
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

  0  15 *  *  * root /usr/bin/php /var/sslautorenew/sslstore-client-tool-0.0.1/bin/sslstore-client autorenew -c www.foo.jp -f /var/sslautorenew/sslstore-
client-tool-0.0.1/conf/foo.conf


				
			

autorenewコマンド実行確認

翌日15時のcronログを確認、autorenewコマンドが実行されている。

				
					May  7 14:01:01 ip-172-30-1-186 run-parts(/etc/cron.hourly)[22711]: finished 0anacron
May  7 15:00:01 ip-172-30-1-186 CROND[22985]: (root) CMD (/usr/bin/php /var/sslautorenew/sslstore-client-tool-0.0.1/bin/sslstore-client autorenew -c www.foo.jp -f /var/sslautorenew/sslstore-client-tool-0.0.1/conf/foo.conf)
May  7 15:01:01 ip-172-30-1-186 CROND[22989]: (root) CMD (run-parts /etc/cron.hourly)
				
			

cronからのコマンド実行後、即座にFujiSSLから下記のようにメール到着。

autorenewコマンドは毎日実行するが、実際に証明書が更新されるのは年1回。更新されたときにこのようなメール届いてくれるなら、このメールを確認してからマニュアルでサーバーを再起動すれば良いと思う。(cronで毎日勝手にサーバー再起動されても構わないサイトならそれでも良いが)

SSLストア::自動更新ツールからの通知
受信トレイ

SSLストア <info@ssl-store.info>

15:00 (1 時間前)

To 自分

※このメールは送信専用です。
———————————————-
ご担当者様

この度はFujiSSLをご利用ありがとうございます。

www.foo.jpの証明書の更新が完了しましたので、ご案内致します。

つきましては、新しい有効期限にて証明書が
反映されているかご確認頂けますようご案内致します。

証明書のタイムスタンプを見ると書き換えられていることがわかる。

/etc/pki/tls/certs

				
					-rw------- 1 root root   2340 May  7 15:00 localhost.crt
				
			
				
					
[root@www certs]# ls -l
total 1164
lrwxrwxrwx 1 root root     49 Apr 17  2017 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
-rw-r--r-- 1 root root 750014 Jun  2  2020 ca-bundle.crt.rpmnew
lrwxrwxrwx 1 root root     55 Apr 17  2017 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rw-r--r-- 1 root root 418466 Jun  2  2020 ca-bundle.trust.crt.rpmnew
-rw------- 1 root root   2340 May  7 15:00 localhost.crt
-rwxr-xr-x 1 root root    610 Dec  8 08:18 make-dummy-cert
-rw-r--r-- 1 root root   2516 Dec  8 08:18 Makefile
-rwxr-xr-x 1 root root    829 Dec  8 08:18 renew-dummy-cert
[root@www certs]# cd /etc/pki/ca-trust/extracted/pem/
[root@www pem]# ls -l
total 340
-r--r--r-- 1 root root 192727 Jan  5 16:48 email-ca-bundle.pem
-r--r--r-- 1 root root 142700 Jan  5 16:48 objsign-ca-bundle.pem
-rw-r--r-- 1 root root    897 Jun  2  2020 README
-r--r--r-- 1 root root   3277 May  7 15:00 tls-ca-bundle.pem
				
			

バックアップも自動で取られている。localhost.crtが新しいもので、localhost.crt.0000が古い証明書。

/var/sslautorenew/backup/

				
					
[root@www certs]# ls -l /var/sslautorenew/backup/
total 248
-rwx------ 1 root root   3277 May  7 15:00 ca-bundle.crt
-rw-r--r-- 1 root root 229558 May  7 15:00 ca-bundle.crt.0000
-rwx------ 1 root root   2340 May  7 15:00 localhost.crt
-rw-r--r-- 1 root root   1521 May  7 15:00 localhost.crt.0000
-rwx------ 1 root root   1704 May  6 23:09 localhost.key
-rw-r--r-- 1 root root   1675 May  7 15:00 localhost.key.0000
				
			

サーバ再起動前

サーバ再起動後

参考 : FujiSSLさんへの質問と回答

お問合せの件につきまして返答致します。

質問1)
confに設定する「注文コード」は「Fuji SSL Management Console」から証明書を購入して初めて発行されるのでしょうか?
→上記ご説明の通りでお間違いございません。

質問2)
これまで利用していたSSLストアには「デポジット残高」が残っていますが、「Fuji SSL Management Console」のデポジットは0円です。連携していないのでしょうか?
→FujiSSL Management Consoleは別のサービスになります為、連携はしておりませんが、SSLストアからもFujiSSL-GOと同様に自動更新サービスをご利用可能でございます。
 詳細につきましては管理画面の証明書の項目にある「自動更新」メニューのページにドキュメントがございますので、こちらをご確認ください。

 

質問3)
仮に「Fuji SSL Management Console」で1年分の料金を支払って注文コードが発行されたとした場合、翌年になって再度購入処理をすると前年とは別の注文コードが発行されるのでしょうか?
→発行されません。
 同じ注文コードにて処理されます。
 また更新の際にはデポジットから証明書代金が毎年差し引かれますので、併せてご報告致します。

以上、宜しくお願い致します。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

上部へスクロール