Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problems connection to WSS with QWebSocket
QtWS25 Last Chance

Problems connection to WSS with QWebSocket

Scheduled Pinned Locked Moved Solved General and Desktop
qwebsocketerrorssltlsopenssl
5 Posts 3 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    erazem
    wrote on last edited by
    #1

    Hi,

    I'm trying to implement a client using QWebSocket to connect to various WSS servers. It works without any problems on all servers but one. That one problematic server never invokes "connected" signal while "disconnected" is invoked just after "error" signal. The captured error is:
    "Error during SSL handshake: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version"

    QWebSocket* socket = new QWebSocket();
    connect( socket, &QWebSocket::connected, this, [=]() 
    { 
        qInfo() << "connected"; 
    });
    connect( socket, &QWebSocket::disconnected, this, [=]() { 
        QString err = ((QWebSocket*)sender())->errorString();
        qInfo() << "disconnected" << err; 
    });
    connect( socket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), [socket](QAbstractSocket::SocketError error) { 
        qInfo() << "error";
    });
    
    typedef void (QWebSocket:: *sslErrorsSignal)(const QList<QSslError> &);
    connect( socket, static_cast<sslErrorsSignal>(&QWebSocket::sslErrors), this, [socket]( const QList<QSslError> &errors )
    {
        socket->ignoreSslErrors( errors );
    });
    socket->open( QUrl("wss://api.huobi.pro/ws") );
    

    I have the latest OpenSSL installed, and environment is set to point to openssl's bin folder. I even tried copying all dlls from bin folder into Debug folder. No difference.

    I didn't need to install OpenSSL specifically (however it might be part of the system) to successfully connect to other servers. If I try to connect to the same server with NodeJS it works just fine.

    I get some warnings when starting the application, before even trying to connect to the server. So far there was no problems with SSL and I ignored it.
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method
    qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method
    qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto
    qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_s
    qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_nego
    qt.network.ssl: QSslSocket: cannot resolve SSL_set_alpn_protos
    qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_
    qt.network.ssl: QSslSocket: cannot resolve SSL_get0_alpn_selected

    Further: QSslSocket::sslLibraryBuildVersionString returns "OpenSSL 1.0.2j 26 Sep 2016".

    Server is a public service and I have no control over it. Locally I'm running the client on windows7 64bit.

    I tried ignoring the SSL errors but nothing happened. Code excerpt:

    typedef void (QWebSocket:: *sslErrorsSignal)(const QList<QSslError> &);
    connect( socket, static_cast<sslErrorsSignal>(&QWebSocket::sslErrors), this, [=]( const QList<QSslError> &errors )
    {
      ((QWebSocket*)sender())->ignoreSslErrors();
    });
    

    QSslSocket::supportsSsl() returns true.

    Is there anything else I need to do? Like load certificate? Do I need to set up OpenSSL? I don't have any clues left.
    Any help would be welcome?

    BR
    Erazem

    raven-worxR 1 Reply Last reply
    0
    • E erazem

      Hi,

      I'm trying to implement a client using QWebSocket to connect to various WSS servers. It works without any problems on all servers but one. That one problematic server never invokes "connected" signal while "disconnected" is invoked just after "error" signal. The captured error is:
      "Error during SSL handshake: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version"

      QWebSocket* socket = new QWebSocket();
      connect( socket, &QWebSocket::connected, this, [=]() 
      { 
          qInfo() << "connected"; 
      });
      connect( socket, &QWebSocket::disconnected, this, [=]() { 
          QString err = ((QWebSocket*)sender())->errorString();
          qInfo() << "disconnected" << err; 
      });
      connect( socket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), [socket](QAbstractSocket::SocketError error) { 
          qInfo() << "error";
      });
      
      typedef void (QWebSocket:: *sslErrorsSignal)(const QList<QSslError> &);
      connect( socket, static_cast<sslErrorsSignal>(&QWebSocket::sslErrors), this, [socket]( const QList<QSslError> &errors )
      {
          socket->ignoreSslErrors( errors );
      });
      socket->open( QUrl("wss://api.huobi.pro/ws") );
      

      I have the latest OpenSSL installed, and environment is set to point to openssl's bin folder. I even tried copying all dlls from bin folder into Debug folder. No difference.

      I didn't need to install OpenSSL specifically (however it might be part of the system) to successfully connect to other servers. If I try to connect to the same server with NodeJS it works just fine.

      I get some warnings when starting the application, before even trying to connect to the server. So far there was no problems with SSL and I ignored it.
      qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method
      qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method
      qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method
      qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method
      qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto
      qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_s
      qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_nego
      qt.network.ssl: QSslSocket: cannot resolve SSL_set_alpn_protos
      qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_
      qt.network.ssl: QSslSocket: cannot resolve SSL_get0_alpn_selected

      Further: QSslSocket::sslLibraryBuildVersionString returns "OpenSSL 1.0.2j 26 Sep 2016".

      Server is a public service and I have no control over it. Locally I'm running the client on windows7 64bit.

      I tried ignoring the SSL errors but nothing happened. Code excerpt:

      typedef void (QWebSocket:: *sslErrorsSignal)(const QList<QSslError> &);
      connect( socket, static_cast<sslErrorsSignal>(&QWebSocket::sslErrors), this, [=]( const QList<QSslError> &errors )
      {
        ((QWebSocket*)sender())->ignoreSslErrors();
      });
      

      QSslSocket::supportsSsl() returns true.

      Is there anything else I need to do? Like load certificate? Do I need to set up OpenSSL? I don't have any clues left.
      Any help would be welcome?

      BR
      Erazem

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @erazem
      what version of Qt are you using?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • E Offline
        E Offline
        erazem
        wrote on last edited by
        #3

        I'm using Qt 5.10.1

        1 Reply Last reply
        0
        • Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @erazem said in Problems connection to WSS with QWebSocket:

          Error during SSL handshake: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

          You may need to look for more information about this error that OpenSSL is showing. At first glance, it looks like a handshake error i.e. your Qt client (which works fine with other servers) cannot work with this one. See this answer for instance.

          Given you cannot control the server, you may want to use openssl as stated in the answer to at least check/confirm that you can connect with a particular protocol version, see this answer which points ... is alerting you that the server doesn't want to talk TLS v1.0 so when you find a proper protocol that server accepts, you need to set it in the QSSLSocket your QWebsocket is using.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • E Offline
            E Offline
            erazem
            wrote on last edited by
            #5

            Ok, thanks for the reply. It pointed me in the correct direction and after many failures I finally figured it out.
            I guess you only learn when you need to dig deep.

            The only thing I had to do was install the correct version of openSSL. Since it is my first time I had no idea what the letter actually meant, I picked the first build, which was version g, I had to install version n.

            For all future wanderers, the only thing you need to do to make the client work is one of the two options:

            1. Just copy ssleay32.dll and libeay32.dll to working directory OR
            2. Install the latest version and set PATH to the folder where the two dlls are located.

            After that you can use QWebSocket without even knowing SSL exists. Just call:

            QWebSocket socket;
            socket.open( QUrl("someaddress") );
            

            And, when the dlls are found the warnings disappear.

            That's it.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved