話題の記事

SSL証明書の有効期限確認に便利なツール「cert」

2017.10.31

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、コカコーラ大好きカジです。

「SSL証明書(サーバ証明書)の有効期限確認や証明書の種類を確認するのは面倒ですよね。」

OpensslのコマンドをGoogle検索して・・・というか、自分もそんな感じです。

同じな悩みを持った人いそうだなぁ・・・と思って調べたら解決していた人がいました。感謝です。

certとは

SSL証明書(サーバ証明書)の情報取得ツールです。(MITライセンスです。)

genkiroid/cert Cert is the Go tool to get SSL certificate information.

前提条件

MacOSXでの利用法を記載します。他のOSの場合は、Goが動作すれば動くようですので、上記URLのReadmeをご参照ください。

certのセットアップ

brewを利用すれば簡単にインストールできます。

% brew tap genkiroid/homebrew-cert
% brew install cert
% which cert
/usr/local/bin/cert

certの使い方

発行者、有効期限、コモンネーム(ドメイン名)が分かります。

% cert dev.classmethod.jp
DomainName: dev.classmethod.jp
IP:         xx.xx.xx.xx
Issuer:     Amazon
NotBefore:  2017-08-01 09:00:00 +0900 JST
NotAfter:   2018-09-01 21:00:00 +0900 JST
CommonName: *.classmethod.jp
SANs:       [*.classmethod.jp classmethod.jp]
Error:

ELB、Cloudfront、サーバ直接接続などで使う場合

「-k」オプションをつけます。

% cert -k hogehoge.ap-northeast-1.elb.amazonaws.com
DomainName: hogehoge.ap-northeast-1.elb.amazonaws.com
IP:         xx.xx.xx.xx
Issuer:     Amazon
NotBefore:  2017-08-01 09:00:00 +0900 JST
NotAfter:   2018-09-01 21:00:00 +0900 JST
CommonName: *.classmethod.jp
SANs:       [*.classmethod.jp classmethod.jp]
Error:

注意:ELB/Cloudfrontは複数IPアドレスを持っていますが、certは1つのみしか表示されません。

便利な機能

これだけ?って思った方、これだけではありません。 「-f」オプションで複数リクエスト可能で、Markdown形式かJSON形式で出力してくれます。 Wikiなどで管理するのに便利ですよね。

% cert -f md classmethod.jp dev.classmethod.jp
DomainName | IP | Issuer | NotBefore | NotAfter | CN | SANs | Error
--- | --- | --- | --- | --- | --- | --- | ---
classmethod.jp | xx.xx.xx.xx | Amazon | 2017-07-12 09:00:00 +0900 JST | 2018-08-12 21:00:00 +0900 JST | *.classmethod.jp | \*.classmethod.jp<br/>classmethod.jp<br/> |
dev.classmethod.jp | xx.xx.xx.xx | Amazon | 2017-08-01 09:00:00 +0900 JST | 2018-09-01 21:00:00 +0900 JST | *.classmethod.jp | \*.classmethod.jp<br/>classmethod.jp<br/> |

作成されたMarkdownの表

感動しました。

DomainName IP Issuer NotBefore NotAfter CN SANs Error
classmethod.jp xx.xx.xx.xx Amazon 2017-07-12 09:00:00 +0900 JST 2018-08-12 21:00:00 +0900 JST *.classmethod.jp *.classmethod.jp
classmethod.jp
dev.classmethod.jp xx.xx.xx.xx Amazon 2017-08-01 09:00:00 +0900 JST 2018-09-01 21:00:00 +0900 JST *.classmethod.jp *.classmethod.jp
classmethod.jp

まとめ

サービス利用しているURLが多数ある場合に、SSL証明書確認や管理などに使えると思います。

参考元

/etc/motg