4

I need to test a REST endpoint that runs on localhost with https /ssl (can't change that to http unfortunately). The problem is that since it's for testing purposes it only contains a self signed certificate which Java doesn't like.

To make it work I tried to allow localhost as hostname:

javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
                new javax.net.ssl.HostnameVerifier(){

                    public boolean verify(String hostname,
                                          javax.net.ssl.SSLSession sslSession) {
                        if (hostname.equals("localhost")) {
                            return true;
                        }
                        return false;
                    }
                });

and further added the self signed certificate to my keystore.

But I'm still getting the following error:

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Does anyone know what else to do except for disabling the whole ssl validation process?

meow
  • 2,062
  • 2
  • 17
  • 27

0 Answers0