Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SSL Handshake failed with rest API
Forum Updated to NodeBB v4.3 + New Features

SSL Handshake failed with rest API

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 935 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mourad_bilog
    wrote on last edited by
    #1

    Hello everyone,
    Since last Thursday, I'm encontering an SSL Handskae failed when I'm consuming my API.
    I'm not using any SSL certificate with then NetworkAccessManager object. Below my source code

    QEventLoop eventLoop;
      QNetworkAccessManager networkManager;
    	if (!m_networkProxy.hostName().isEmpty())
    		networkManager.setProxy(m_networkProxy);
    
    	qDebug() << QString("%1/getUserToken?username=%2").arg(m_sServerURL, m_strSerialLic); //TheriaqueSuivi/
    
    	QObject::connect(&networkManager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
        QNetworkRequest networkRequest( QUrl( QString("%1/getUserToken?username=%2").arg(m_sServerURL, m_strSerialLic) ) );
    	
        QNetworkReply *networkReply = networkManager.get(networkRequest);
        eventLoop.exec();
     
    	QString strResponse = (QString)networkReply->readAll();
    
        QJsonDocument jsonResponse = QJsonDocument::fromJson(strResponse.toUtf8());
        QJsonValue valErrorCode = jsonResponse.object().value(ERROR_CODE);
        QJsonValue valResult = jsonResponse.object().value(RES_MSG);
    
        if ((networkReply->error() != QNetworkReply::NoError) || (valErrorCode.toInt() != 1000))
            qDebug() << networkReply->errorString() << valResult.toString() << networkReply->error();
            
            emit networkError( networkReply->error() );
    
    		delete networkReply;
        }
    

    I've seen this issue but despite adding the below source, the error is still here.

    	QString pemCert = QApplication::applicationDirPath() + "/"+"isrgrootx1.pem";
    
    #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
    	QSslConfiguration::defaultConfiguration().addCaCertificates(pemCert);
    #else
        QSslSocket::addDefaultCaCertificates(pemCert);
    #endif
    
    	QSslConfiguration SslConfiguration(QSslConfiguration::defaultConfiguration());
    
    	QList<QSslCertificate> caList = SslConfiguration.caCertificates();
    
    	caList.append(QSslCertificate::fromPath(pemCert.toLocal8Bit())); //Root CA
    
    	SslConfiguration.setCaCertificates(caList);
    
    	SslConfiguration.setLocalCertificate(QSslCertificate(pemCert.toLocal8Bit()));
    
    	SslConfiguration.setProtocol(QSsl::SslV3);
    
    	SslConfiguration.setPeerVerifyMode(QSslSocket::VerifyPeer);
    
    	networkRequest.setSslConfiguration(SslConfiguration); 
    

    Can anyone tell me what I'm wrong and what to do to fix the problem because it impacts my clients.
    Regards

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Any chances that your API uses a Let's Encrypt certificate ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mourad_bilog
        wrote on last edited by
        #3

        Hello
        As you can see, I'm not using any certificate to consume the API. In server side, we use a LetsEncryt certficate to use HTTPS protocol. The certificate is up to date after the LetsEncrypt update on 30/09/21.

        Adding a certificate on the client side doesn't resolve the problem. For test, we have tried to consume the API from a Java client and it works fine. So, the problem is from the application.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I am wondering whether you are having the same issue discussed here.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mourad_bilog
            wrote on last edited by
            #5

            Hello,

            Thanks for the link. It helped me.
            But, in my case, I've used the solution given here and the problem was fixed.

            Regards.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved