我写了一个使用OpenSSL的应用程序。从昨天起,一切都没问题。我编译了应用程序并发送给了我的朋友。在他的计算机应用程序上可以打开https。我打开其他计算机,它不起作用。所以我把它交给了其他朋友,他无法打开https网站。我很困惑,并给了其他人,在他的电脑上,我的应用程序正在运行。我不明白情况。以前的版本没有错误。但我运行以前的版本工作,它也不起作用。我关闭了所有防火墙。什么都没有改变。
有什么建议吗?
我们都有7 x64。我测试了XP HE并且它可以工作,7 x64上的bou不起作用。在我朋友的电脑上7 x64工作,但在XP上他不起作用。 IMO操作系统没有任何意义。
答案 0 :(得分:2)
答案 1 :(得分:2)
尝试使用QSslSocket::ignoreSslErrors()
方法。
我也有这样的问题,使用这个功能为我解决了这些问题。
答案 2 :(得分:2)
如果您仍然无法解决错误 - 我只是遇到了同样的问题。这似乎是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