title: Qt QSslSocket comodo positive ssl
body: <p>I have a real bought comodo positive ssl certificate installed on apache and checked the correct installation through the site <a href="https://www.sslshopper.com/ssl-checker.html" rel="nofollow noreferrer">https://www.sslshopper.com/ssl-checker.html</a>
  in the kit with the certificate is 5 files</p>
  
  <pre><code>AddTrust_External_CA_Root.crt
  COMODO_RSA_Certification_Authority.crt
  sslserver.crt
  sslserver.key
  sslserver.ca-bundle
  </code></pre>
  
  <p>When I try to connect to my server via the chrome in the console, the following error occurs:</p>
  
  <blockquote>
    <p>WebSocket connection to 'wss://192.165.10.70:5870/' failed: Error in
    connection establishment: net::ERR_CERT_COMMON_NAME_INVALID</p>
  </blockquote>
  
  <p>And on the server side:</p>
  
  <blockquote>
    <p>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))</p>
    
    <p>peerName  ""</p>
    
    <p>encrypted data</p>
    
    <p>encrypted</p>
    
    <p>ERROR  "The remote host closed the connection"</p>
    
    <p>ERROR: could not receive message (The remote host closed the
    connection)</p>
  </blockquote>
  
  <p>js client:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      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);
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Qt:</p>
  
  <pre><code>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() &lt;&lt; "Now listening on " &lt;&lt; qPrintable(address.toString()) &lt;&lt; ":" &lt;&lt; port;
      else
          qDebug().nospace() &lt;&lt; "ERROR: could not bind to " &lt;&lt; qPrintable(address.toString()) &lt;&lt; ":" &lt;&lt; port;
  
      if (sslServer.waitForNewConnection(-1))    // Wait until a new connection is received, -1 means no timeout
      {
          qDebug() &lt;&lt; "New connection";
          QSslSocket *sslSocket = dynamic_cast&lt;QSslSocket*&gt;(sslServer.nextPendingConnection());
  
          qDebug() &lt;&lt; "peerCertificate " &lt;&lt; sslSocket-&gt;peerCertificate();
          qDebug() &lt;&lt; "peerName " &lt;&lt; sslSocket-&gt;peerName();
          QObject::connect(sslSocket, &amp;QSslSocket::encrypted, [](){
             qDebug() &lt;&lt; "encrypted";
          });
  
          if (sslSocket-&gt;waitForReadyRead(-1))
          {
              QByteArray message = sslSocket-&gt;readAll();
              qDebug() &lt;&lt; "Message:" &lt;&lt; QString(message);
  
              sslSocket-&gt;disconnectFromHost();
              sslSocket-&gt;waitForDisconnected();
              qDebug() &lt;&lt; "Disconnected";
          }
  
          else
          {
              qDebug().nospace() &lt;&lt; "ERROR: could not receive message (" &lt;&lt; qPrintable(sslSocket-&gt;errorString()) &lt;&lt; ")";
          }
      }
  
      else
      {
          qDebug().nospace() &lt;&lt; "ERROR: could not establish encrypted connection (" &lt;&lt; qPrintable(sslServer.errorString()) &lt;&lt; ")";
      }
  
      this-&gt;deleteLater();
      QThread::currentThread()-&gt;quit();
      qApp-&gt;exit();
  }
  void SslServer::incomingConnection(qintptr socketDescriptor)
  {
      QSslSocket *sslSocket = new QSslSocket(this);
      sslSocket-&gt;setSocketDescriptor(socketDescriptor);
      qDebug() &lt;&lt; m_sslLocalCertificate.issuerInfo(QSslCertificate::Organization);
      qDebug() &lt;&lt; m_sslLocalCertificate.issuerInfo(QSslCertificate::CommonName);
      qDebug() &lt;&lt; m_sslLocalCertificate.issuerInfo(QSslCertificate::CountryName);
  
      sslSocket-&gt;setLocalCertificate(m_sslLocalCertificate);
  
      sslSocket-&gt;setPrivateKey(m_sslPrivateKey);
      sslSocket-&gt;setProtocol(m_sslProtocol);
      sslSocket-&gt;setPeerVerifyMode(QSslSocket::VerifyNone);
  
      sslSocket-&gt;startServerEncryption();
  
      QObject::connect(sslSocket, &amp;QSslSocket::encrypted, [=](){
          qDebug() &lt;&lt; "encrypted data";
  
      });
      QObject::connect(sslSocket, static_cast&lt;void (QSslSocket::*)(QAbstractSocket::SocketError)&gt;(&amp;QAbstractSocket::error), [sslSocket] (QAbstractSocket::SocketError) {
             qDebug()&lt;&lt; "ERROR " &lt;&lt; sslSocket-&gt;errorString();
  
         });
      QObject::connect(sslSocket, &amp;QSslSocket::peerVerifyError, [sslSocket](QSslError err){
          qDebug()&lt;&lt; "ERROR " &lt;&lt; err.errorString();
      });
      QObject::connect(sslSocket, SIGNAL(sslErrors(const QList&lt;QSslError&gt; &amp;)), this, SLOT(sslErrorst(const QList&lt;QSslError&gt; &amp;)));
      connect(sslSocket, &amp;QSslSocket::hostFound, [](){
          qDebug() &lt;&lt; "host";
      });
      this-&gt;addPendingConnection(sslSocket);
  }
  </code></pre>
  
  <p>I read similar articles, not one does not have a solution, how to correctly use the comodo certificate?</p>