Android Question SSL Websocket client

Discussion in 'Android Questions' started by LucaMs, Jan 18, 2018.

  1. LucaMs

    LucaMs Expert Licensed User

    Trying to connecting to my websocket server:

    closed javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x63a133b0: 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 0x61803166:0x00000000)

    Libraries used:
    client: WebSocket 2.00
    server: jServer 2.80

    The server starts and it is reachable (ping). I suppose that if the server SslConfiguration (and the keyvaluestore I created) were incorrect the server would not start/work, correct?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that you are connecting to the SSL port?
     
  3. LucaMs

    LucaMs Expert Licensed User

    Yes, it was an old project I modified just to use SSL, then same port.

    Also, if I had set the wrong port...
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    My guess is that the port is wrong.
     
  5. LucaMs

    LucaMs Expert Licensed User

    Unfortunately not.

    client b4a:
    Public Const ServerURL As String = "wss://xxxxxxxxx:52650/xxxx"

    server b4j:
    ConfigureSSL(52650)
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You should provide more information.

    Example of a working ssl connection using the libraries you mentioned:
    Code:
    Dim ws As WebSocket
    ws.Initialize(
    "ws")
    ws.Connect(
    "wss://b4x.com:51041/smiley/ws")
    Wait For ws_Connected
    Log("connected")
    Wait For ws_TextMessage (Message As String)
    Log(Message)
     
  7. LucaMs

    LucaMs Expert Licensed User

    I don't know what informations.

    My code is very similar to yours.

    Just one thing: creating the keyvaluestore I had to use, temporarily, an IP address; but I think that if this were the problem I would not reach the server (I pinged the server from an online service).

    The old project works perfectly if I do not use SSL.

    I found this:
    https://stackoverflow.com/questions...on-javax-net-ssl-sslprotocolexception-ssl-han

    where they say that there are problems with Android < 4.4 but I'm using Android 4.4.2
     
  8. LucaMs

    LucaMs Expert Licensed User

    Tried this code in my app:
    Code:
    Private Sub TryToConnect
    '    wsh.Initialize(Me, "wsh")
    '    wsh.ws.Connect(Main.ServerURL)

        NewWS.Initialize(
    "NewWs")
        NewWS.Connect(
    "wss://b4x.com:51041/smiley/ws")
        
    Wait For NewWs_Connected
        
    Log("connected here")
        
    Wait For NewWs_TextMessage (Message As String)
        
    Log(Message)
        
    ExitApplication
    End Sub
    No logs (TryToConnect starts, of course)

    This works (browser):
    https://www.b4x.com:51041/smiley/index.html
     
  9. Star-Dust

    Star-Dust Expert Licensed User

    @LucaMs
    To make the ranking of your game safe, use FireBase and not the SSL protocol that in some way can be sniffed by Hacker and used to induce false scores.

    With Firebase the App that sends will be authenticated.
    With SSL you can not identify the genuineness of the sending app. This is the main problem for security.

    Better that you talk to an expert about it rather than improvise solutions
     
    LucaMs likes this.
  10. Erel

    Erel Administrator Staff Member Licensed User

    Please try the attached project and post the logs.
     

    Attached Files:

    • WSS.zip
      File size:
      7.9 KB
      Views:
      107
    LucaMs likes this.
  11. LucaMs

    LucaMs Expert Licensed User

    *** Service (starter) Create ***
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    Connecting
    ** Activity (main) Resume **
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Add this sub:
    Code:
    Sub ws_Closed (Reason As String)
       
    Log("error: " & Reason)
    End Sub
    Is it raised? Are you testing it on a real device?
     
  13. LucaMs

    LucaMs Expert Licensed User

    I'm trying this for A9, but it's the same.

    Anyway, I will not use only SSL, I think.

    Thank you
     
  14. LucaMs

    LucaMs Expert Licensed User

    Added.

    Real device (Android 4.4.2) and, now, in release mode.


    *** Service (starter) Create ***
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    Connecting
    ** Activity (main) Resume **
    error: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x6355af90: 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 0x61803166:0x00000000)
     
  15. Star-Dust

    Star-Dust Expert Licensed User

    But the @Erel code is very useful for me, thank you
     
  16. LucaMs

    LucaMs Expert Licensed User

    I know what the bug is: I AM THE BUG! Every day at least one abnormal problem!
    :mad:
    :)


    This is LUCK
     
    DonManfred likes this.
  17. LucaMs

    LucaMs Expert Licensed User

    It's the same log (Erel's code) using a different old device, Android 4.0.4.
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    I also get this error on an AVD running Android 4. Checking this...
     
    LucaMs likes this.
  19. Erel

    Erel Administrator Staff Member Licensed User

    You can try the attached project. It uses a Google service to update the security provider. It didn't work on the emulator (the ProviderInstaller failed).

    The code is in the starter service.
     

    Attached Files:

    • wss.zip
      File size:
      8.4 KB
      Views:
      158
    Cristian Rufino and LucaMs like this.
  20. LucaMs

    LucaMs Expert Licensed User

    It almost works, since connects, but after 2 seconds:
    *** Service (starter) Create ***
    Installing security provider if needed...
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    Provider installed successfully
    Connecting
    connected
    {"data":[],"etype":"setAutomaticEvents"}
    android.os.NetworkOnMainThreadException
    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
    at com.google.android.gms.org.conscrypt.Platform.blockGuardOnNetwork:)com.google.android.gms@11951070)
    at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.shutdownAndFreeSslNative:)com.google.android.gms@11951070:1)
    at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.close:)com.google.android.gms@11951070:15)
    at com.google.android.gms.org.conscrypt.KitKatPlatformOpenSSLSocketImplAdapter.close:)com.google.android.gms@11951070)
    at io.crossbar.autobahn.websocket.WebSocketConnection.closeAndCleanup(WebSocketConnection.java:405)
    at io.crossbar.autobahn.websocket.WebSocketConnection.access$12(WebSocketConnection.java:394)
    at io.crossbar.autobahn.websocket.WebSocketConnection$2.handleMessage(WebSocketConnection.java:486)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
    at dalvik.system.NativeStart.main(Native Method)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice