Search code examples
javaopensslssl-certificatekeytool

Import Certificate and Private Key for Java


I am getting the following error from a Java Application ERROR: Naming service connection failed for https://******* com.iplanet.services.comm.client.SendRequestException: sun.security.validator.ValidatorException: PKIX path building failed:

I have been provided two files from who managed the target URL:

File.cer (should be a DER Encoded certificate) File.key (it's the private key)

I have then Read a lot from different site about what I need to do in order to import both into the JVM using tje keytool, ma still haven't understood how to do it correctly. Is there a procedure ?


Solution

  • You can import the certificate in your truststore with the following:

    keytool -import -alias YOURALIAS -file File.cer -keystore YOURTRUSTSTORE.truststore -password YOURTRUSTSTOREPASSWORD

    In your JVM arguments, please make sure you have -Djavax.net.ssl.trustStore= and -Djavax.net.ssl.trustStorePassword