https://kotlinlang.org logo
Title
t

tim

06/11/2021, 11:40 AM
Hi is there an easy way for the ktor http client to accept self signed certs for dev?
d

divyanshunegi

06/12/2021, 3:38 PM
Looking for an answer to this as well
a

Aleksei Tirman [JB]

06/15/2021, 11:41 AM
As a workaround, on the JVM target using CIO engine, you can accept all certificates:
val client = HttpClient(CIO) {
    engine {
        https.trustManager = object : X509TrustManager {
            override fun checkClientTrusted(certs: Array<X509Certificate?>?, authType: String?) {}
            override fun checkServerTrusted(certs: Array<X509Certificate?>?, authType: String?) {}
            override fun getAcceptedIssuers(): Array<X509Certificate?> = arrayOfNulls(0)
        }
    }
}
🙏 1
Also, you can add a certificate chain:
HttpClient(CIO) {
    engine {
        https.addCertificateChain(...)
    }
}
👍 1