Java – Analyze SSL certificate programmatically or via commandline


I'ld like to analyze the certificate of a given url and get some details of it. Do you know any ways to do this? A command-line tool can be something like downloadSSLCert https://my.funny.url/ > certFile and then analyzing it for e.g. the fingerprint of the cert. It can be a command line utility, a C/C++/Objective-C or Java code and will be used on osx >= 10.5

Best Solution

You can make an SSL connection from the command line thus:

echo '' | openssl s_client -connect

The output will contain the X.509 cert in base64 encoding.

To view further details,

... | openssl x509 -fingerprint -text

If you only want the fingerprint, omit the "-text" flag and add "-out /dev/null".