I'm trying to call an api using RestTemplte from service on server A and the other service on server B and i get the error below :
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Even when i added this configuration (code below) into the rest template still the same problem.
SSLContext sslContext = new SSLContextBuilder()
.loadTrustMaterial(new File(keystore), trustStorePassword.toCharArray())
.build();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext);
HttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(socketFactory)
.build();
HttpComponentsClientHttpRequestFactory factory =
new HttpComponentsClientHttpRequestFactory(httpClient);
RestTemplate restTemplate = new RestTemplate(factory);
the solution that i found on the net is to export certificate from chrome and add it to the JVM trusted certificate. I don't know if this is the right solution becouse we can change this certif evry 3 month for example..
And i have some other questions :
Does JVM knows all certificate authority (i think there are billion..) for example when i call google using rest certificate will be validated by JVM using "security/cacerts"?
Should I add our certificate in JVM trusted certifies to fix
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
?The validation process is not automatic by SSL mechanism ?
thank you in advance.