PDA

View Full Version : connect to rest service with qt and error SSL handshake failed



panagiotisss
20th September 2015, 18:55
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::defaultConfigu ration());

QList<QSslCertificate> caList = SslConfiguration.caCertificates();

caList.append(QSslCertificate("cacert.pem")); //Root CA

SslConfiguration.setCaCertificates(caList);

SslConfiguration.setLocalCertificate(QSslCertifica te("bla_bla_server.pem"));

SslConfiguration.setProtocol(QSsl::SslV3);

SslConfiguration.setPeerVerifyMode(QSslSocket::Ver ifyPeer);

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?

ChrisW67
20th September 2015, 20:59
You could start by telling us what the error was (any text output and the QSslError value) and whether you have installed OpenSSL.

panagiotisss
21st September 2015, 08:06
Yes I have installed OpenSSL.
I connect the QNetworkReply:networkerror with a method messageError like this

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

and the error I get is "SSL handshake failed" and the number 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!

ChrisW67
21st September 2015, 11:27
There is no SIGNAL or SLOT matching the signature"sslErrors(QNetworkReply , const QList<QSslError> &)". Perhaps you mean "sslErrors(QNetworkReply*,QList<QSslError>)" and are ignoring the warning printed in the console by connect().
For consistency you could use the sslErrors() signal from the reply object.

If there is a more general SSL library issue you will also see warnings about that in the output.

panagiotisss
21st September 2015, 13:23
I don't know if I have understand well what you have proposed.
I have added the following line

connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslError2(const QList<QSslError>)));

but the execution of the program does not get inside sslError2 slot.

panagiotisss
24th September 2015, 09:56
I have achieved to pass this error by copying msvcr120.dll and msvcp120.dll in to bin folder of openssl
But now I receive new errors
QSslSocket: cannot call unresolved function SSLv3_client_method
QSslSocket: cannot call unresolved function SSL_CTX_new
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function ERR_get_error

I have the test line of code in qt
qsslsocket::supportsssl()
that returns false

In my .pro file I have the qt+=network and I have also paste to qt bin folder the following dlls
libeay32.dll
libssl32.dll
ssleay32.dll

Any idea about that?