4

QSslSocket を使用してサーバーに接続したいのですが、サーバーで soketSslError "The certificate is self-signed, and untrusted" が発生しますが、なぜこのエラーが発生するのかわかりません。

最初のステップでは、openssl を使用してサーバーとクライアント用のファイルを生成しました

$openssl req -new -newkey rsa:1024 -keyout ca.key -x509 -days 500 -out ca.crt
$openssl req -new -newkey rsa:1024 -keyout client01.key -out client01.csr
$openssl ca -config ca.config -in  client01.csr -out client01.crt -batch

C++ サーバー/クライアントで

サーバー上:

サーバーを起動

if (listen(QHostAddress::Any,this->connectingPort)) {
        std::cout<<"Server start on port: "<<this->connectingPort<<std::endl;
        return true;
    } else {
        std::cout<<"Cant start server. "<<errorString().toStdString().c_str()<<std::endl;
        return false;
    }

着信接続

    QFile keyFile("ca.key");
    if (!keyFile.open(QIODevice::ReadOnly)) {
        delete this->sslSocket;
        qDebug()<<"Cant open file: "<<keyFile.fileName();
        return false;
    }
    QByteArray pasp ="qwerty";
    QSslKey key(keyFile.readAll(),QSsl::Rsa,QSsl::Pem,QSsl::PrivateKey,pasp);
    if (key.isNull()) {
        delete this->sslSocket;
        qDebug()<<"key in file "<<keyFile.fileName()<<" is empty";
        return false;
    }
    keyFile.close();

    this->sslSocket->setPrivateKey(key);
    this->sslSocket->setPeerVerifyMode(QSslSocket::VerifyPeer);
    this->sslSocket->setLocalCertificate("ca.crt");
    this->sslSocket->startServerEncryption();

クライアント側:

this->sslSocket->setPeerVerifyMode(QSslSocket::VerifyPeer);


QFile keyFile("client01.key");

if (!keyFile.open(QIODevice::ReadOnly)) {
    delete this->sslSocket;
    qDebug()<<"Cant open file: "<<keyFile.fileName();
    return ;
}
QByteArray pasp ="qwerty";
QSslKey key(keyFile.readAll(),QSsl::Rsa,QSsl::Pem,QSsl::PrivateKey,pasp);
if (key.isNull()) {
    delete this->sslSocket;
    qDebug()<<"key in file "<<keyFile.fileName()<<" is empty";
    return ;
}
keyFile.close();

this->sslSocket->setPrivateKey(key);

this->sslSocket->setLocalCertificate("client01.crt");

this->sslSocket->connectToHostEncrypted("192.168.0.10",1258);

if (!this->sslSocket->waitForEncrypted()) {
    qDebug()<<"error: "<<sslSocket->errorString();
}

クライアントから接続すると、サーバーエラーが発生します

soket ssl error
"The certificate is self-signed, and untrusted" 
"The certificate is self-signed, and untrusted" 
socketError:  QAbstractSocket::SocketError( 13 ) 

私が間違っていることは何ですか?

アップデート:

Qt Creator 3.0.1 Qt 5.2.1 ベース (GCC 4.8.2、64 ビット)

4

2 に答える 2