2011-05-09 4 views
3

OpenSSL을 사용하는 응용 프로그램을 작성합니다. 어제부터 모두 괜찮 았어. 나는 응용 프로그램을 컴파일하고 내 친구에게 보냈습니다. 컴퓨터 응용 프로그램에서 https를 열 수 있습니다. 다른 컴퓨터에서 열면 작동하지 않습니다. 그래서 나는 그것을 다른 친구에게 주었고 그는 https 웹 사이트를 열 수 없다. 혼란 스러웠고 다른 사람에게 컴퓨터를 보냈습니다. 내 앱이 작동 중입니다. 나는 상황을 이해하지 못한다. 이전 버전은 버그없이 작동했습니다. 하지만 작동했던 이전 버전을 돌렸고 작동하지 않습니다. 나는 모든 방화벽을 껐다. 아무것도 바뀌지 않았다.Qt OpenSSL 문제 - 일부 컴퓨터에서 차단 (?)

제안 사항?

우리 모두 7 x64입니다. 나는 XP에서 그는 테스트를 거쳤으며 7 x64에서 동작하지 않는다. 내 친구의 컴퓨터에서 7 x64 작품이지만 XP에서는 작동하지 않습니다. IMO 운영체제에는 아무런 의미가 없습니다.

+1

"작동하지 않음"으로 무엇을 의미하는지 자세히 설명하면 도움이됩니다. 특정 오류가 유용합니다. –

+0

https가로드되지 않습니다. SSL 페이지에 요청을 보내면 빈 페이지가 반환됩니다. 내 faut, 나는 "작동하지 않습니다"설명하지 않았다 – RzuF

답변

2

기본적으로 Qt에는 OpenSSL 구현이 포함되어 있지 않지만 시스템에 이미 설치된 라이브러리가 사용됩니다.

Win32 OpenSSL을 설치하면 작동됩니다.

또 다른 옵션은 Qt를 OpenSSL로 빌드하는 것입니다. 일부 정보 here.

+0

나는 Qt를 OpenSSL로 빌드한다. 내 PC에 더있는 것 OpenSSL이 설치되어 있지만 내 앱이 작동하지 않습니다. – RzuF

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