使用WCF和gSOAP向服务器和客户端添加证书

Add certificate to both server and client using WCF and gSOAP

本文关键字:客户端 添加 服务器 证书 WCF gSOAP 使用      更新时间:2023-10-16

我有WCF web服务,需要使用SSL/TLS协议进行安全保护。另一方面,我有使用gSOAP库使用WCF web服务的C++客户端。已经只有服务器需要证书。现在我的任务是强制客户端拥有证书。我之前为客户端实现的是这样的:

    soap_ssl_init();
    int soapResult = soap_ssl_client_context(soapPtr, SOAP_SSL_NO_AUTHENTICATION, "client.pem", NULL,
        NULL, "cacert.pem", NULL);
    if (soapResult)
    {
        soap_print_fault(soapPtr, stderr);
        throw new ClientLogException("Can not use ssl for comminucations!");
    }
    else
    {
    }
    struct soap mySoap = *soapPtr;
    WSHttpBinding_USCOREILogServicesProxy proxy(mySoap);
    input.request = &request;
    int callCode = proxy.CallWebService(WEB_SERVICE_ADDRESS, NULL, &input, response);
    if (callCode != 0)
    {
        cout << "Web service call code: " + callCode << endl;
        throw new ClientLogException("Error in calling web service with call code: " + callCode);
    } 

这是我从gSOAP文档中完成的。它只适用于需要证书的服务器。我使用WireShark查看了通信,连接完全加密。

现在,为了强制客户端使用证书,我将使用九个简单步骤在WCF文章中启用X.509证书。但是本文使用了一个C#WCF客户端。我必须在我的gSOAP C++客户端中实现客户端配置。当调用soap_ssl_client_context和第三个参数时,我可以在上面的代码中添加客户端证书。

我有两个问题:

1-我不知道当服务器使用WCF而客户端使用gSOAP时,是否可能调用客户端和服务器都有证书和通信安全的web服务。

2-在CodeProject的文章中,web服务调用似乎使用http,我想知道通信中没有加密。

最后如果有人有更好的解决方案,或者推荐其他工具都会受到欢迎。

HTTPS在gsoap中开箱即用,如果您使用-DWITH_OPENSSL进行编译并针对OpenSSL库进行链接。开箱即用的默认设置将使用https://加密消息,但这不会强制进行身份验证,因为您需要首先使用soap_ssl_client_context()注册服务器证书。

为了验证服务器和客户端,gsoap手册建议如下:

int soapResult = soap_ssl_client_context(soapPtr,
    SOAP_SSL_DEFAULT,  // requires server to authenticate
    "client.pem",      // client cert (+public key) to authenticate to server
    "password",        // you need this when client.pem is encrypted
    NULL,              // capath to certs, when used
    "cacert.pem",      // should contain the server cert
    NULL);

此外,对于windows,您可能需要将PEM转换为CER(或其他方式)。