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/

Thursday, January 2, 2020

Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement:


When we try to connect to the embedded H2 database from H2 clients such as DBEver, I was getting following error message

Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement:
ALTER TABLE PUBLIC.IDN_OAUTH2_ACCESS_TOKEN_SCOPE ADD CONSTRAINT PUBLIC.CONSTRAINT_B1 FOREIGN KEY(TOKEN_ID) REFERENCES PUBLIC.IDN_OAUTH2_ACCESS_TOKEN(TOKEN_ID) ON DELETE CASCADE NOCHECK [23505-200]

When i search for this issue, It seems to be introduced with bug fixes for H2 database. Since in WSO2 we use H2 as the default database, we encountered this issue when connecting the H2 database.

So, we can avoid this issue by adding following part to the end of the database URL.


;mv_store=false

Once we added it , the full URL will look like follows.


jdbc:h2:/Users/shammijayasinghe/wso2am-2.6.0/repository/database/WSO2AM_DB;mv_store=false


Hope this helps.. Enjoy!!!

[1] https://groups.google.com/forum/#!topic/h2-database/5LZlZ_jC4QI