Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.net.ssl.SSLException: Connection closed by peer. in android kitkat versions

i am using REST api to connect with server on ssl https the problm is on android kitkat devices. all device with kitkat version or 4.x.x are not making connection with server

javax.net.ssl.SSLException: Connection closed by peer at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)

on all above devices than 4.x.x working fine and making connection

Is there any solution for that. i have also tried OkHttp which is also not working in my cause.

like image 763
Shoaib Anwar Avatar asked Jul 31 '17 07:07

Shoaib Anwar


1 Answers

I faced a similar problem before, where my endpoint was using TLS 1.2 for encryption. If your endpoint is using https you could try change to http for unencrypted api call. If that is an option.

If you are only releasing your app on devices with Google Play Services you can use ProviderInstaller to provide support for 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

There was an issue opened on the okhttp git page which discussed this problem.

https://github.com/square/okhttp/issues/3098

If relying on play services is not an option then its possible to implement yourself.

https://github.com/square/okhttp/issues/2372#issuecomment-244807676

like image 172
Eoin Avatar answered Nov 17 '22 04:11

Eoin