Tuesday Mar 17, 2009

unable to find valid certification path to requested target

When working on a client that works with an SSL enabled server running in https protocol, you could get error 'unable to find valid certification path to requested target' if the server certificate is not issued by certification authority, but a self signed or issued by a private CMS.

Don't panic. All you need to do is to add the server certificate to your trusted Java key store if your client is written in Java. You might be wondering how as if you can not access the machine where the server is installed. There is a simple program can help you. Please download the Java program and run

% java InstallCert _web_site_hostname_

This program opened a connection to the specified host and started an SSL handshake. It printed the exception stack trace of the error that occured and shows you the certificates used by the server. Now it prompts you add the certificate to your trusted KeyStore.

If you've changed your mind, enter 'q'. If you really want to add the certificate, enter '1', or other numbers to add other certificates, even a CA certificate, but you usually don't want to do that. Once you have made your choice, the program will display the complete certificate and then added it to a Java KeyStore named 'jssecacerts' in the current directory.

To use it in your program, either configure JSSE to use it as its trust store or copy it into your $JAVA_HOME/jre/lib/security directory. If you want all Java applications to recognize the certificate as trusted and not just JSSE, you could also overwrite the cacerts file in that directory.

After all that, JSSE will be able to complete a handshake with the host, which you can verify by running the program again.

To get more details, you can check out Leeland's blog No more 'unable to find valid certification path to requested target'

Comments:

if i use run this application (anyway if in eclipse or by commandline) all seems to be fine. it tells me that the alias is added to jssecacerts.

but it isnt. if i run the programm again it adds the certificate again to jssecacerts. and again, and again...
of course ma java applications are not able to handshake with the ca's host.

to you have an idea what could cause this problem?

Posted by Gerald Ruckendorfer on April 09, 2009 at 05:23 AM PDT #

It works for me just fine.

Posted by GC on April 20, 2009 at 06:38 PM PDT #

I am getting the error "Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target"

however when I run your tool, it says the cert is already trusted:

java InstallCert www.travelex-insurance.com
Loading KeyStore /usr/local/jdk1.6.0_14/jre/lib/security/cacerts...
Opening connection to www.travelex-insurance.com:443...
Starting SSL handshake...

No errors, certificate is already trusted

I'm stumped.

Posted by Greg Ryan on October 15, 2009 at 11:58 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed