I tried the recommendations in this post but have not been able to get a working solution.
Despite using TrustSelfSignedStrategy and NoopHostnameVerifier I am still getting the following error:
javax.net.ssl.SSLPeerUnverifiedException: Certificate for <fooHost> doesn't match any of the subject alternative names: []
It seems like if I could add fooHost to the SANs it would fix my issue but I am uncertain of how to do that.
This is my current implementation:
String serverHost = "fooHost";
String port = "1111";
TrustStrategy acceptingTrustStrategy = new TrustSelfSignedStrategy();
SSLContext sslContext =
org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
SSLConnectionSocketFactory sslsf =
new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
try( CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); ){
String url = "https://" + serverHost+ ":" + port ;
HttpPost totpPost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add( new BasicNameValuePair( "param0", "value0") );
params.add( new BasicNameValuePair( "param1", "value1") );
totpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
try (CloseableHttpResponse totpResponse = httpClient.execute(totpPost)) {
HttpEntity totpEntity = totpResponse.getEntity();
String response = EntityUtils.toString(totpEntity);
MyResponse nmr= objectMapper.readValue(response, MyResponse.class);
EntityUtils.consume(totpEntity);
return nmr;
}
}catch(Exception e){
log.error("Well this is fooBar:" , e);
}