Wednesday, August 13, 2014

How to add ssl certificate from StartCom in Grails

StartCom provide free SSL/TLS certificate for you website that is valid for a year. This certificate is good enough to get going with SSL without warning etc.

Part1) get the certificate from StartCom
How to get a free certificate from StartCom?
1) visit https://www.startssl.com/?app=12
2) Click on express lane.
3) Supply the info to get your email address verified
4) Verify the email address, it will install a certificate in your browser.
5) Now visit https://www.startssl.com/?app=12 again and go to authneticate
6) Now go to Certificate Wizard and follow the instructions for getting Web Server SSL/TLS Certificate.
7) I opted for generating the the private key file from StartCom to make my life easier. It created a private key text that I saved as file mydomain.key and then they generated certificate for my domain  that I saved as mydomain.crt. Be careful about saving the private key text since I don't think you can retrieve that later. The certificate you can retrieve later also.

Part2) Create java key store file
1) create a pkcs12 file: You need to create a pkcs12 file using the private key and certificate. You can use the following command:
 openssl pkcs12 -export -inkey mydomain.key -in mydomain.crt -name mydomain_name -out mydomain.p12
It will ask for password, supply your favorite password. For simplicity I used the same password everywhere. StartCom also provides a tool to create this pkcs12 file under tools sections.

 2) Create a java keystore file: You can use keytool or you cal use kse (http://keystore-explorer.sourceforge.net/) GUI. Open the pk12 file in kse and change the type (Tools/Change Type/JKS). Then right click on the only entery you have and set password to your favorite password as above. The save this file as one with jks extension.

Part 3) To install this file in grails, 
add these two entries in conf/BuildConfig.groovy
grails.tomcat.keystorePath = "full file path of .jks file"
grails.tomcat.keystorePassword = "your password"