2017-01-23 9 views
0

아래 코드에서 "QSslCertificate :: fromPath"가 지정한 파일을 찾지 못했지만 확인했을 때 문제가 있습니다. 아래의 fileExists-function을 사용하면 파일이 결국 있음을 알 수 있습니다. 이 문제는 내 개발 PC와 다른 PC에서 응용 프로그램을 실행하려고 할 때만 발생합니다. 나는 윈도우 10 64 비트에서 개발, 테스트 PC는 윈도우 7 64 비트입니다. QT 5.4.0을 사용합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?Qt : QSslCertificate :: fromPath가 내 파일을 찾지 못했지만 QFileInfo가 파일을 찾음

void MyClass::init() 
{ 

    // ... some other init code 

    QLatin1String rootCApath = QLatin1String("./ssl/rootCA.crt"); 
    if (fileExists(rootCApath)) 
     log("File exists"); // This is just a log function for displaying messages in the GUI. 
    else 
     log("File doesn't exist"); 

    static QList<QSslCertificate> cert = QSslCertificate::fromPath(rootCApath); 
    if(cert.size()==1) 
    { 
     ssl_configuration.setCaCertificates(cert); 
     m_webSocket.setSslConfiguration(ssl_configuration); 
    } 
    else 
    { 
     QString s = "Server certificate not found. Size is " + QString::number(cert.size()); 
     log(s); 
    } 
} 

bool MyClass::fileExists(QString path) { 
    QFileInfo check_file(path); 
    // check if file exists and if yes: Is it really a file and no directory? 
    return check_file.exists() && check_file.isFile(); 
} 

편집 : 그리고 나는 QByteArray에 인증서를 읽고 내 Windows 10 개발자 PC의 모든 여전히 잘 작동에있는 동안, 다음 내 연결 기능이 윈도우 7 PC에 아무것도하지 않습니다에 하나를 통과 할 때 .

또한 내가하는 일과 상관없이 일관되게 TLS 핸드 셰이크 오류를 제공하는 또 다른 PC가 있습니다. 3 PC, 3 결과, 우울합니다.

답변

0

를 내 경우에 해결책을 발견 : 어디 디렉토리에는 OpenSSL 라이브러리 않으면 LIBEAY32.dll 추가 ssleay32.dll하지 않았다 내 exe가 들어 있습니다.

0

코드가 잘 보이고 내 Linux 시스템에서 아무 문제없이 작동합니다. 당신은 상대 경로를 확인해야하거나 QFileInfo를 통해 인증서를 설정하려고 :

QLatin1String rootCApath = QLatin1String("./ssl/rootCA.crt"); 
QFileInfo temp(rootCApath); 
QString tempssl; 
QDir dir ;//try to set dir also if this does not work dir("/home/foo/yourapppath/"); 

tempssl=dir.relativeFilePath("./ssl/rootCA.crt"); 
static QList<QSslCertificate> cert = QSslCertificate::fromPath(tempssl); 

if(cert.size()==1) 
{ 
    ssl_configuration.setCaCertificates(cert); 
    m_webSocket.setSslConfiguration(ssl_configuration); 
} 
else 
{ 
    QString s = "Server certificate not found. Size is " + QString::number(cert.size()); 
    log(s); 
} 
+0

QCoreApplication :: applicationDirPath()에 QDir 디렉토리를 설정했는지 여부에 관계없이 불행히도이 작업이 도움이되지 않았습니다. – Alex

관련 문제