I have a java cucumber test automation framework that I am using for testing apis.
Previously I was using a tool called Karate that has a simple flag ( karate.configure('ssl', { trustAll: true });) that allows you to trust all certificates.
I was hoping there would be a similar flag for use with Apache HTTP Client...but all my googling leads to long and complicated code.
This is the code I have written so far to send the .pfx file to the api
String keyPassphrase = "";
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream("src/main/resources/sslCertificates/certificate.pfx"), keyPassphrase.toCharArray());
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(keyStore, null)
.build();
//This is the httpClient that you will use to send your http request
CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
//Send the request
CloseableHttpResponse response = httpClient.execute(request);
but it gets rejected before it is sent saying
"javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
How can I easily accept all certificates to get around this problem? As stated I am just testing so there is no problem with doing this.
However I do have certificate files in .pfx and .crt formats and a client.key file that could potentially be used - but I don't know how.