Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice to handle third party SSL certificate in Java

I'm working on an application that calls a third-party webservice over https. So I need to add this certificate to the truststore of my application. I can see 3 solutions to fix my problem:

  • add this certificate to $JAVA_HOME/jre/lib/security/cacerts
  • create a custom truststore and launch my JVM with -Djavax.net.ssl.trustStore= ...
  • programatically load this truststore when starting my application

Which solution do you recommend/discourage me to use?

like image 952
Nicolas C Avatar asked Dec 10 '14 13:12

Nicolas C


People also ask

How do you manage a certificate in Java?

I found out that Java has it's own "certificate Store" which is located in a file in the security-folder inside the lib-folder. You could access this from the Java Control Panel -> Security -> Manage Certificates.

How would do SSL configuration using Java?

To configure your Java Runtime Environment to use SSL, follow these steps: Import a certificate from the database server to a Java truststore on the client. Use the Java keytool utility to import the certificate into the truststore. Example: Suppose that the server certificate is stored in a file named cacerts.


1 Answers

I'd prefer the second one. Because;

For the first one; when you change your java version you need to do extra work (you must add these ssl certs to cacerts again).

For the third one; when you need to add another ssl cert. you must change your code.

So, the second is the best choice because; you will not need to change your code when new ssl comes (You will just add it to external trustStore) and you will do nothing for these certs when you upgrade your java version.

like image 125
mokarakaya Avatar answered Sep 21 '22 06:09

mokarakaya