QtSoap网络传输错误(99):创建SSL上下文时出错()Linux Mint

时间:2014-12-17 16:16:31

标签: c++ ssl https webserver

我遇到与ssl协议的Web服务连接有问题。我试图使用开放式库WebService与特定的QtSoap建立联系。从现在开始,我一直在搜索我在主题中提到的任何错误解决方案,但找不到linux-mint系统的任何错误解决方案。我见过的只有一个,人们在此确认的是12。我有这个包含密钥的webService的证书。

我的代码:

#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");
}

如果您已经在submitRequest中注意到,添加了specsfied SslProtocol和certificatePath,我在库中做了一些更改。这是一个巫术:

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());
}

与此修改的库相关的另一件事。我添加了一些标题:

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

我猜我的* .pro文件中缺少某些内容,但我不知道它可能是什么。所以我在下面添加了

QT       += core network xml
QT        -= gui

TARGET = SSLConnectionTest
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp \
    qtsoap.cpp

HEADERS += \
    qtsoap.h

另一件可能出错的事情是遗漏了一些我不知道的其他图书馆。我希望有人找到解决这个问题的方法吗?

抱歉我的英语很差。

0 个答案:

没有答案