[英]WCF with transport security via certificates
我想使用客户端证书来保护WCF服务,即仅应允许来自特定根CA的客户端证书来调用我的服务。
为了进行测试,我先创建了一个没有CA的客户端证书。 我在服务器的证书存储区(在当前用户->受信任的人下)注册了客户端证书。
在VS2013中,我已经在WCF服务项目上启用了SSL,以便拥有HTTPS端点。 我对服务的以下Web.config文件进行了如下修改:
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</clientCertificate>
...
</serviceCredentials>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
此外,我还对客户端应用程序的App.config文件进行了如下修改:
<clientCredentials>
<clientCertificate findValue="Client" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="TrustedPeople" />
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</serviceCertificate>
</clientCredentials>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
但是,这不起作用,我收到以下异常消息:
向https://localhost:44300/Service1.svc
发出HTTP请求时发生错误。 这可能是由于在HTTPS情况下未使用HTTP.SYS正确配置服务器证书。 这也可能是由客户端和服务器之间的安全绑定不匹配引起的。
如果我切换到消息安全性(而不是传输安全性)并切换到HTTP协议,那么一切似乎都可以正常工作。 所以我想我错过了一些启用HTTPS的步骤吗?! 如何使运输安全工作?
您的证书配置不正确。请按照以下步骤操作
复制证书的指纹并在提升模式下从命令提示符运行以下命令
netsh http add sslcert [Ipaddress:port] certhash=[thumbprint of certifcate]
appid={unique id for application.you can use GUID for this]
[Ipaddress:port] Ipaddress and port
[thumbprint of certifcate]: thumbprint of certificate without spaces
appid :unique id you can use guid
如何从命令提示符生成GUID
打开Visual Studio命令提示符并在命令下方运行
c:> uuidgen
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.