Android Question error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3

iNKUBO

Member
Hi, i recently updated to B4a v11.20 and one of my apps stopped working.

I get an error when trying to get an url with httpjob

error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x9e0a06e2:0x00000000), Response:

B4X:
Private Sub Comprobar2_Click
    Activity.LoadLayout("premiados")
    Dim url As String
    url="https://www.laprimitiva.info/"
    Dim x As Int
    Dim i As Int
    Dim acertado As Int=0
    Dim complementario As Int=0
    Dim combinacion As String
    Dim lacombi As List
    Dim elacierto As List
    Dim elcomplem As List
    Dim inicio As String
    Dim final As String
    Dim index1 As Int
    Dim index2 As Int
    Dim mat As Matcher
    Dim premiados As List
    premiados.Initialize
    elacierto.Initialize
    elcomplem.Initialize
    lacombi.Initialize
    Dim html As String
    Dim http As HttpJob
    Dim mensaje As List
    mensaje.Initialize
    Dim rs As ResultSet
    http.Initialize("",Me)
    Dim texto As String
    
    '--------------------------------------
    
    
    http.Download(url)
    Wait For (http) JobDone(http As HttpJob)
    If http.Success Then
        html=http.getString
        inicio =$"<article class="$
        final=$"</article>"$
        Dim index1 As Int=html.IndexOf(inicio)
        Dim index2 As Int=html.IndexOf(final)
        html=html.Substring2(index1,index2)
    End If
    http.Release
    inicio=$"<div class="combi">"$
    final=$"<div class="sepanum"></div>"$
    index1=html.IndexOf(inicio)
    index2=html.IndexOf(final)
    html=html.Substring2(index1,index2)
    
    Dim patron As String=$"<div class=\"num\">(\d+)<\/div>"$
    mat=Regex.Matcher(patron,html)
    
    Do While mat.Find = True
        premiados.Add(mat.Group(1))
    Loop

    rs=sql.ExecQuery("select n1,n2,n3,n4,n5,n6 from apuestas")

    Do While rs.NextRow
        acertado=0
        complementario=0
        combinacion=rellena(rs.GetInt("n1"))&"-"&rellena(rs.GetInt("n2"))&"-"&rellena(rs.GetInt("n3"))&"-"&rellena(rs.GetInt("n4"))&"-"&rellena(rs.GetInt("n5"))&"-"&rellena(rs.GetInt("n6"))
        'Log(combinacion)
        For i = 1 To 6
            For x=0 To 5
                If rs.getInt("n"&i)=premiados.Get(x) Then
                    acertado=acertado+1
                End If
            Next
        Next
        For i=1 To 6
            If rs.getInt("n"&i)=premiados.Get(6) Then
                complementario=complementario+1
            End If
        Next
        mensaje.Add("[ "&combinacion&" ] : Acertados:" & acertado & " Complementario:"&complementario)       
        lacombi.add(combinacion)
        elacierto.add(acertado)
        elcomplem.add(complementario)
        If acertado>=3 Then       
            MsgboxAsync("Tienes un premio de "&acertado&" Aciertos y "&complementario&" Complementario con la combinacion : ["&combinacion&"]","PREMIO!!")
        End If
    Loop
    texto=""
    For i=0 To 5
        If i=0 Then
            texto=rellena(premiados.Get(i))
        Else
            texto=texto&"-"&rellena(premiados.Get(i))
        End If
    Next
    texto="[ "&texto& " ]   COMP:" & rellena(premiados.Get(6)) & " REINT:"&rellena(premiados.Get(7))
    For i = 0 To mensaje.Size-1   
         premio_grid.Add(crea_row_premiados(lacombi.Get(i),elacierto.Get(i),elcomplem.Get(i)),i)
        'ListView1.AddSingleLine(mensaje.Get(i))
    Next
    Ganadora.Text=texto

The error:

Error:
Installing security provider if needed...
Error installing provider: 2
Panel size is unknown. Layout may not be loaded correctly.~i:Panel size is unknown. Layout may not be loaded correctly.
*** Service (httputils2service) Create ***
(Http client initialized with accept all option.)
** Service (httputils2service) Start **
ResponseError. Reason: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb7626948: 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:741 0x9e0a06e2:0x00000000), Response:
main$ResumableSub_Comprobar2_Clickresume (java line: 1029)
java.lang.StringIndexOutOfBoundsException: length=0; regionStart=-1; regionLength=0
    at java.lang.String.startEndAndLength(String.java:593)
    at java.lang.String.substring(String.java:1474)
    at b4a.Primitiva.main$ResumableSub_Comprobar2_Click.resume(main.java:1029)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

I searched the forum and have already tested all posible workarounds

Also calling ActivateSSL from Starter.bas at service_create function

B4X:
Sub ActivateSSL

    Dim javaobjectContext                                                       As JavaObject
    Dim javaobjectInstance                                                      As JavaObject
    Dim objectListener                                                          As Object
    Dim phoneInstance                                                           As Phone

    Try
        Select Case phoneInstance.SdkVersion
            Case 16, 17, 18, 19, 20 ' Android 4.1 - 4.4
            Case Else
                Return
        End Select
        javaobjectInstance.InitializeStatic ("com.google.android.gms.security.ProviderInstaller")
        javaobjectContext.InitializeContext
        DisableStrictMode
        objectListener = javaobjectInstance.CreateEventFromUI ("com.google.android.gms.security.ProviderInstaller.ProviderInstallListener", "objectListener", Null)
        javaobjectInstance.RunMethod ("installIfNeededAsync", Array (javaobjectContext, objectListener))
        Wait For objectListener_Event (stringMethodName As String, objectArguments () As Object)
        ' If stringMethodName = "onProviderInstalled" Then [ Provider installed successfully ] Else [ Error installing provider (objectArguments (0)) ]
    Catch
        Log("Application_Error")
    End Try

End Sub

Sub DisableStrictMode

    Dim javaobjectInstance                                                      As JavaObject
    Dim javaobjectPolicy                                                        As JavaObject
    Dim javaobjectStrictMode                                                    As JavaObject

    Try
        javaobjectInstance.InitializeStatic ("android.os.Build.VERSION")
        If javaobjectInstance.GetField ("SDK_INT") > 9 Then
            javaobjectPolicy = javaobjectPolicy.InitializeNewInstance ("android.os.StrictMode.ThreadPolicy.Builder", Null)
            javaobjectPolicy = javaobjectPolicy.RunMethodJO ("permitAll", Null). RunMethodJO ("build", Null)
            javaobjectStrictMode.InitializeStatic ("android.os.StrictMode"). RunMethod ("setThreadPolicy", Array (javaobjectPolicy))
        End If
    Catch
        Log("Application_Error")
    End Try

End Sub

This is the manifest part

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/>
    <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
)


#AdditionalJar: com.google.android.gms:play-services-base
was added to Region Project Attributes

I've tried to use HU2_ACCEPTALL as suggested
1641216342692.png
 

iNKUBO

Member
Thank you Erel, yes this part of the code is not controlled yet for exceptions, i'm still developing it...
I think that it's a problem with my virtual device only ( Android 4.1.2 -SDK 16 ), other versions of SDK don't work well at my pc, no HAXM available with my processor, and when i create a virtual device with SDK 25, it does not run, get stucked and does not start.

The app is working well at a real device with Android 9, i'll give a try to BlueStacks or other emulator for developing...

Thanks again for your advice and sorry for the inconvenience
 
Upvote 0
Top