SSL, Certificates and Java
For Java to be able to carry out secured communication, one must first make sure that the certificate associated with the endpoint is stored in the Java keystore. If you don’t have the certificate stored in the keystore, you’re likely to run into error messages similar to the following:
To find the current keystore type:
You’ll probably get more than one result, but the one that is of most interest is the folder that resides inside the Java JRE folder, e.g.,
To see all installed certificates type (keystore password: changeit):
keytool -list -keystore /usr/lib/jvm/java-6-sun-18.104.22.168/jre/lib/security/cacerts
How to add a certificate
Lets assume that we would like to communicate with the following soap endpoint
whose wsdl can be found at
- First, lets use Firefox (or any web browser capable of handling certificates) to browse to the wsdl. On the way there, we should get some notification about a certificate being used. After a bit of clicking, we should see the wsdl (an xml file – “view source” to see it).
- Now left-click on the “secure” icon on the left of the address bar and choose “More information” -> “View Certificate” -> “Details” -> “Export”. Choose to save the certificate with (DER) encoding. Lets assume you save the certificate to
- Now we want to add this certificate to our Java keystore. Use the following command:
keytool -import -alias example -keystore /usr/lib/jvm/java-6-sun-22.214.171.124/jre/lib/security/cacerts -file /tmp/security/example.cer
You should now be able to use the service without getting the above exceptions.