Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Secure connection to the websocket server



  • I have a problem with connection through protocol scheme wss, my certificate comodo positivessl
    Standard js query:

    let socket = new WebSocket("wss://server:port");
    

    error: failed: Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID

    I also tried:

    QList<QSslCertificate> ca = sslConfiguration.caCertificates();
     ca.append(QSslCertificate(byte,QSsl::Pem));
     sslConfiguration.setCaCertificates(ca);
    

    error: in connection establishment: net::ERR_CONNECTION_CLOSED

    when i am trying to connect ,on the server there are no errors and signals about connection
    and

    qDebug() << sslConfiguration.peerCertificate();
    

    here's what happens

    QSslCertificate("", "", "922M4Y88sgT3gBhY721Cfc==", (), (), QMap(), QDateTime(Invalid), QDateTime(Invalid))
    
    QSslConfiguration sslConfiguration;
     QFile certFile(QStringLiteral(":/ct/local.crt"));
     QFile keyFile(QStringLiteral(":/ct/local.key"));
     certFile.open(QIODevice::ReadOnly);
     keyFile.open(QIODevice::ReadOnly);
     QSslCertificate certificate(&certFile, QSsl::Pem);
     QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
     sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
     sslConfiguration.setLocalCertificate(certificate);
     sslConfiguration.setPrivateKey(sslKey);
     sslConfiguration.setProtocol(QSsl::TlsV1SslV3);
     wtServer->setSslConfiguration(sslConfiguration);
    
    objConnect.append(QObject::connect(wtServer, &QWebSocketServer::newConnection, this, &Server::newUser));
    objConnect.append(QObject::connect(wtServer, &QWebSocketServer::sslErrors, this, &Server::onSslError));
    objConnect.append(QObject::connect(wtServer, &QWebSocketServer::closed, this, &Server::close));
    

    What is the possible cause?


Log in to reply