C++ gSOAP-如何使用SSL和自签名证书
我需要将我的跨平台程序连接到SOAP web服务。我编译了gSOAP工具wsdl2h和soapcpp2,并使用这些工具从.wsdl文件生成了源代码文件。我在stdsoap2.h中加入了define“#define WITH_OPENSSL”,并以这种方式使用SSL。问题是,当我调用服务时,调用返回错误30,这意味着SSL错误,但我不知道真正的问题是什么。我知道服务器发送自签名证书,因为这是一个测试环境。实际上,会打印与此相关的错误消息。输出为:C++ gSOAP-如何使用SSL和自签名证书,c++,soap,openssl,ssl-certificate,gsoap,C++,Soap,Openssl,Ssl Certificate,Gsoap,我需要将我的跨平台程序连接到SOAP web服务。我编译了gSOAP工具wsdl2h和soapcpp2,并使用这些工具从.wsdl文件生成了源代码文件。我在stdsoap2.h中加入了define“#define WITH_OPENSSL”,并以这种方式使用SSL。问题是,当我调用服务时,调用返回错误30,这意味着SSL错误,但我不知道真正的问题是什么。我知道服务器发送自签名证书,因为这是一个测试环境。实际上,会打印与此相关的错误消息。输出为: Creating SOAP objects ...
Creating SOAP objects ...
Calling SOAP httpAccessService:
SSL verify error or warning with certificate at depth 0: self signed certificate
certificate issuer /C=IT/ST=Milan/L=Milan/O=Company/OU=Company/CN=company.it
certificate subject /C=IT/ST=Milan/L=Milan/O=Company/OU=Company/CN=company.it
SOAP ERROR 30
我用来调用服务的函数是:
void gSOAPTesting::runTest()
{
int结果=0;
尺寸要求尺寸;
大小和响应
char endpoint[1024];
char buffer[8192];
string SoapAction;
struct soap *soap_container;
ApplicationConfigurationServiceSoapBindingProxy Proxy1;
_ns1__httpAccessService *httpAccessService;
_ns1__httpAccessServiceResponse *httpAccessServiceResponse;
printf("Creating SOAP objects ...\n");
soap_container = soap_new();
//soap_container->mode
httpAccessService = (_ns1__httpAccessService *) soap_instantiate(soap_container , SOAP_TYPE___ns1__httpAccessService , "" , "" , &requestSize);
httpAccessServiceResponse = (_ns1__httpAccessServiceResponse *) soap_instantiate(soap_container , SOAP_TYPE___ns1__httpAccessService , "" , "" , &responseSize);
soap_ssl_init(); /* init OpenSSL (just once) */
if(soap_ssl_client_context(soap_container ,
SOAP_SSL_DEFAULT ,
NULL,
NULL,
NULL,
NULL,
NULL
) != SOAP_OK)
{
printf("SOAP SSL Initialization Failure\n");
soap_print_fault(soap_container , stderr);
return ;
}
printf("Calling SOAP httpAccessService:\n");
SoapAction.clear();
SoapAction.append(SOAP_NAMESPACE_OF_ns1);
SoapAction.append("/");
SoapAction.append("httpAccessService");
result = Proxy1.httpAccessService("https://XXX.XXX.XXX.XXX:XXXX" , NULL , httpAccessService , httpAccessServiceResponse);
if(result == SOAP_OK)
{
printf("SOAP OK\n");
}
else
{
printf("SOAP ERROR %d\n" , result);
if(soap_check_state(soap_container) ) printf("Error: request soap struct not initialized\n");
if(httpAccessService->soap == NULL)
{
printf("Error: NULL request SOAP struct\n");
return;
}
if(httpAccessService->soap->endpoint == NULL) printf("Error: Empty request endpoint\n");
soap_stream_fault(soap_container , std::cout);
}
}
非常感谢您的帮助。问题与证书有关,该证书由于自签名而不受信任。如果我在stdsoap2.cpp中注释这些行
if (!ok)
{ soap_set_sender_error(soap, "SSL/TLS error", "SSL/TLS certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR);
soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
…即使证书是由未知机构颁发的,也会接受该证书。如果(soap\u ssl\u client\u上下文(&soap),
SOAP\u SSL\u无\u身份验证,
空,空,,
空,/*```````````````````
*/
空,空)!=SOAP\u确定)
{
如果您可以忽略主机,您可以执行上述操作,而不是在生成的文件中进行通信