If you have access to OpenSSL, try
openssl s_client -connect {HOSTNAME}:{PORT} -showcerts
replacing {HOSTNAME} and {PORT} with whatever your values are.
Answer from gbroiles on Stack ExchangeVideos
If you have access to OpenSSL, try
openssl s_client -connect {HOSTNAME}:{PORT} -showcerts
replacing {HOSTNAME} and {PORT} with whatever your values are.
A quick method to get the certificate pulled and downloaded would be to run the following command which pipes the output from the -showcerts to the x509 ssl command which just strips everything extraneous off. For example:
openssl s_client -showcerts -connect server.edu:443 </dev/null 2>/dev/null|openssl x509 -outform PEM >mycertfile.pem
To use the certificate, with wget,
wget https://server.edu:443/somepage --ca-certificate=mycertfile.pem
In order to download the certificate, you need to use the client built into openssl like so:
</dev/null openssl s_client -connect $HOST:$PORTNUMBER -servername $SERVERNAME \
| openssl x509 > /tmp/$SERVERNAME.cert
That will save the certificate to /tmp/$SERVERNAME.cert.
The -servername is used to select the correct certificate when multiple are presented, in the case of SNI.
You can use -showcerts if you want to download all the certificates in the chain. But if you just want to download the server certificate, there is no need to specify -showcerts. The x509 at the end will strip out the intermediate certs, you will need to use sed -n '/-----BEGIN/,/-----END/p' instead of the x509 at the end.
</dev/null indicates that nothing should be sent to the server, so that the connection is released.
openssl x509 removes information about the certificate chain and connection details. This is the preferred format to import the certificate into other keystores.
I found the answer. Openssl provides it.
openssl s_client -connect ${REMHOST}:${REMPORT}