<mazgi.github.io 移行済>複数のサーバーに対してSSL証明書の期限を確認する

移行しました=> https://mazgi.github.io/posts/2016.02/tls-certificates-validation-via-s_client/

会社のサーバーが一斉にSSL証明書更新のシーズンを迎えたのでOpenSSLの各種コマンドで確認の手間を減らしてみる。

まず、 openssl s_client コマンドで /dev/null を標準入力に入れつつ標準エラー出力を捨てるとこんな出力が得られる。

$ openssl s_client -connect www.mvrck.co.jp:443 < /dev/null 2> /dev/null                                        
CONNECTED(00000003)
---
Certificate chain
 0 s:/CN=*.mvrck.co.jp
   i:/C=US/O=GeoTrust Inc./CN=RapidSSL SHA256 CA - G3
 1 s:/C=US/O=GeoTrust Inc./CN=RapidSSL SHA256 CA - G3
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
---
Server certificate
(snip)
    Verify return code: 0 (ok)
---

openssl s_client の結果を -startdate, -enddate オプションを指定しつつ openssl x509 コマンドに渡すとこんな出力が得られる。

$ openssl s_client -connect www.mvrck.co.jp:443 < /dev/null 2> /dev/null | openssl x509 -noout -startdate -enddate 
notBefore=Feb 24 16:02:53 2016 GMT
notAfter=Mar 28 02:59:00 2017 GMT

のでこんな感じで複数のホストのSSL証明書の期限を確認できる。

$ for h in {foo,bar,baz}.example.com
do
echo -n "$h:"
openssl s_client -connect $h:443 < /dev/null 2> /dev/null | openssl x509 -noout -enddate | grep -E '^\s*notAfter='
done
foo.example.com:notAfter=Mar 28 01:23:45 2017 GMT
bar.example.com:notAfter=Mar 28 01:23:45 2017 GMT
baz.example.com:notAfter=Mar 28 01:23:45 2017 GMT

便利!