gSOAP - How to use SSL and self-signed certificate

Bemipefe picture Bemipefe · Oct 7, 2013 · Viewed 7.5k times · Source

I need to connect my cross-platform program to a SOAP web service. I have compiled the gSOAP tools wsdl2h and soapcpp2 and with these tools I have generated the source code files from from the .wsdl file. I have putted in the stdsoap2.h the define "#define WITH_OPENSSL" and in this way SSL are used. The problem is that when i call the service the call return ERROR 30 that means SSL ERROR but i don't know what is really the problem. I know the server send a self-signed certificate because this is a testing environment. Indeed an error message related this is printed. The output is:

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

The function i use to call the service is this:

void gSOAPTesting::runTest() { int result = 0; size_t requestSize; size_t responseSize;

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

}

Any help is appreciated.

Answer

Bemipefe picture Bemipefe · Oct 7, 2013

The problem is related the certificate that is not trusted because is self-signed. If I comment these lines in 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;
}

...the certificate is accepted even if the it is issued by an unknown authority.