2

I have a problem with connection to a web service with ssl protocol. I was trying to connect with specyfied WebService using open libraries QtSoap. Since now I have been searching any solution of error which I have mentioned in the topic, but not found any for linux-mint system. Only one I have seen, which people confirmed were for Windows here 1 and here 2. I have certificate for this webService which contains a key.

My pice of code:

#include "qtsoap.h"
...
int main(int argc, char **argv)
{
...
    QtSoapMessage message;
    QSsl::SslProtocol protocol = QSsl::SslV2;
    message.addHeaderItem(new QtSoapSimpleType(QtSoapQName("tagName"),"tagValue"));
...
    message.setMethod("method", "WSAddress");
    message.addMethodArgument("attr", "", value);
...
    QtSoapHttpTransport http;
    http.setHost("ipaddress", true, port);
    http.setAction("http://tempuri.org/IDataService/DARTGetReservationData");
    http.submitRequest(message, "path", protocol, "certificatePath");
}

I have made some changes in a library if You have already noticed in submitRequest, adding specyfied SslProtocol and certificatePath. Here is a sorce:

void QtSoapHttpTransport::submitRequest(QNetworkRequest &networkReq, QtSoapMessage &request, const QString &path, QSsl::SslProtocol ssl, QString certificatePath)
{
    networkReq.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml;charset=utf-8"));
    networkReq.setRawHeader("SOAPAction", soapAction.toLatin1());
    url.setPath(path);
    networkReq.setUrl(url);
    QSslConfiguration sslConf = networkReq.sslConfiguration();

    soapResponse.clear();
    if(certificatePath != NULL)
    {
        QFile sslCertificateFile(certificatePath);
        if (sslCertificateFile.open(QIODevice::ReadOnly))
        {
            QSslCertificate certif(&sslCertificateFile);
            if (certif.isNull())
            {
                qDebug() << "Failed to load certificate";
            }
            sslConf.setLocalCertificate(certif);
            sslConf.setPrivateKey(certif.publicKey());
            qDebug() << "certif version=" << certif.version() << ", serial=" << certif.serialNumber()
                << ", issuer=" << certif.issuerInfo(QSslCertificate::Organization)
                << " and subject=" << certif.subjectInfo(QSslCertificate::CommonName);
            QSslKey key(certif.publicKey());
            qDebug() << "key isNull ? " << key.isNull();
            sslConf.setPrivateKey(key);
            sslCertificateFile.close();
        }
        else
            qDebug() << "Cannot open certificate";
    }

    if(ssl != NULL)
        sslConf.setProtocol(ssl);
    networkReq.setSslConfiguration(sslConf);

    networkRep = networkMgr.post(networkReq, request.toXmlString().toUtf8().constData());
}

One more thing related to this modified libraries. I added some headers to:

#include <QSslCertificate>
#include <QSsl>
#include <QSslConfiguration>
#include <QSslKey>
#include <QFile>

I guess that there is missing something in my *.pro file, but I do not know what it could be. So I added it below

QT       += core network xml
QT        -= gui

TARGET = SSLConnectionTest
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp \
    qtsoap.cpp

HEADERS += \
    qtsoap.h

Another thing that could be wrong is there is missing some other libraries which I don't know. I hope someone have found solution of this problem?

Sorry for my poor english.

Community
  • 1
  • 1
  • I was trying this source with `Qt 4.8.6` and `Qt 5.3` Situation is repeating with similar error. In first case I get this metioned in topic in second case got "Network transport error (99): Unable to init SSL Context" – Paweł Ruciński Dec 18 '14 at 07:47
  • Hello, I have made some progress with this issue. As it is said in [1] I installed openssl using install file clues. After that I copied files libcrypto.so and libssl.so into /usr/lib. And problem disappear. Now I am facing problem with security like this: "An error occurred when verifying security for the message.", but it is another issue. [1]: http://codeblog.vurdalakov.net/2009/11/solution-qsslsocket-cannot-call.html – Paweł Ruciński Dec 18 '14 at 12:44

0 Answers0