我正在尝试使用相互 SSL 身份验证在同一台机器上设置 WCF 服务和客户端。
我有:
为服务器和客户端创建证书并将它们放在 LocalMachine 证书存储中。服务器和客户端私钥在“个人”存储中,而公钥在“受信任的人”存储中。
我已经配置了一个 WCF 服务和客户端,每个服务和客户端都从商店中指定了自己的证书引用,并且还设置了要验证的其他方证书引用
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="LocalMachine" />
注意:服务器证书颁发给Machine name,客户端调用的服务url为'https:\tokenservice\tokenservice.svc
使用此配置,我希望客户端安全地连接到服务,任一端解析来自“受信任的人”存储的证书,但我收到以下错误,表明证书验证失败:
[AuthenticationException:根据验证程序,远程证书无效。]
所以这并没有像我预期的那样工作。任何人都可以指出任何错误吗?还是我的期望不正确?
WCF 配置如下:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="CertificateForClient">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CertificateBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"
trustedStoreLocation="LocalMachine" />
</clientCertificate>
<serviceCertificate findValue="CN='ServerCertificate which is machine name'"
storeLocation="LocalMachine" storeName="My"
x509FindType="FindBySubjectDistinguishedName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="TokenService.TokenService" behaviorConfiguration="CertificateBehaviour">
<endpoint contract="TokenService.ITokenService"
binding="wsHttpBinding" />
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding" address="mex">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="https://tokenservice" />
</baseAddresses>
</host>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
客户端配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ClientBehaviour">
<clientCredentials>
<clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName" findValue="CN=TokenClient"/>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="LocalMachine"></authentication>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="ClientBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://tokenservice/TokenService.svc"
behaviorConfiguration="ClientBehaviour"
binding="wsHttpBinding" bindingConfiguration="ClientBinding"
contract="TokenService.ITokenService" name="ToolClient">
<identity>
<dns value="MachineName" />
</identity>
</endpoint>
</client>