Monday, March 28, 2016

Generating an SSL Certificate for a Java application

I was recently working with a vendor to generate a new ssl for one of our web applications.  Our vendor required for use to create the keystore with a password and then give him the password so that he can install it.  I worked with Entrust and my lead.  Here is what we came up with.

The version of Java that we were working with on the server jre1.8.0_65.  Creating the csr and the ssl is a little different from Windows -- which is what I am used to.  First you have to create a keystore and give it a password.  Typically you need to do this from a command line and cd into the bin dir under java to run the key tool.  The command to generate a new keystore is:

keytool -genkey -alias server -keyalg RSA -keysize 2048 -keystore keystore.jks
Enter Password - ########
Confirm Password - ########

from there you will get a series of prompts for : First and Last Name, Organizational Unit, Organization, City, State, Country Code

You fill these out just like you would for generating a CSR.

After to create your CSR you use this command:

keytool -certreq -alias server -keyalg RSA -file server.csr -keystore keystore.jks
Keystore Password - ######

The keyalg is the algorithm it is using.  In our case RSA.
The file is what ever you want to call the crs.  In our case server.csr.
The keystore is the name of the keystore.  In our case keystore.jks.  Entrust recommended that we make a copy of the jks file and keep it in a safe place.  But if you don't know the password for the keystore then that would be useless.
The Keystore Password is the password that you use to initially set up the keystore.

So after you have created your csr and gave it to your ssl provider and they have provided you with a properly formated  ssl cert -- the proper format for a cert on a java app is .p7b. You need to install said ssl.  The command to install the ssl into the keystore is:

keytool -import -trustcacerts -alias server -file server.p7b -keystore keystore.jks
Password - ######

After we imported the ssl and provided the password we gave the info to the vendor.