所以我完全失去了证书。我在网上搜索了解这方面的解决方案和教程,并没有发现任何可以帮助我的东西。 我想要做的是为我的WCF客户端 - 服务器应用程序同时拥有服务器和客户端证书验证。该应用程序托管在IIS上。 我希望它在我的开发计算机(服务器是本地主机)和测试(其中即时客户端和服务器是一个Windows服务器)。客户证书认证WCF
配置我现在是:
客户:
<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”的颁发者。
很少有东西..
我知道这个客户端证书应该在CurretUser目录中的“MMC”,但是当它的存在,我有一个例外,该应用程序无法找到证书。 我试图通过“FindBySubjectDistinguishedName”和“FindByThumbprint”找到它,两次都是同样的异常“不能找到证书与给定的标准...”,所以我把它放在LocalMachine和它的罚款。 任何人有一个想法,为什么它不工作?
我有很多问题和例外与此=目前是: “私钥不在X.509证书” 任何人都知道这个例外,并知道如何解决它?
非常感谢您的回答,我坐在这了几天,现在
我确实在客户端配置中指定了客户端证书的存储位置。你建议的代码应该在服务器配置中?如果是的话,我应该指定什么证书,客户端证书位于客户端的计算机上。 并关于第二个错误,我实际上有一个私钥,我用它来创建客户端证书,但不超过。我需要做些别的事吗?比如把它放在一个特定的位置或者添加到配置中? – user2834816