I have a client cert, key, and cacert to work with. The curl for the code I want would be
curl https:<ip>/query --cert client_cert.pem --key client_key.pem --cacert ca_cert.pem "-d <post data>"
I have tried to combine these files into a PFX (and p12) since that seems to be the required format but I'm not sure I did it correctly:
openssl pkcs12 -export -out client.pfx -inkey client_key.pem -in client_cert.pem -certfile ca_cert.pem
I initially received an error about not having a SAN defined in my cert, I have since added some code that should ignore this but I don't think it's the cause of my problem. I receive a 404 as a result form the POST when a curl gives me the actual expected content
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream("client.pfx"), keyPassphrase.toCharArray());
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(keyStore, keyPassphrase.toCharArray())
.loadTrustMaterial(keyStore, TrustSelfSignedStrategy.INSTANCE)
.build();
HttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).setSSLContext(sslContext).build();
HttpPost httpPost = new HttpPost("https://" + ip + "/query");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(postKey, postVal));
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = httpClient.execute(httpPost);
System.out.println(response.toString());
Gives
HttpResponseProxy{HTTP/1.1 404 Not Found [Date: Sun, 28 Oct 2018 02:11:55 GMT, Server: Apache/2.4.29 (Ubuntu), Content-Length: 280, Keep-Alive: timeout=5, max=100, Connection: Keep-Alive, Content-Type: text/html; charset=iso-8859-1] ResponseEntityProxy{[Content-Type: text/html; charset=iso-8859-1,Content-Length: 280,Chunked: false]}}
Any ideas if my code is wrong or if it's the certs or what? From what I can tell I have made the pfx correctly, and the certs obviously work if the curl works. I've been working on this for a while and not able to figure it out.
Edit: The original code ("https//" vs "https://") was a typo on stack overflow due to me debugging. That wasn't the issue.