title: What is the correct way to create succesfull SSL handshake in QT?
body: <p>I have following three files: <strong>key.pem</strong>, <strong>cert.pem</strong>, <strong>ca.pem</strong> and working piece of code which creates SSL connection to my server. It is created using boost libraries.</p>
  
  <p>Working boost code:</p>
  
  <pre><code>ssl::context ctx(io_service, ssl::context::sslv23);
  ctx.set_password_callback(password_callback);
  ctx.load_verify_file("ca.pem");
  ctx.set_verify_mode(ssl::context_base::verify_peer);
  ctx.use_certificate_file("cert.pem", ssl::context::pem);
  ctx.use_private_key_file("key.pem", ssl::context::pem);
  </code></pre>
  
  <p>I have to rewrite this client code using Qt5 and its QSslSocket.</p>
  
  <p>So far I created this code (with many small variations - dwitching files, changing password encofding):</p>
  
  <pre><code>    QSslSocket ssl;
      QList&lt;QSslCertificate&gt; certy = QSslCertificate::fromPath("C:\\ssltest\\cert.pem");
  
      ssl.setCaCertificates(certy);
      ssl.setLocalCertificate(QString("C:\\ssltest\\ca.pem"));
     ssl.setPrivateKey(QString("C:\\ssltest\\key.pem"),QSsl::Rsa,QSsl::Pem,QString("password").toUtf8());
  
  
      ssl.connectToHostEncrypted(QString("192.168.90.41"),6500);
  
      if(ssl.waitForEncrypted()){
          cout &lt;&lt; "SSL handsake succesful!" &lt;&lt; endl;
      } else {
          cout &lt;&lt; "Something went terribly wrong!" &lt;&lt; endl;
      }
  </code></pre>
  
  <p>But my Qt code cannot achieve succesfull SSL handshake (the TCP connection is succesful).
  What am I doing wrong ?</p>
  
  <p>I immediatly get this SSL error: The host name did not match any of the valid hosts for this certificate.
  When i switch ca with cert, It tooks longer for it to fail, but i don't get any error.</p>