Android Question OkHttpUtils2 and SSL-Problem (maybe TLS?) [SOLVED]

W. Graf

Member
Licensed User
Longtime User
Hi!

I want to download a text-file from a webserver via https (unfortunally the server doesn't support http).
I'm using the library: OkHttpUtils2 on Android 4.4.2

This is my code:

B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://services.swpc.noaa.gov/text/geoalert.txt")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log("Inhalt: " & j.GetString)
End If
j.Release

This file has a size of ~450 bytes and is only plain text (... about space wheater).

I'm getting the following error:
ResponseError. Reason: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x6328e530: Failure in SSL library, usually a protocol error
error:1407743E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:744 0x5e64a7e8:0x00000000), Response:

Because of the text-sequence "SSL23_GET_SERVER_HELLO:tlsv1", I think that the cause of this issue is TLS.

I was searching the web the last few hours, but I only found the hint, that it may be necessary to enable TLS on a phone (it is installed but disabled).
But if I open the textfile with my default browser on my phone, the textfile is displayed without any problems (and it tells me that the connection uses TLS 1.1).

Do you have any ideas, what I can do to successfully download this file?

Thank you and BR!
 

W. Graf

Member
Licensed User
Longtime User
Thank you for testing it and for your advice!

I imported the subs from your link into my app and tried it. But "TryToFix" crashes:

B4X:
Public Sub TryToFix
    Dim jo As JavaObject
    jo.InitializeStatic("com.google.android.gms.security.ProviderInstaller")
    Dim context As JavaObject
    context.InitializeContext
    
    DisableStrictMode

    Dim listener As Object = jo.CreateEventFromUI("com.google.android.gms.security.ProviderInstaller.ProviderInstallListener", _
        "ProviderInstall", Null)
    Log("Installing security provider if needed...")
    jo.RunMethod("installIfNeededAsync", Array(context, listener))
End Sub

The instruction
B4X:
jo.InitializeStatic("com.google.android.gms.security.ProviderInstaller")
fails with error
java.lang.ClassNotFoundException: com.google.android$gms$security$ProviderInstaller

Do you think, that the reason is the same (old Android Version)?

Thanks again!
 
Upvote 0

W. Graf

Member
Licensed User
Longtime User
I also found the following thread:
https://www.b4x.com/android/forum/threads/network-v1-50-adds-support-for-ssl-sockets.55871/

In this thread, you posted the following Code:
B4X:
Dim r As Reflector
r.Target = so 'socket variable
r.Target = r.GetField("socket")
r.RunMethod4("setEnabledProtocols", Array(Array As String("TLSv1", "SSLv3")), _
     Array As String("[Ljava.lang.String;"))

Is it possible to try this for OkHttpUtils2 too? But I have no socket variable with OkHttpUtils2?
Sorry for my missing knowledge ...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

W. Graf

Member
Licensed User
Longtime User
No, the line was missing. After adding it, it works.
EVERYTHING WORKS!!! :) THANK YOU VERY MUCH.

But one last question:
What I have done?? :)
I mean, what is SSL_TryToFix() and SSL_DisableStrictMode() doing?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
It uses a Google Play service that updates the security provider and adds support for newer protocols on old devices.


This disables a check for network calls on the main thread. It is a workaround for an issue with the updated provider.

Good to know
 
Upvote 0
Top