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 Certificate has no content" error
Qt 6.11 is out! See what's new in the release blog

"SSL Certificate has no content" error

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 685 Views 2 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.
  • S Offline
    S Offline
    Sini
    wrote on last edited by
    #1

    Hello everyone, I am trying to connect to a server url to get token from the server by posting the request with the parameters ,ssl certificates etc.But when I try to run the program I get "The certificate has no content"error .But the certificate has all the data inside it. I am attaching the code here. I don't understand how to resolve the error. Any help would be appreciated.

    QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);

    QByteArray postData;
    QSslConfiguration config;
    QString pemfile("path/to/cl_signed.pem");
    QFile file(pemfile);
    if(!file.exists()) {
        qWarning("Filename doent exists");
    }
    if(!file.open(QIODevice::ReadOnly)) {
        qWarning("Cannot open filename %s.", qPrintable(pemfile));
    }  
    QByteArray data_cert =file.readAll() ;
    QSslCertificate sslcert(data_cert, QSsl::Pem);
    config.setLocalCertificate(sslcert);
    if(sslcert.isNull()) {
        qWarning("The certificate has no content.");
    }
    QByteArray keyData;
    const QSslKey sslPrivateKey (keyData, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "privatekey");
    config.setPrivateKey(sslPrivateKey);
    QUrl url("http:...................../oauth2/v1/token?");
    QNetworkRequest request(url);
    postData.append("param1");
    postData.append("param2");
    postData.append("param3");
    postData.append(param4");
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    networkManager->post(request,postData);
    QNetworkAccessManager mgr;
    QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
    QNetworkReply *reply = mgr.get(request);
    if (reply->error() == QNetworkReply::NoError) 
     {
        QString strReply = (QString)reply->readAll();
        qDebug() << "Response:" << strReply;
        QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
        QJsonObject jsonObj = jsonResponse.object();
        qDebug() << "result:" << jsonObj["result"].toInt();
        delete reply;
     }
    else
     {
        qDebug() << "Failure" 
        delete reply;
     }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you try to print some data from sslcert ?
      Also, check the value of isNull.

      By the way, which version of Qt are you using ?
      On which platform ?

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

      S 1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3
        QString pemfile("path/to/cl_signed.pem");
        

        will open a file at a path relative to the current working directory of the process. The current working directory is not necessarily the same as the source path, build path, where the executable is, or even static within a run. You may be opening an empty/corrupt PEM file other than the one you think you are opening.

        Is data_cert.size() greater than 0?
        Is there more than one cl_signed.pem in the system?

        S 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Did you try to print some data from sslcert ?
          Also, check the value of isNull.

          By the way, which version of Qt are you using ?
          On which platform ?

          S Offline
          S Offline
          Sini
          wrote on last edited by
          #4

          @SGaist .. Yes, I tried printing the certificate and its showing the data also.
          I am using Qt 5.15.0 and in Windows .

          1 Reply Last reply
          0
          • piervalliP Offline
            piervalliP Offline
            piervalli
            wrote on last edited by
            #5

            @Sini, Have you copied the dll for openssl?

            S 1 Reply Last reply
            0
            • piervalliP piervalli

              @Sini, Have you copied the dll for openssl?

              S Offline
              S Offline
              Sini
              wrote on last edited by
              #6

              @piervalli Yes I copied the necessay dll files and pasted it in the bin folder, also i mentioned the path to all those dll in the .pro file.

              1 Reply Last reply
              0
              • C ChrisW67
                QString pemfile("path/to/cl_signed.pem");
                

                will open a file at a path relative to the current working directory of the process. The current working directory is not necessarily the same as the source path, build path, where the executable is, or even static within a run. You may be opening an empty/corrupt PEM file other than the one you think you are opening.

                Is data_cert.size() greater than 0?
                Is there more than one cl_signed.pem in the system?

                S Offline
                S Offline
                Sini
                wrote on last edited by
                #7

                @ChrisW67 The certificate is not empty. I tried printing some data from the certificate and yes,it printed that. There are two different pem files, since I have 2 client certificates and one private key .

                1 Reply Last reply
                0

                • Login

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