Weird Qt SSL issue — error “No Error” shows up, no

2019-07-24 07:13发布

问题:

The issue is as follows : in my Qt app, I have a QWebView, which I use to load a HTTPS page.

Everything worked fine on my development machine, so I'm now trying to get it to run on a test machine. I ran the app, but the page didn't load (the QWebView was blank). After much debugging, I found the problem is that an SSL error shows up, and the sslErrors() signal is fired.

Here is my sslErrors() handling code:

void blah::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors) {
  foreach(QSslError error, errors) {
    qDebug() << error.errorString() << endl;
  }
  reply->ignoreSslErrors();
}

The only thing the above code prints is:

"No error"

So there's no error, but unless I call reply->ignoreSslErrors(), the page doesn't load (on the test machine, on my developer computer no error is reported). Huh? Is this a bug?

Is it safe to ignore the error, if I make sure it's of the type "No error"?

回答1:

QSslSocket builds a NoError SslError only when translating an OpenSSL X509_V_OK error.

The OpenSSL documentation reports:

If no peer certificate was presented, the returned result code is X509_V_OK. This is because no verification error occurred, it does however not indicate success.

You should use tcpdump or a similar tool to check that certificates are correctly exchanged between peers.



回答2:

You may be hitting QTBUG-28343 which is due to a binary incompatibility in openssl between the version your Qt was compiled against and the one you are running. This will be fixed in Qt 4.8.5.

http://lists.qt-project.org/pipermail/announce/2013-January/000020.html https://bugreports.qt-project.org/browse/QTBUG-28343