Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

connect to rest service with qt and error SSL handshake failed



  • 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?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

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



  • 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!


  • Lifetime Qt Champion

    What version of Qt and OS are you running ?



  • I am running qt 4.8.2 in windows xp


  • Lifetime Qt Champion

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



  • 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?



  • 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.



  • This post is deleted!


  • 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.


Log in to reply