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? -
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!
-
What version of Qt and OS are you running ?
-
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?