Last active
August 26, 2024 13:06
-
-
Save maiconhellmann/c61a533eca6d41880fd2b3f8459c07f7 to your computer and use it in GitHub Desktop.
Revisions
-
maiconhellmann revised this gist
May 1, 2024 . 2 changed files with 47 additions and 44 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,44 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ import android.annotation.SuppressLint import okhttp3.OkHttpClient import java.security.cert.CertificateException import javax.net.ssl.SSLContext import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager object UnsafeOkHttpClient { fun Builder(): OkHttpClient.Builder { try { // Create a trust manager that does not validate certificate chains val trustAllCerts = arrayOf<TrustManager>(@SuppressLint("CustomX509TrustManager") object : X509TrustManager { @SuppressLint("TrustAllX509TrustManager") @Throws(CertificateException::class) override fun checkClientTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) { // N / A } @SuppressLint("TrustAllX509TrustManager") @Throws(CertificateException::class) override fun checkServerTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) { // N / A } override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> { return arrayOf() } }) // Install the all-trusting trust manager val sslContext = SSLContext.getInstance("SSL") sslContext.init(null, trustAllCerts, java.security.SecureRandom()) // Create an ssl socket factory with our all-trusting manager val sslSocketFactory = sslContext.socketFactory val builder = OkHttpClient.Builder() builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) // builder.hostnameVerifier { _, _ -> true } builder.hostnameVerifier(hostnameVerifier = { _, _ -> true }) return builder } catch (e: Exception) { throw RuntimeException(e) } } } -
maiconhellmann revised this gist
Aug 11, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import java.security.cert.CertificateException import javax.net.ssl.SSLContext import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager import javax.net.ssl.HostnameVerifier class UnsafeOkHttpClient { companion object { -
maiconhellmann revised this gist
Aug 25, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,8 @@ class UnsafeOkHttpClient { val builder = OkHttpClient.Builder() builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) // builder.hostnameVerifier { _, _ -> true } builder.hostnameVerifier ( hostnameVerifier = HostnameVerifier{ _, _ -> true }) return builder } catch (e: Exception) { -
maiconhellmann created this gist
Nov 21, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ import okhttp3.OkHttpClient import java.security.cert.CertificateException import javax.net.ssl.SSLContext import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager class UnsafeOkHttpClient { companion object { fun getUnsafeOkHttpClient(): OkHttpClient.Builder { try { // Create a trust manager that does not validate certificate chains val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager { @Throws(CertificateException::class) override fun checkClientTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) { } @Throws(CertificateException::class) override fun checkServerTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) { } override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> { return arrayOf() } }) // Install the all-trusting trust manager val sslContext = SSLContext.getInstance("SSL") sslContext.init(null, trustAllCerts, java.security.SecureRandom()) // Create an ssl socket factory with our all-trusting manager val sslSocketFactory = sslContext.socketFactory val builder = OkHttpClient.Builder() builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) builder.hostnameVerifier { _, _ -> true } return builder } catch (e: Exception) { throw RuntimeException(e) } } } }