I'm new to all the SSL and certificate management of the Java. I'm trying to call an API provided by my partner and it's 2 way SSL. There is no encryption involved and it's only the certificate for the partner to know the source of the request.
I've generated my private key and used it to get a valid certificate from a CA and then passed a CRT & PEM file to my partner to install on their servers.
Using the curl with the pem file and my private key I can easily call their API.
curl -X POST -v -d '{"someparam1":"somevalue1"}' -H "Content-Type: application/json" https://api.domain.com/something --cert cn_file.pem --key cn_file.key
Now I wanna call the API via my Java code using OkHttp. I'm confused with all the adding the certificate to my JVM's keystore. I've used openssl to convert pem to der and the private key to p12 and added them both to the cacerts.jks.
When I use the keystore in my code and pass the x509 trust manager & x509 key manager, the code throws an IOException as below:
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
I'm puzzled because when I look into the keystore loaded into the code I can see the der & the p12 files as well.