gpt4 book ai didi

soap - 使用 GSoap 和 SSL 时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:56 29 4
gpt4 key购买 nike

我正在针对具有标准 http 和 https 版本的服务编写 gSoap 客户端应用程序。到目前为止,我编写的所有内容都适用于 http 服务,但当我切换到 https 服务时,突然出现错误。

我对 https 支持代码所做的唯一更改是在启动时添加以下内容:

 soap_ssl_init();   
if(soap_ssl_client_context(&_tradeService, SOAP_SSL_SKIP_HOST_CHECK, NULL, NULL, NULL, NULL, NULL)) {
handleError("Failed to set up SSL connection");
return;
}

如果我打开了 -DDEBUG 标志,我会收到有关证书的错误:“深度 2 证书的 SSL 验证错误或警告:证书链中的自签名证书”这不会导致soap_ssl_client_context 返回一个错误,我认为这没什么大不了的,因为在我进行测试时我并不真正关心对主机进行身份验证。

真正的问题是这个错误:

SOAP 1.2 fault: SOAP-ENV:Sender [no subcode] "Unable to handle request without a valid action parameter. Please supply a valid soap action."

当我尝试向服务发出请求时得到的。如果我查看 gsoap 生成的发送日志,我会在传出 header 中看到 SoapAction 参数集。事实上,如果我比较 http/https 服务的发送日志,唯一的区别是安全服务的 url 以 https 为前缀。

然后我想也许服务器出了问题,所以我使用 curl 发送与 gsoap 记录它发送的完全相同的 XML 数据,具有完全相同的 header 。这工作正常,我看到了我期望的数据的正常响应。这让我相信我可能没有正确设置 SSL?

我遇到的另一个问题不在文档中,是当我使用 -DWITH_OPENSSL -lgsoapssl++ -lssl -lcrypto 标志构建时,我仍然收到有关 gsoap 的 ssl 方法的链接器错误。我必须在我的构建中包含 stdsoap2_ssl_cpp.cpp 才能解决这些问题,我认为这很奇怪。

有人试过这样做可以给我一些指导吗?

最佳答案

看起来我们同时在与类似的问题作斗争。

让我先从这个开始:

The other issue I had that was not in the docs, was that when I built with the -DWITH_OPENSSL -lgsoapssl++ -lssl -lcrypto flags I was still getting linker errors about gsoap's ssl methods. I had to include stdsoap2_ssl_cpp.cpp in my build in order to get these resolved, which I thought was odd.

仅供引用:我使用的是 VirtualBox、Ubuntu 14.04。我使用标志 --enable-debug--with-openssl=/opt/libraries/openssl/build/1.0.1j 从源代码编译了 Gsoap 2.8.21。

