"SSL Certificate has no content" error
-
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; } -
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? -
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 ? -
@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.
-
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?