gsoap 通过SSL双向认证调用service

通过<<SSL安全网络架设>>>一文,最终得到以下文件

ca.crt

ca.key

server.crt

server.key

client.crt

client.key

生成IIS需要的文件

[root]# openssl pkcs12 -export -in server.crt -inkey server.key -out server.pfx

将server.pfx ca.crt 传到IIS机器上,在证书管理中,除个人一项导入client.pfx外,其余都导入ca.crt

IIS 勾选使用SSL,客户端证书选择必须。

生成gsoap客户端需要的文件

1.[root]# cat client.crt client.key > client.pem

调用service接口

代码如下

soap_ssl_client_context($soap,

SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION
| SOAP_SSL_SKIP_HOST_CHECK
| SOAP_SSL_ALLOW_EXPIRED_CERTIFICATE,
"client.pem",
"123456789",
"ca.crt",
NULL,
NULL);

int res = soap.method(request, response);

注意:

第二个参数使用SOAP_SSL_DEFAULT的话会报错,提示SSL/TLS certificate host name mismatch in tcp_connect()

出现了一次405错误,后来发现是自己的endpoint只改成了https://xxx.xxx.xxx:443 应该是 https://xxx.xxx.xxx:443/service.asmx才对,一时大意,还花了不少时间解决

你可能感兴趣的:(SOAP,IIS)