QNetworkAccessManager and HTTPS
-
Hello,
I'm a newbie at SSL and https... I need to send files by Https... I've searched about how to use of QNetworkAccessManager, QNetworkRequest, QHttpMultipart, QnetworkReply and QSslSocket for working together without any success. Can you give me some guide about it?
-
Try to install an SSL library, "OpenSSL":http://www.openssl.org/
-
Are you using the source version of Qt? Mening you compile your Qt yourself?
If so you need to download precompiled OpenSSL libraries or compile them yourself. And reconfigure and recompile Qt.
AFAIK the prebuild Qt releases should already have OpenSSL integrated.Please tell us what exactly didn't work out for you. Also there a many resources on the web how to use ssl in your Qt application.
-
Hello this is part of my code,
@
QFile certFile("./ca.crt");
if(!certFile.open(QIODevice::ReadOnly))
qDebug() <<certFile.fileName() << " not opened";
QByteArray arrayCert = certFile.readAll();
QSslCertificate cert(arrayCert, QSsl::Pem);qDebug() << "null: " << cert.isNull() << " valid: " << cert.isValid() ;
QSslSocket *sslSocket = new QSslSocket(this);
sslSocket->addCaCertificate(cert);
QSslConfiguration config = sslSocket->sslConfiguration();
sslSocket->setSslConfiguration(config);
request.setSslConfiguration(config);
@After that, I added some headers and a file.... then
I send:
@
reply = manager->post(request, multiPart);
@after that I get this errors:
err: "The issuer certificate of a locally looked up certificate could not be found"
err: "The root CA certificate is not trusted for this purpose"
err: "No certificates could be verified"I supouse that my ssl config is bad.
Regads
-
Hi,
are you sure your certificate is encoding using Qt::Pem format? OR is it QSsl::Der?
We had same issues and the reason was that we have extracted the certificate as DER encoded and passed Qt::Pem.
Other than that, make sure you have all SSL dependencies installed and check your code again. Usually it's not need to define a QSslSocket if your are using the QNetworkManager.
We are setting the root CA from geotrust just in case its not available:
@
QSslConfiguration defaultSSLConfig = QSslConfiguration::defaultConfiguration();
QList<QSslCertificate> certificates = defaultSSLConfig.caCertificates();
QFile cert;
cert.setFileName(":/cert/geotrust.cer");
if(cert.open(QIODevice::ReadOnly))
{
QSslCertificate certificate(&cert, QSsl::Der);
certificates.append(certificate);
}
defaultSSLConfig.setCaCertificates(certificates);
QSslConfiguration::setDefaultConfiguration(defaultSSLConfig);
@afterwards you can access your server with QNetworkManager and QWebKit.
Hope that helps
Good Luck!