howettl
howettl

Reputation: 12518

How can I pull the SSL certificate from a remote server?

As the title says. I need to use it to work around an SSL error I am getting in my application.

Upvotes: 1

Views: 5080

Answers (1)

Stephen Kidson
Stephen Kidson

Reputation: 2836

You can do this with openssl via terminal, this question has actually been asked over on ServerFault.

In order to download the certificate, you need to use the client built into openssl like so:

echo -n | openssl s_client -connect HOST:PORTNUMBER | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/$SERVERNAME.cert

That will save the certificate to /tmp/$SERVERNAME.cert.

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

echo -n gives a response to the server, so that the connection is released

sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' removes information about the certificate chain. This is the preferred format to import the certificate into other keystores.

Upvotes: 2

Related Questions