我完全不了解证书。我在网上搜索了很多解决方案和教程,但都没有找到真正能帮助我的内容。
我想要的是,在我的WCF客户端-服务器应用程序中同时进行服务器和客户端证书验证。该应用程序托管在IIS上。
我希望在我的开发计算机上(服务器为localhost)以及在测试环境中(我是客户端,服务器是Windows服务器)实现此目标。
我现在的配置如下:
客户端:
<behaviors>
<endpointBehaviors>
<behavior name="myBehaviorConfig">
<clientCredentials>
<clientCertificate findValue="CN=MyTestClientCertificate"
storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="MyBindingConfig">
<security mode="TransportWithMessageCredential">
<transport realm=""/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/Service.Calculator.svc"
binding="wsHttpBinding"
bindingConfiguration="MyBindingConfig"
behaviorConfiguration="MyBehaviorConfig"
contract="Service.ICalculator"
name="ICalculatorServiceEndpoint">
<identity>
<servicePrincipalName value="host"/>
</identity>
</endpoint>
</client>
服务器:
<behaviors>
<serviceBehaviors>
<behavior name="myBehavior">
<serviceCredentials>
<serviceCertificate findValue="CN=MyTestRootCA"
storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName"/>
<userNameAuthentication userNamePasswordValidationMode="Windows"/>
<clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust"/>
</clientCertificate>
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<unity operationContextEnabled="true"
instanceContextEnabled="true"
contextChannelEnabled="true"
serviceHostBaseEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="MyBinding">
<security mode="TransportWithMessageCredential">
<transport realm=""/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service.Calculator"
behaviorConfiguration="myBehavior">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="MyBinding"
contract="Service.ICalculator" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange"
name="CalculatorServiceMex" />
</service>
</services>
"CN=MyTestRootCA" 是 "创建" 证书时的 "授权机构",我将其放置在本地计算机的可信根证书以及个人目录下,并且它是客户端证书 "CN=MyTestClientCertificate" 的颁发者。
几件事情:
我知道客户端证书应该在 "MMC" 中的 CurrentUser 目录下,但当它在那里时,我会收到一个异常,应用程序无法找到该证书。我尝试使用 "FindBySubjectDistinguishedName" 和 "FindByThumbprint" 定位它,两种方法都出现了相同的异常 "无法按照给定的条件找到证书...",所以我把它放到了 LocalMachine 中,这样就好了。有人有想法为什么它不起作用吗?
我遇到了很多问题和异常 =\ 当前这个异常是:"X.509 证书中未提供私钥"。有人熟悉这个异常并知道如何解决吗?
非常感谢您的回答,我已经困扰数天了。