Wednesday, August 5, 2020

Download / Get Public certificate of secured websites / HTTPs endpoints


In our day today life, Sometimes we need to get the public certificate of various HTTPs endpoints to invoke them securely.

So, if you are a MAC OS user, you ll have a hard time since google chrome is not having the option to download it as 2020 and Firefox also not giving it as a single one. You have to go through certificate chain to get it.

However, If you have a single command to get it, It is very convenient. With Open SSL, We can get it easily.

Following is the pattern.

$ echo | openssl s_client -servername NAME -connect HOST:PORT |\
  sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > certificate.crt

Short explanation:
OptionDescription
-connect HOST:PORTThe host and port to connect to
-servername NAMEThe TLS SNI (Server Name Indication) extension (website)
certificate.crtSave SSL certificate to this file


Example:

$ echo | openssl s_client -servername run.mocky.io -connect run.mocky.io:443 |\
  sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > certificate.crt

I found this information from [1] and here is my gratitude to the author of that side.

Enjoy!!!

[1] https://www.shellhacks.com/get-ssl-certificate-from-server-site-url-export-download/

No comments:

Post a Comment