如您所见,我还从源代码编译了 openssl 以获得 libssl.alibcrypto.a 文件。此外,我编译了 zlib 以获得 libz.a 存档。所有这些都到位:

  • 我使用以下命令从 WSDL 生成头文件:

    wsdl2h -v -g -o temporary.h https://something.com?wsdl
  • 在生成代理类之前将此行添加到 temporary.h:

    #import "wsse.h"
  • 使用以下命令生成 C++ 代理客户端类:

    soapcpp2 -1 -I/opt/libraries/gsoap/build/2.8.21/share/gsoap/import -C -j temporary.h
  • 使用 QT Creator(Plain Project,遗憾的是没有 cmake),我的 project.pro 文件如下所示:

    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt

    QMAKE_CXXFLAGS += -DWITH_OPENSSL
    QMAKE_CXXFLAGS += -DWITH_DOM
    QMAKE_CXXFLAGS += -DDEBUG

    QMAKE_CFLAGS += -DWITH_OPENSSL
    QMAKE_CFLAGS += -DWITH_DOM
    QMAKE_CFLAGS += -DDEBUG

    SOURCES += main.cpp \
    soapBasicHttpBinding_USCOREIBarcodeWebServiceProxy.cpp \
    soapC.cpp \
    ../../../opt/libraries/gsoap/build/2.8.21/share/gsoap/plugin/wsseapi.cpp \
    ../../../opt/libraries/gsoap/build/2.8.21/share/gsoap/plugin/mecevp.c \
    ../../../opt/libraries/gsoap/build/2.8.21/share/gsoap/plugin/smdevp.c \

    HEADERS += \
    BasicHttpBinding_USCOREIBarcodeWebService.nsmap \
    soapBasicHttpBinding_USCOREIBarcodeWebServiceProxy.h \
    soapStub.h \
    soapH.h

    include(deployment.pri)
    qtcAddDeployment()

    INCLUDEPATH += ../../../opt/libraries/gsoap/build/2.8.21-debug/share/gsoap

    unix:!macx: LIBS += -L$$PWD/../../../opt/libraries/gsoap/build/2.8.21-debug/lib/ -lgsoapssl++
    INCLUDEPATH += $$PWD/../../../opt/libraries/gsoap/build/2.8.21-debug/include
    DEPENDPATH += $$PWD/../../../opt/libraries/gsoap/build/2.8.21-debug/include
    unix:!macx: PRE_TARGETDEPS += $$PWD/../../../opt/libraries/gsoap/build/2.8.21-debug/lib/libgsoapssl++.a

    unix:!macx: LIBS += -L$$PWD/../../../opt/libraries/openssl/build/1.0.1j/lib/ -lssl
    INCLUDEPATH += $$PWD/../../../opt/libraries/openssl/build/1.0.1j/include
    DEPENDPATH += $$PWD/../../../opt/libraries/openssl/build/1.0.1j/include
    unix:!macx: PRE_TARGETDEPS += $$PWD/../../../opt/libraries/openssl/build/1.0.1j/lib/libssl.a

    unix:!macx: LIBS += -L$$PWD/../../../opt/libraries/openssl/build/1.0.1j/lib/ -lcrypto
    INCLUDEPATH += $$PWD/../../../opt/libraries/openssl/build/1.0.1j/include
    DEPENDPATH += $$PWD/../../../opt/libraries/openssl/build/1.0.1j/include
    unix:!macx: PRE_TARGETDEPS += $$PWD/../../../opt/libraries/openssl/build/1.0.1j/lib/libcrypto.a

    unix:!macx: LIBS += -L$$PWD/../../../opt/libraries/zlib/build/1.2.8/lib/ -lz
    INCLUDEPATH += $$PWD/../../../opt/libraries/zlib/build/1.2.8/include
    DEPENDPATH += $$PWD/../../../opt/libraries/zlib/build/1.2.8/include
    unix:!macx: PRE_TARGETDEPS += $$PWD/../../../opt/libraries/zlib/build/1.2.8/lib/libz.a

    LIBS += -ldl

现在回答您的第一部分问题,我认为以下指南应该可以解决您当前面临的问题:

仅供引用:在我包含的 main.cpp 文件中:

#include <iostream>
#include "BasicHttpBinding_USCOREIBarcodeWebService.nsmap"
#include "soapBasicHttpBinding_USCOREIBarcodeWebServiceProxy.h"
#include "soapStub.h"
#include "soapH.h"
#include "plugin/wsseapi.h"

然后在我添加的文件中:

// creating empty soap struct with SOAP_IO_FLUSH
soap *soap = soap_new();
// setting flags: SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION | SOAP_TLSv1
soap->ssl_flags = SOAP_SSL_DEFAULT;
// registering plugin
soap_register_plugin(soap, soap_wsse);
// file with CA certs of peers (downloaded https://www.cs.fsu.edu/~engelen/cacerts.pem.zip)
soap->cafile = "cacerts.pem";
// I placed cacerts.pem file in the same folder where your program executable will be created

所以回到您的案例,我认为在您使用 soap_ssl_client_context 的方法中,其中一个参数还负责设置 cacerts.pem 位置。 p>

如果这仍然不起作用,您始终可以将 ssl_flags 设置为 SOAP_SSL_NO_AUTHENTICATION

不知道这样能不能解决这个问题:

SOAP 1.2 fault: SOAP-ENV:Sender [no subcode] "Unable to handle request without a valid action parameter. Please supply a valid soap action."

然而,从 gsoap 插件附加正确的文件可能会出现这种情况。我正在玩 SOAP 1.1 并禁用为 SOAP 1.2 生成代理客户端类。

无论如何,我期待着您的回复。希望我能在你第一次使用 Gsoap 时帮到你一些忙,避免很多挫败感 :)

关于soap - 使用 GSoap 和 SSL 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1890090/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com