我想在与WCF服务通信时使用基于证书的加密和验证。所以我创建了测试证书,“TempCA”作为我的根CA,“SignedByCA”作为由该CA签署的客户端证书。
当我将客户端证书放入“本地计算机\受信任的人”并使用certificateValidationMode="PeerTrust"
时,该服务会识别客户端,一切都按预期工作。但是通过信任链验证(certificateValidationMode="ChainTrust"
),我遇到了错误“调用者未被服务验证”。
相关的服务器端配置:
<behaviors>
<serviceBehaviors>
<behavior name="customServiceBehavior">
[...]
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="ChainTrust" trustedStoreLocation="LocalMachine" mapClientCertificateToWindowsAccount="false" />
</clientCertificate>
<serviceCertificate findValue="TempCA"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="soapBindingConfiguration">
<security mode="Message">
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
相关客户端配置(其余由“添加服务参考”自动创建):
<endpointBehaviors>
<behavior name="customClientBehavior">
<clientCredentials>
<clientCertificate findValue="SignedByCA" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
</clientCredentials>
</behavior>
</endpointBehaviors>
客户端和服务器证书都与其私钥一起存储在“本地计算机\个人”中(因为我正在一台计算机上进行测试),而“TempCA”(我的根证书)是也在“本地计算机\受信任的根证书颁发机构”中。
我在这里缺少什么?有什么实际的例子吗?
答案 0 :(得分:5)
我终于发现了问题所在。必须禁用撤销检查。我的测试CA显然没有关联的CRL,因此在这种情况下,WCF似乎阻止了每个客户端,因为它无法验证。
<clientCertificate>
<authentication certificateValidationMode="ChainTrust"
revocationMode="NoCheck" ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←
[...] />
</clientCertificate>
答案 1 :(得分:0)
看起来你正在做的事情应该基于this MSDN article使用WCF使用证书。使用受信任的根证书方法时,您可能希望从个人存储中删除证书。
如果这不起作用,则部署根证书可能还需要将组策略应用于您的计算机。查看“如果您不使用Microsoft Enterprise根证书颁发机构并且只想要计算机组”部分this TechNet article.它表示如果未应用组策略,计算机可能不会自动信任根证书。这两篇文章似乎相互矛盾,所以我不确定哪一篇会有效。