Accept server’s self-signed ssl certificate in Java client

It looks like a standard question, but I couldn’t find clear directions anywhere.

I have java code trying to connect to a server with probably self-signed (or expired) certificate. The code reports the following error :

[HttpMethodDirector] I/O exception (javax.net.ssl.SSLHandshakeException) caught 
when processing request: sun.security.validator.ValidatorException: PKIX path 
building failed: sun.security.provider.certpath.SunCertPathBuilderException: 
unable to find valid certification path to requested target

As I understand it, I have to use keytool and tell java that it’s OK to allow this connection.

All instructions to fix this problem assume I’m fully proficient with keytool, such as

generate private key for server and import it into keystore

Is there anybody who could post detailed instructions?

I’m running unix, so bash script would be best.

Not sure if it’s important, but code executed in jboss.

16 Answers
16

Leave a Comment