Skip to content
Advertisement

Android Https web service communication (SSL / TLS 1.2)

In my Android application I’ve got to communicate with a https web service and read the response.

I’ve informed the server configured SSL with TLS 1.2.

I am using the following sample code to connect with the service (https get request), but only the devices that runs Android 5.0 or above can successfully communicate and read the response….

All the other devices below that version (Android 5.0) can’t communicate and thrown IOException at the time when trying to establish connection…

JavaScript

OR

JavaScript

Question 1

Would like to know if I am doing anything wrong in here (if any additional parameter is missing in my code that will support older versions of Androids than 5.0 to support TLS 1.2 web service communication) ?

Question 2

I just googled and found this DOCUMENT.

There it says the minimum supporting browser in ANDROID to communicate with TLS 1.2 is “GOOGLE Android 5.0 OS Browser”. So is it the same restriction applying when trying to connect by the code (Apps)?

if so what would be the minimum Android version I should support if want to communicate with this web service (the minimum version of android that support TLS 1.2 web services)?

Sample exception stack traces are as follows

Android 2.2 Simulator

JavaScript

Android 3.0 Simulator

JavaScript

EDITS

This is the full stack trace when use Robert’s MySSLSocketFactory class implemention with an Android 4.4.2 AND Android 5.1.1 device.

JavaScript

Advertisement

Answer

According to the Android Developer documentation TLS 1.2 is available and enabled on devices with API level 20+ (Android 4.4 Wearable):

http://developer.android.com/reference/javax/net/ssl/SSLEngine.html

I assume non of your test devices uses that API level therefore you got the result that only 5.0 devices can connect.

My personal experience is that some 4.4 devices support TLS 1.2 however it is not enabled. You can try to enable it by calling setEnabledProtocols(new String[]{"TLSv1.2"}) on the used SSLSocket.

An elegant solution doing so is implementing an own SSLSocketFactory using the Proxy pattern:

JavaScript

You can use it this way:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement