Created
March 10, 2021 09:39
-
-
Save Skeptick/1122cdb783f389b10dd1f44950e4b7e4 to your computer and use it in GitHub Desktop.
OkHttp. Trust all SSL certificates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun buildHttpClientEngine(): HttpClientEngine = OkHttp.create { | |
config { | |
retryOnConnectionFailure(true) | |
hostnameVerifier { _, _ -> true } | |
val trustManager = object : X509TrustManager { | |
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) = Unit | |
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) = Unit | |
override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray() | |
} | |
val sslContext = SSLContext.getInstance("TLS") | |
sslContext.init(null, arrayOf(trustManager), SecureRandom()) | |
sslSocketFactory(sslContext.socketFactory, trustManager) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment