Created
June 15, 2020 17:33
-
-
Save wongk/9ff3ec0f7661f362d6b4e0fc2fa2148e to your computer and use it in GitHub Desktop.
Blog - Wire mock with HTTPS - example trust manager
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
with (URL(url).openConnection() as HttpsURLConnection) { | |
val trustManager = object : X509TrustManager { | |
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) = Unit | |
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) { | |
// TODO validate the chain, and throw an exception if invalid. | |
} | |
override fun getAcceptedIssuers() = emptyArray<X509Certificate>() | |
} | |
sslSocketFactory = SSLContext.getInstance("TLS").run { | |
init(null, arrayOf(trustManager), null) | |
socketFactory | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment