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/

Response time for curl commands

In our day today life when we are using CURL commands, It is worth that if we can measure the time it took to respond. In curl , we can write out the time taken for many of the cases.

You can read information about them from the man page of the CURL too.

For the simplicity i would post following here.

curl -w'%{time_total}' -X  GET "https://run.mocky.io/v3/7f8d8e53-b0a3-47bd-b2e6-fda5f449b0be"


you ll get a response like follows.

{"shammi":"jayasinghe"}1.496453 

you can see, it has taken about 1.49 seconds for overall response.


You can read about -w operation and about the flags from man curl page or from [1] which i learnt to use these

[1]  https://ops.tips/gists/measuring-http-response-times-curl/