Skip to content

Instantly share code, notes, and snippets.

@wongk
Created June 15, 2020 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wongk/9ff3ec0f7661f362d6b4e0fc2fa2148e to your computer and use it in GitHub Desktop.
Save wongk/9ff3ec0f7661f362d6b4e0fc2fa2148e to your computer and use it in GitHub Desktop.
Blog - Wire mock with HTTPS - example trust manager
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