首页 文章

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

提问于
浏览
1

我有需要使用SSL / TLS协议保护的WCF Web服务 . 另一方面,我有C客户端使用gSOAP library消耗WCF Web服务 . 已经只有服务器需要证书 . 现在我的任务是强制客户获得证书 . 我之前对客户端的实现是这样的:

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 documents做的 . 只有拥有证书所需的服务器才能正常工作 . 我使用WireShark查看了通信,并且连接已完全加密 .

现在为了强制客户端使用证书,我将使用Nine simple steps to enable X.509 certificates on WCF文章 . 但是本文使用的是C#WCF客户端 . 我必须在我的gSOAP C客户端中实现客户端配置 . 我可以在调用 soap_ssl_client_context 和第三个参数时在上面的代码中添加客户端证书 .

我这里有2个问题:

1-我不知道当服务器使用WCF并且客户端使用gSOAP时,调用Web服务可以使客户端和服务器都具有证书并保证通信安全 .

2-在CodeProject文章中,似乎Web服务调用正在使用 http ,我很惊讶通信中没有加密 .

最后,如果有人有更好的解决方案,或推荐其他工具将是受欢迎的 .

1 回答

  • 0

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

    要对服务器和客户端进行身份验证,gsoap manual建议如下:

    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 to CER(或其他方式) .

相关问题