Making SSLEngine use TLSv1.2 on Android (4.4.2)?

后端 未结 3 1607
耶瑟儿~
耶瑟儿~ 2020-12-02 10:32

Folks, I\'m hoping there\'s something obvious that I\'m missing, and I hope someone will be able to shed some light. I\'m trying to get TLSv1.2 running in an SSL + NIO cont

相关标签:
3条回答
  • 2020-12-02 10:37

    Try this solution if you are using okHttp. Solution for enabling TLSv1.2 on Android 4.4

    Had the same issue on Android < 5.0 (16 <= API < 20). Thanks to your posts, I was able to make this work, so for anyone who gets here, this is the out-of-the-box solution. At the time of this writing, I'm using OkHttp 3.4.1.

    Tags : Unable to find acceptable protocols, javax.net.ssl.SSLProtocolException: SSL handshake aborted:

    0 讨论(0)
  • 2020-12-02 10:43

    Here is how to do in with AndroidAsync:

    ProviderInstaller.installIfNeeded(context);
    SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
    sslContext.init(KeyManager[] km, TrustManager[] tm, SecureRandom rm);
    SSLEngine engine = sslContext.createSSLEngine();
    AsyncHttpClient.getDefaultInstance().insertMiddleware((AsyncHttpClientMiddleware) engine); 
    

    Updating SSLEngine and inserting it as middleware into AndroidAsync seems to work.

    0 讨论(0)
  • 2020-12-02 10:50

    The Android API docs correctly state that TLSv1.2 is only supported for SSLEngine in API Level 20 or later (Lollipop) while SSLSocket supports it since level 16.

    Using SSLSocket or requiring API 20 was no option for our project and neither was changing the server code to allow TLSv1 or SSLv3. Our solution was to install a newer security provider using Google Play Services:

        ProviderInstaller.installIfNeeded(getApplicationContext());
    

    This effectively gives your app access to a newer version of OpenSSL and Java Security Provider which includes support for TLSv1.2 in SSLEngine. Once the new provider is installed, you can create an SSLEngine which supports SSLv3, TLSv1, TLSv1.1 and TLSv1.2 the usual way:

        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
        sslContext.init(null, null, null);
        SSLEngine engine = sslContext.createSSLEngine();
    

    Or you can restrict the enabled protocols using engine.setEnabledProtocols.

    0 讨论(0)
提交回复
热议问题