LoginSignup
5
5

More than 3 years have passed since last update.

certtoolで作る自己認証局署名の証明書の期限の限界は9999年だった

Last updated at Posted at 2016-12-28

ほんとか?と思って納会のさなかに遊んでみたところ本当だったので投下してみます。
環境はCentOS7です。

自己CA局の鍵と証明書を作る必要がある

てけとうなディレクトリ掘って作業
設定ファイル /etc/pki/tls/openssl-ca.cnf はこちらを参考に作成
https://bucci.bp7.org/archives/30220

# cd hoge

# openssl genrsa -des3 -out ./ca.key 2048 -config /etc/pki/tls/openssl-ca.cnf 
Enter pass phrase for ./ca.key:*****
# openssl req -new -x509 -days 3650 -sha256 -key ./ca.key -out ./ca.crt -config /etc/pki/tls/openssl-ca.cnf
Enter pass phrase for ./ca.key:*****
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) [JP]:
State or Province Name (full name) [Tokyo]:
Locality Name (eg, city) [****bashi]:
Organization Name (eg, company) [****Corporation]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:

# openssl x509 -inform pem -in ./ca.crt -outform der -out ./ca.der
# cp ca.key /etc/pki/CA/private/
# cp ca.crt /etc/pki/CA/
# cp ca.crt /usr/share/pki/ca-trust-source/anchors/
# update-ca-trust extract
# touch /etc/pki/CA/index.txt
# echo 01 > /etc/pki/CA/serial

opensslコマンドだと2049年が限界だった模様

※csr作るとかは最後のあたりの参考サイトでもどうぞ。

# openssl ca -in ../server.csr -keyfile /etc/pki/CA/private/ca.key -cert /etc/pki/CA/ca.crt -startdate 161228000000Z -enddate 491231235959Z -out server.crt -config /etc/pki/tls/openssl-server.cnf
~略~
            Not Before: Dec 28 00:00:00 2016 GMT
            Not After : Dec 31 23:59:59 2049 GMT
~略~

-enddate 501231235959Zにすると1950年になってた。それ以上も同様に1900年代。

certtoolを使いたいのでgnutlsとそのutilityを入れる

certtoolはcentosだとgnutls-utilsというpackageに入ってました。gnutlsはすでに入ってた。

# yum install gnutls-utils
# rpm -qa|grep gnutls
gnutls-utils-3.3.24-1.el7.x86_64
gnutls-dane-3.3.24-1.el7.x86_64
gnutls-3.3.24-1.el7.x86_64
# rpm -ql gnutls-utils-3.3.24-1.el7.x86_64
~略~
/usr/share/doc/gnutls-utils-3.3.24/certtool.cfg

certtool用のtemplateを準備

# cp -p /usr/share/doc/gnutls-utils-3.3.24/certtool.cfg .
# diff /usr/share/doc/gnutls-utils-3.3.24/certtool.cfg certtool.cfg
~略~
65,66c65,66
< #activation_date = "2004-02-29 16:21:42"
< #expiration_date = "2025-02-29 16:24:41"
---
> activation_date = "2016-12-28 00:00:00"
> expiration_date = "9999-12-31 23:59:59"
~略~

日にちの設定以外はマニュアルの最後のあたりでもみててきとうに。
http://www.gnutls.org/manual/html_node/certtool-Invocation.html

certtoolで自己認証局で9999年まで有効な証明書をつくる

すでにca証明書とca鍵はあるのでそれと作った設定ファイルとcsrを使ってマニュアル見て証明書を作ってみる

# certtool --generate-certificate --load-request server.csr \
   --outfile server.crt --load-ca-certificate /etc/pki/CA/ca.crt \
   --load-ca-privkey /etc/pki/CA/private/ca.key --template certtool.cfg
~略~
        Validity:
                Not Before: Tue Dec 27 15:00:00 UTC 2016
                Not After: Fri Dec 31 23:59:59 UTC 9999
~略~

あまりみかけない年が表示されていました。
念のためopensslコマンドのtextオプションでみてみます

# openssl x509 -text -noout -in server.crt |grep -A 3 Validity
        Validity
            Not Before: Dec 27 15:00:00 2016 GMT
            Not After : Dec 31 23:59:59 9999 GMT
        Subject: C=JP, ST=Tokyo, L=****bashi, O=****Corporation, OU=****, CN=*.hoge.net

あら本当でした。
(ちなみにUTCにしたせいかブラウザ(Chrome)からみると「‎10000‎年‎1‎月‎1‎日 8:59:59」になっていました)
letsencryptとかで自動更新するよりもサービスが廃れる可能性を考えると確実かも?
自社内でつかうワイルドカード証明書とかならこれで数十代あとの子孫までいけそうでしょうか。
実質期限監視いらないかな。(商用サイトは自己認証局とかしないと思うので関係なさそうですが)
あとopensslコマンドで作ったやつは2050年問題がでて、certtoolで作ったやつは1万年問題が生じるみたいなことでしょうか。
そんなに先だと会社がのこってるのか人類が地球に住めているのか謎に満ちて鬼が大爆笑ですかね。

参考

http://blog.keshi.org/hogememo/2015/02/01/ssl-certificate-valid-for-9999-years
https://bucci.bp7.org/archives/30220
http://www.unix-power.net/centos7/openldap_ssl.html
http://www.kakiro-web.com/linux/ssl-client.html
http://int128.hatenablog.com/entry/2015/07/27/224351
http://www.gnutls.org/manual/html_node/certtool-Invocation.html
https://letsencrypt.jp/command/

追記です。

自己認証局ルート証明書の期限が先に切れて作り直したらサーバ証明書も作り直しかどうかという話ですが、まあ作り直しだろうなというのが以下の5ページあたりをみるとなんかわかるかと思います。

サーバ証明書の期限より期限が長いルート証明書で署名する、という運用でカバーするのがいいのかなという感想です。

5
5
1

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
5
5