In Chrome, clicking on the green HTTPS lock icon opens a window with the certificate details:
When I tried the same with cURL, I got only some of the information:
$ curl -vvI https://gnupg.org
* Rebuilt URL to: https://gnupg.org/
* Hostname was NOT found in DNS cache
* Trying 217.69.76.60...
* Connected to gnupg.org (217.69.76.60) port 443 (#0)
* TLS 1.2 connection using TLS_DHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate: gnupg.org
* Server certificate: Gandi Standard SSL CA
* Server certificate: UTN-USERFirst-Hardware
> HEAD / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: gnupg.org
> Accept: */*
Any idea how to get the full certificate information form a command line tool (cURL or other)?
You should be able to use OpenSSL for your purpose:
That command connects to the desired website and pipes the certificate in PEM format on to another openssl command that reads and parses the details.
(Note that "redundant"
-servername
parameter is necessary to makeopenssl
do a request with SNI support.)Basic certificate info
That's my everyday script:
Output:
Full certificate info
The
-p 443
specifies to scan port 443 only. All ports will be scanned if it is omitted, and the certificate details for any SSL service that is found will be displayed. The--script ssl-cert
tells the Nmap scripting engine to run only thessl-cert
script. From the doc, this script "(r)etrieves a server's SSL certificate. The amount of information printed about the certificate depends on the verbosity level."Sample output:
Depends on what kind of information you want, but:
should give you most, although not as nicely human readable like Chrome presents it.
For completeness: if you have installed on your system Java 7 or higher
shows the chain (as served) with nearly all details in a mostly rather ugly format.
Whether you should have Java installed on your system I do not answer.
If you want to do this in Windows you can use PowerShell with the following function:
This allows you to do some neat things like
If you only want the expiry date (which isn't exactly the answer but is 9/10 what people use the Chrome cert details for), you can use:
echo | openssl s_client -connect google.com:443 2>/dev/null | openssl x509 -noout -enddate
Useful for scripts etc.
To check for SSL certificate details, I use the following command line tool ever since it's become available:
https://github.com/azet/tls_tools
It's great to double-check you have all info correct for re-issuing certs or validating existing ones, and also as few dependencies AND it requires no setup.
This is what the first few lines of the output look like:
That output is followed by the whole certificate chain at the same level of detail.
What I like that instead of being a ssl-centric cli tool like openssl's s_client, this one tries to just do the one job we need most of the time. Of course openssl is more flexible (i.e. also checking clientcerts, imaps on odd ports, etc) - but I don't always need that.
Alternatively, if you have time to dig in & setup or appreciate more features, there's the bigger tool named sslyze (not using it since dependencies and install...)
I use a shell script for this. It's just a wrapper around the openssl command that saves me from remembering the syntax.
It provides options for parsing out most of the certificate information I'm typically interested in, or display raw openssl output.
Can either query a local certificate file, or a remote server.
Usage:
You can get the script here: https://web.archive.org/web/20190528035412/http://giantdorks.org/alain/shell-script-to-check-ssl-certificate-info-like-expiration-date-and-subject/