エラーの解決策がまだない場合は、同じ問題に遭遇しました。Windows コンピューターの CA 証明書チェーンに問題があるようです。詳細はhttps://bugreports.qt-project.org/browse/QTBUG-20012にあります。
アプリケーションでエラーが発生しないように ca チェーンを修正する小さなクラスもあります。
#ifndef OPENSSLFIX_H
#define OPENSSLFIX_H
#include <QSslConfiguration>
/* this class fixes a problem with qt/openssl and expired ca certificates.
* the idea is taken from https://bugreports.qt-project.org/browse/QTBUG-20012
* which describes the problem and the workaround further. the workaround is
* scheduled for qt5, but will not be introduced into qt4.x.
*
* to use this fix just call it in main() before doing any network related
* stuff
*
* OpenSslFix::fixCaCertificates();
*
* it will go through the certificates and remove invalid certs from the chain,
* thus avoiding the error to arise.
*/
class OpenSslFix {
public:
static void fixCaCertificates()
{
QSslConfiguration config(QSslConfiguration::defaultConfiguration());
QList<QSslCertificate> in(config.caCertificates());
QList<QSslCertificate> out;
for (int i=0, size=in.size(); i<size; ++i) {
const QSslCertificate &c(in[i]);
if (c.isValid()) {
/* not expired -> add */
out << c;
continue;
}
/* check if the cert is already present in the output */
bool found = false;
for (int j=0, size=out.size(); j<size; ++j) {
if (isCertificateSameName(c, out[j])) {
/* already present... */
found = true;
break;
}
}
if (!found)
out << c;
}
/* now set the new list as the default */
config.setCaCertificates(out);
QSslConfiguration::setDefaultConfiguration(config);
}
private:
static inline bool isCertificateSameName(const QSslCertificate &cert1,
const QSslCertificate &cert2)
{
return cert1.subjectInfo(QSslCertificate::Organization) ==
cert2.subjectInfo(QSslCertificate::Organization) &&
cert1.subjectInfo(QSslCertificate::CommonName) ==
cert2.subjectInfo(QSslCertificate::CommonName) &&
cert1.subjectInfo(QSslCertificate::LocalityName) ==
cert2.subjectInfo(QSslCertificate::LocalityName) &&
cert1.subjectInfo(QSslCertificate::OrganizationalUnitName) ==
cert2.subjectInfo(QSslCertificate::OrganizationalUnitName) &&
cert1.subjectInfo(QSslCertificate::StateOrProvinceName) ==
cert2.subjectInfo(QSslCertificate::StateOrProvinceName) &&
cert1.subjectInfo(QSslCertificate::CountryName) ==
cert2.subjectInfo(QSslCertificate::CountryName);
}
};
#endif // OPENSSLFIX_H