Javax.net.ssl.SSLException: The connection was closed by the peer. in android kitkat versions
I am using REST api to connect to server on ssl https problm resides on android kitkat devices. all devices with kitkat or 4.xx version do not connect to the server
javax.net.ssl.SSLException: Connection closed by peer at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
on all the above devices than 4.xx works fine and makes a connection
Is there any solution for this. I also tried OkHttp, which also doesn't work in my work.
source to share
I faced a similar issue before when my endpoint was using TLS 1.2 for encryption. If your endpoint is using https
, you can try going to http
for an unencrypted api call. If that's an option.
If you only release your app on devices using Google Play Services
, you can use ProviderInstaller
to support TLS 1.2
fun installSecurityProvider() {
try {
ProviderInstaller.installIfNeeded(activity)
} catch (e: GooglePlayServicesRepairableException) {
handlePlayServicesError(e.connectionStatusCode)
} catch (e: GooglePlayServicesNotAvailableException) {
handleCriticalFailure()
}
}
https://developer.android.com/training/articles/security-gms-provider.html
An issue was discovered on the ohttp git page where this issue was discussed.
https://github.com/square/okhttp/issues/3098
If relying on gaming services is not an option, then you can implement it yourself.
https://github.com/square/okhttp/issues/2372#issuecomment-244807676
source to share