0

I've built an Android App that I'm using to send a camera captured image to our server. I convert the Bitmap to a Base64 String view the following code:

ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOS);
return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);

Now I'm actually running into a few problems, one of which is that I will intermittently get a SSLHandshakeException but it doesn't happen every time so I'm very confused, I've tried many different angles to solve this issue with possible solutions from StackOverflow but nothing seems to work.

The exact exception is

javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x601201b8: Failure in SSL library, usually a protocol error

error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:742 0x5d066d74:0x00000000)

It does seem to work sometimes but I can't pinpoint what are the factors that allow it to work vs notworking. Also I thought at some point it could be a timeout issue so I set the timeout limit of the HttpsURLConnection to an arbitrarily large number e.g.

        secureConnection = (HttpsURLConnection) url.openConnection();
        secureConnection.setConnectTimeout(100000);
        HttpURLConnection.setFollowRedirects(false);
        secureConnection.setRequestMethod(requestType.toString());
        secureConnection.setRequestProperty("Content-Type", contentType.toString());
        secureConnection.setConnectTimeout(3000);
        secureConnection.setReadTimeout(3000);
        secureConnection.setDoInput(true);
        secureConnection.setDoOutput(true);

The other solution I attempted was to try and accept all certs in case my device was rejecting the server certificate How to solve javax.net.ssl.SSLHandshakeException Error?

Some other info is that I'm testing this on an Android 4.4 device, and using the latest Android Studio version. If it was something that consistently happening I'd know exactly what was wrong but it only happens sometimes :( but its a pain because I can't get past it.

Community
  • 1
  • 1

0 Answers0