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. connect to rest service with qt and error SSL handshake failed

connect to rest service with qt and error SSL handshake failed

Scheduled Pinned Locked Moved General and Desktop
qnetworkrequestssl failed
10 Posts 3 Posters 11.1k 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.
  • V Offline
    V Offline
    vagelis
    wrote on last edited by
    #1

    I am trying to connect to rest service that has ssl certificates. I have those certificates files(cacert.pem and another file .pem) locally.
    For this purpose I use qt library.
    I can connect to a rest service without certificates but I cannot connect to a service with certificates.

    I try this code(having the certificate in the release folder of the project)

    QNetworkAccessManager *m_network = new QNetworkAccessManager(this);

    QNetworkRequest request;
    
    QUrl wapi_url=QUrl("...");
    
    wapi_url.setPort(8082);
    
    request.setUrl(wapi_url);
    
    QSslConfiguration SslConfiguration(QSslConfiguration::defaultConfiguration());
    
    QList<QSslCertificate> caList = SslConfiguration.caCertificates();
    
    caList.append(QSslCertificate("cacert.pem")); //Root CA
    
    SslConfiguration.setCaCertificates(caList);
    
    SslConfiguration.setLocalCertificate(QSslCertificate("bla_bla_server.pem"));
    
    SslConfiguration.setProtocol(QSsl::SslV3);
    
    SslConfiguration.setPeerVerifyMode(QSslSocket::VerifyPeer);
    
    request.setSslConfiguration(SslConfiguration);
    QNetworkReply *reply = m_network->get(request);
    

    but I get a SSL handshake failed error.
    Any idea how can I pass this error and connect to the rest service?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You can connect the sslErrors signal from QNetworkReply to have more information about what is happening exactly.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vagelis
        wrote on last edited by vagelis
        #3

        Hi SGaist,

        I have already done a connection like that

        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,SLOT(messageError(QNetworkReply::NetworkError)));

        and the error I get is "SSL handshake failed" as I have already mentioned.
        This is the QNetworkReply errorString.
        The QNetworkReply error is "6".

        I also have added a connection like that

        connect(m_network, SIGNAL(sslErrors(QNetworkReply , const QList<QSslError> &)), this, SLOT(sslError(QNetworkReply, const QList<QSslError> &)));

        but my code doesn't go inside sslError method.
        Any idea about that?

        THank you in advance!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What version of Qt and OS are you running ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vagelis
            wrote on last edited by
            #5

            I am running qt 4.8.2 in windows xp

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              That's pretty old. What version of OpenSSL did you install ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • V Offline
                V Offline
                vagelis
                wrote on last edited by
                #7

                I have installed openssl 0.9.8.
                But I have tried the code also in another pc that has windows 7 and openssl 1.0.2 and the same error occured.
                Do you think that my code is ok?
                Do I pass the certificates by the right way?
                And does anyone know a working way to call a rest service with certificates?

                1 Reply Last reply
                0
                • hskoglundH Online
                  hskoglundH Online
                  hskoglund
                  wrote on last edited by
                  #8

                  Hi, with openssl 1.02 I also had problems with the SSL handshake.
                  But when i copied the MSVC2013 runtime files msvcr120.dll and msvcp120.dll and put them together with ssleay32.dll etc. my problems went away and I could connect ok.

                  1 Reply Last reply
                  1
                  • V Offline
                    V Offline
                    vagelis
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • hskoglundH Online
                      hskoglundH Online
                      hskoglund
                      wrote on last edited by
                      #10

                      Hi, this post might help you, basically it says you should check you've copied also the Qt4Core.dll, Qt4Gui.dll etc. to your bin directory.

                      1 Reply Last reply
                      0

                      • Login

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