I'm trying to connect to a company server using HTTPS. The server certificates are stored on all clients (Windows) and I want to configure my Java app to use the Windows trust store.
I set javax.net.ssl.trustStoreType=Windows-ROOT which I understand should allow Java to use the certificates installed in Windows.
The Client is created in this method:
static CloseableHttpClient getClientWindowsTrust() throws Exception {
System.setProperty("javax.net.ssl.trustStoreType", "Windows-ROOT");
SSLContext sslContext = SSLContext.getDefault();
DefaultClientTlsStrategy strat = new DefaultClientTlsStrategy(sslContext);
var connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setTlsSocketStrategy(strat)
.build();
return HttpClients.custom()
.setConnectionManager(connectionManager)
.build();
}
The required certificates are in the Windows trust store and other apps (which I am assuming use these) are working ok.
The error message is:
TransportContext.java:363|Fatal (CERTIFICATE_UNKNOWN): PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
What might I be missing? How can I determine where exactly the path-building fails?
UPDATE
thanks to those who replied. I tried all suggestions but to no avail. I then focussed more on the server as I had tried everything I could think of on the client side.
The server recently got a new intermediate certificate and this is not being found by the client. I tried a different server which already has the new cert - and it worked. The difference is that server 1 is a Windows server with Apache and Tomcat, server 2 is a containerised server.
At the moment I'm guessing that the Windows installation has a config problem. I installed the new certificate on another Windows server that had been working and now it doesn't.
I'll post another update when I have more information.
PROBLEM SOLVED
It wasn't a client problem. The certificate was installed on the server by a co-worker who forgot to update the Apache config. The config still referenced the old intermediate cert and this caused the problem.
javax.net.ssl.trustStoreTypeis checked every time a new instance is created.