Last active
January 25, 2017 13:32
-
-
Save sczerwinski/c7da8c7ce2369dc8874c9fe5f1c5dbdb to your computer and use it in GitHub Desktop.
Kotlin port of the solution proposed by @naderghanabri: http://stackoverflow.com/a/28787883/4568679
This file contains hidden or 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
import java.security.SecureRandom | |
import java.security.cert.X509Certificate | |
import javax.net.ssl.* | |
object SSL { | |
fun trustAll() { | |
val sslContext = SSLContext.getInstance("SSL") | |
sslContext.init(null, arrayOf(TrustAll), SecureRandom()) | |
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.socketFactory) | |
HttpsURLConnection.setDefaultHostnameVerifier(VerifyAllHostnames) | |
} | |
private object TrustAll : X509TrustManager { | |
override fun getAcceptedIssuers() = null | |
override fun checkClientTrusted(x509Certificates: Array<X509Certificate>, s: String) {} | |
override fun checkServerTrusted(x509Certificates: Array<X509Certificate>, s: String) {} | |
} | |
private object VerifyAllHostnames : HostnameVerifier { | |
override fun verify(s: String, sslSession: SSLSession) = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment