Here are the steps i did with the .crt file given and provided to me that i need to add on my request:

step 1: converted the .crt file to .cer file

openssl x509 -inform PEM -in cert.crt -outform DER -out cert.cer

step2: imported certificate to a java keystore file

keytool -importcert -file cert.cer -keystore cert.jks -storepass 123@123 <<< "yes"

now i have to pass this cert.jks via http request, but after running, im receiving this error of **"PKIX path building failed" and "unable to find valid certification path to requested target" **

here is my code in kotlin

val newUnirestInstance = Unirest.primaryInstance()

val filePath = "cert.jks"

val headers: MutableMap<String, String> = HashMap()
   headers["Content-Type"] = "text/xml; charset=utf-8"

val customSslContext = SSLContexts
       .custom()
       .loadTrustMaterial(
         File(filePath),
         "123@123".toCharArray()
       )
       .build()

val hostNameUrl = URL(url).host

val verifier = HostnameVerifier { hostname: String, session: SSLSession? -> hostname == hostName }
newUnirestInstance.config()
                .verifySsl(true)
                .connectTimeout(0)
                .sslContext(customSslContext)
                .hostnameVerifier(verifier)

val responseResult = newUnirestInstance.put(url)
                    .headers(headers)
                    .body(body)
                    .asString()
0

There are 0 best solutions below