Qt QSslSocket comodo positive ssl

227 views Asked by At

I have a real bought comodo positive ssl certificate installed on apache and checked the correct installation through the site https://www.sslshopper.com/ssl-checker.html in the kit with the certificate is 5 files

AddTrust_External_CA_Root.crt
COMODO_RSA_Certification_Authority.crt
sslserver.crt
sslserver.key
sslserver.ca-bundle

When I try to connect to my server via the chrome in the console, the following error occurs:

WebSocket connection to 'wss://192.165.10.70:5870/' failed: Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID

And on the server side:

Now listening on 0.0.0.0:5870 ("COMODO CA Limited") ("COMODO RSA Domain Validation Secure Server CA") ("GB") New connection peerCertificate QSslCertificate("", "", "1B2C1Y8AsgApgBmY7PhCtg==", (), (), QMap(), QDateTime(Invalid), QDateTime(Invalid))

peerName ""

encrypted data

encrypted

ERROR "The remote host closed the connection"

ERROR: could not receive message (The remote host closed the connection)

js client:

<script type="text/javascript">
    let socket = new WebSocket("wss://192.165.10.70:5870");

    socket.onmessage = function(response) {
        console.log(response.data);
    }
    socket.onopen = function() {
        socket.send("hi");
    }
    socket.onclose = function(e) {
        if(e.wasClean) {
            console.log('Close server connect');
        }
        else {
            console.log('connect fail');
        }
        console.log('error: ' + e.code + ' reason: ' + e.reason);
    }
    socket.onerror = function(err) {
        console.log('error: '+err.message);
    }
</script>

Qt:

void ServerExample::run()
{
    QHostAddress address = QHostAddress::Any;
    quint16 port = 5870;

    SslServer sslServer;
    sslServer.setSslLocalCertificate("C:\\Users\\Adm\\Documents\\Server\\sslserver.pem");
    sslServer.setSslPrivateKey("C:\\Users\\Adm\\Documents\\Server\\sslserver.key");
    sslServer.setSslProtocol(QSsl::TlsV1_2);

    if (sslServer.listen(address, port))
        qDebug().nospace() << "Now listening on " << qPrintable(address.toString()) << ":" << port;
    else
        qDebug().nospace() << "ERROR: could not bind to " << qPrintable(address.toString()) << ":" << port;

    if (sslServer.waitForNewConnection(-1))    // Wait until a new connection is received, -1 means no timeout
    {
        qDebug() << "New connection";
        QSslSocket *sslSocket = dynamic_cast<QSslSocket*>(sslServer.nextPendingConnection());

        qDebug() << "peerCertificate " << sslSocket->peerCertificate();
        qDebug() << "peerName " << sslSocket->peerName();
        QObject::connect(sslSocket, &QSslSocket::encrypted, [](){
           qDebug() << "encrypted";
        });

        if (sslSocket->waitForReadyRead(-1))
        {
            QByteArray message = sslSocket->readAll();
            qDebug() << "Message:" << QString(message);

            sslSocket->disconnectFromHost();
            sslSocket->waitForDisconnected();
            qDebug() << "Disconnected";
        }

        else
        {
            qDebug().nospace() << "ERROR: could not receive message (" << qPrintable(sslSocket->errorString()) << ")";
        }
    }

    else
    {
        qDebug().nospace() << "ERROR: could not establish encrypted connection (" << qPrintable(sslServer.errorString()) << ")";
    }

    this->deleteLater();
    QThread::currentThread()->quit();
    qApp->exit();
}
void SslServer::incomingConnection(qintptr socketDescriptor)
{
    QSslSocket *sslSocket = new QSslSocket(this);
    sslSocket->setSocketDescriptor(socketDescriptor);
    qDebug() << m_sslLocalCertificate.issuerInfo(QSslCertificate::Organization);
    qDebug() << m_sslLocalCertificate.issuerInfo(QSslCertificate::CommonName);
    qDebug() << m_sslLocalCertificate.issuerInfo(QSslCertificate::CountryName);

    sslSocket->setLocalCertificate(m_sslLocalCertificate);

    sslSocket->setPrivateKey(m_sslPrivateKey);
    sslSocket->setProtocol(m_sslProtocol);
    sslSocket->setPeerVerifyMode(QSslSocket::VerifyNone);

    sslSocket->startServerEncryption();

    QObject::connect(sslSocket, &QSslSocket::encrypted, [=](){
        qDebug() << "encrypted data";

    });
    QObject::connect(sslSocket, static_cast<void (QSslSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error), [sslSocket] (QAbstractSocket::SocketError) {
           qDebug()<< "ERROR " << sslSocket->errorString();

       });
    QObject::connect(sslSocket, &QSslSocket::peerVerifyError, [sslSocket](QSslError err){
        qDebug()<< "ERROR " << err.errorString();
    });
    QObject::connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrorst(const QList<QSslError> &)));
    connect(sslSocket, &QSslSocket::hostFound, [](){
        qDebug() << "host";
    });
    this->addPendingConnection(sslSocket);
}

I read similar articles, not one does not have a solution, how to correctly use the comodo certificate?

0

There are 0 answers