I have had a look at several different attempts of ignoring SSL handshake errors in Qt but I have gotten none to work. I am using a self signed certificate and during development I would just like to ignore any error in case I have to change certs or something else happens.
I've looked at:
http://qt-project.org/doc/qt-5/qnetworkaccessmanager.html#sslErrors
https://qt-project.org/forums/viewthread/17456
Weird Qt SSL issue -- error "No Error" shows up, nothing else, and if I ignore it, everything works
http://www.qtcentre.org/threads/48736-Ignore-SSL-Errors
http://xizhizhu.blogspot.se/2010/08/basic-samples-for-ssl-communication.html
Here is my request code
mManager = new QNetworkAccessManager(this);
... // adding onRequestComplete slot and creation of postdata and request
QObject::connect(mManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(onSslError(QNetworkReply*, QList<QSslError>)));
QNetworkReply *reply = mManager->post(request, postData);
//QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(onSslError(QList<QSslError>)));
As you can see I have tried both to connect to the networkmanager signal and to the reply signal. Here are my slots:
void onSslError(QList<QSslError> errors) {
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
reply->ignoreSslErrors();
}
void onSslError(QNetworkReply* r, QList<QSslError> l) {
r->ignoreSslErrors();
}
When I make a regular HTTP request that works fine. Changing the QUrl in the request to https causes my issue. The error I get in my onRequestComplete slot is "Could not initiate SSL context".
I've tried setting breakpoints in both the slots and they never trigger and it seems to me that then the ignoreSslErrors call is never executed. Any help is greatly appreciated.
It better to use it this way:
QList<QSslError> errorsThatCanBeIgnored;
errorsThatCanBeIgnored << QSslError(QSslError::HostNameMismatch, cert);
errorsThatCanBeIgnored << QSslError(QSslError::SelfSignedCertificate, cert);
ignoreSslErrors(errorsThatCanBeIgnored);