Sunday, February 20, 2011

How to fetch HTTPS end point certificate chain via Shell ?

You can do it through the web browser - and download each and every certificate...
Following is the easy way via shell..

$ openssl s_client -showcerts  -connect www.amazon.com:443 > ssl.log
depth=1 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = Terms of use at https://www.verisign.com/rpa (c)09, CN = VeriSign Class 3 Secure Server CA - G2
verify error:num=20:unable to get local issuer certificate
verify return:0
CtrL+C
$ sed -n  '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' ssl.log  > cert.pem

The above will save the certificate chain corresponding to www.amazon.com in cert.pem file.

Read more: F A C I L E L O G I N