0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OpenSSL のコマンドで証明書の情報確認

Last updated at Posted at 2021-09-21

はじめに

テスト環境とかに組み込んだ SSL 環境で「Server certificate chain verification faild and the CA is missing」とか言われて時に、証明書の確認を行うが、そのときに OpenSSL のコマンドを利用していろいろ確認する。

だた、この OpenSSL のコマンド(引数) をすぐに忘れるので備忘録を残しておく。

証明書の期限確認

実行コマンド

openssl x509 -noout -dates -in  <証明書ファイル>

コマンド例

# サーバ証明書
openssl x509 -noout -dates -in  newcert.pem
notBefore=Sep  6 06:17:24 2019 GMT
notAfter=Sep  5 06:17:24 2020 GMT

# CA証明書
openssl x509 -noout -dates -in  cacert.pem
notBefore=Sep  6 06:02:19 2019 GMT
notAfter=Sep  5 06:02:19 2022 GMT

証明書が組み込まれたサーバ(サービス) の証明書有効期限確認

コマンド例

openssl s_client -connect <ホスト名>:636 | openssl x509 -noout -enddate
depth=1 C = XX, ST = XX, O = XX, OU = XX, CN = XXXXXXX
verify error:num=19:self signed certificate in certificate chain
notAfter=Sep  5 06:17:24 2020 GMT

SMTP の場合は以下のオプション付き

openssl s_client -connect <ホスト名>:25 -starttls smtp | openssl x509 -noout -dates

証明書内容の確認

実行コマンド

penssl x509 -text -noout -in <証明書ファイル>

コマンド例

penssl x509 -text -noout -in newcert.pem
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            a9:6f:0b:e9:0f:57:31:f7
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=XX, ST=XXXX, O=XXXX, OU=XXX, CN=XXXXXX
        Validity
            Not Before: Sep  6 06:17:24 2019 GMT
            Not After : Sep  5 06:17:24 2020 GMT
        Subject: C=XX, ST=XXXX, O=XXXX, OU=XXX, CN=XXXXXX
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                     :
                     :
                     :

サーバ証明書と秘密鍵のセットか確認

サーバ証明書の内容表示

openssl x509 -noout  -modulus -in  newcert.pem
Modulus=XXXX.....

秘密鍵の内容表示

# openssl rsa -noout  -modulus -in  newkey.pem
Enter pass phrase for newkey.pem:XXXXXXXXXX
Modulus=XXXX....
0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?