4
3

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 5 years have passed since last update.

openssl コマンドと csplit コマンドでサーバが返す証明書を分割する

Posted at

次のようにします。

openssl s_client -connect example.com:443 -showcerts < /dev/null |
  csplit -k -f cert - '/^-----BEGIN CERTIFICATE-----/' '{*}'

cert00 cert01 cert02 みたいなファイルがカレントディレクトリに保存されます。cert00 はゴミで、それ以外が証明書です。

cert01cert02 の中身を見てみると -----END CERTIFICATE----- 以降にゴミがついているのですが・・openssl コマンドに食わす分には問題ありません。

openssl x509 -in cert01 -noout -subject
# subject= /CN=example.com

openssl x509 -in cert02 -noout -subject
# subject= /C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X1

openssl verify -verbose cert02
# cert02: OK

openssl verify -untrusted cert02 cert01
# cert01: OK

openssl verify -CAfile <(cat /etc/pki/tls/certs/ca-bundle.crt cert02) cert01
# cert01: OK

cat cert02 cert01 | openssl verify
# stdin: OK
4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?