0

I have an android app with ktor-client. The normal http is working. The https with public or self-signed certification is working. But I want to accept the certification even if I just put the ip address (not the domain).

For example, if I make a request like this: https://192.168.1.100 I got this error: Hostname 192.168.1.100 not verified

My code is:

//SSL configuration
    engine {
        config {

            //trust all certificates
            val sslContext: SSLContext = SSLContext.getInstance("SSL")
            sslContext.init(null, trustAllCerts, SecureRandom())
            sslSocketFactory()
            sslSocketFactory(sslContext.socketFactory, trustAllCerts[0] as X509TrustManager)
        }
    }



var trustAllCerts: Array<TrustManager> = arrayOf(
        @SuppressLint("CustomX509TrustManager")
        object : X509TrustManager {
            @SuppressLint("TrustAllX509TrustManager")
            override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {}
            @SuppressLint("TrustAllX509TrustManager")
            override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {}
            override fun getAcceptedIssuers(): Array<X509Certificate> {
                return arrayOf()
            }
        }
    )

Currently, I'm using Ktor with OkHttp engine, but I can change it.

0 Answers0