我有一个基于证书的相互(双向)SSL WCF RESTful 服务,它托管在 Windows 应用程序中。服务器使用绑定自签名证书的端口。该证书存在于“我的”商店的“LocalMachine”中。在同一个“我的”商店中也是客户端证书。客户端和服务器证书的名称都与机器名称相同。客户端和服务器配置如下:
客户:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ClientBehavior">
<webHttp />
<clientCredentials>
<clientCertificate storeLocation="LocalMachine" x509FindType="FindByThumbprint" storeName="My" findValue="F50C62754783EC741F6E84E25888D17CBC145691" />
<serviceCertificate>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding_Conf">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="https://mymachine:8088/Service" behaviorConfiguration="ClientBehavior"
binding="webHttpBinding" bindingConfiguration="WebHttpBinding_Conf"
contract="RESTfulLib.IService" name="WebHttpBinding_NAme" />
</client>
服务器:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceCredentials>
<serviceCertificate storeLocation="LocalMachine" x509FindType="FindByThumbprint" findValue="7975794831242F2D39ED3B1BC8323EAF5DA2CA11" storeName="My"/>
</serviceCredentials>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding_Conf">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="RESTfulLib.Service" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="https://mymachine:8088/Service"/>
</baseAddresses>
</host>
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_Conf" contract="RESTfulLib.IService">
</endpoint>
</service>
</services>
但是,我在 SSL 握手期间收到此错误:
The HTTP request was forbidden with client authentication scheme 'Anonymous'.
启用详细的 WCF 日志表明我们在握手期间遇到了这个错误:
System.Net Error: 0 : [11504] Decrypt returned SEC_I_RENEGOTIATE.
我已经尝试过设置,但这也无济于事:
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
证书也被复制到受信任的根 CA 存储中,并且有一个 ServicePointManager.ServerCertificateValidationCallback 在所有情况下都返回 true(!)
任何答案将不胜感激。谢谢!