The problem I have is that I was testing with different versions of the SDK
and with a samsung SM-A500M
version of the API 19 it jumps in front of the onFailure
and the error that I get is the following:
SSL handshake aborted: ssl = 0x78cb85f0: I / O error during system call, Connection reset by peer
I have tried API 22 more and if you connected without problems.
The class I used is this
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()
}
})
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
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)
}
}
}
}
and the way I use it is
val okHttpClient = UnsafeOkHttpClient.getUnsafeOkHttpClient()
val retrofit = Retrofit.Builder()
.baseUrl(Constants.RUTA_API)
.client(okHttpClient.build())
.addConverterFactory(GsonConverterFactory.create())
.build()
I've also tried using the 'com.squareup.okhttp3:okhttp:3.9.1'
library, but I get the same error.