【问题标题】:WCF with transport security via certificates通过证书具有传输安全性的 WCF
【发布时间】:2014-01-22 11:12:09
【问题描述】:

我想使用客户端证书来保护我的 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 的步骤?!如何让交通安全发挥作用?

【问题讨论】:

    标签: c# wcf security ssl


    【解决方案1】:

    您的证书配置不正确。请按照以下步骤操作

    复制证书的指纹并在提升模式下从命令提示符运行以下命令

       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

    【讨论】:

    • 感谢您的信息,如果我使用此工具,我会收到简单的错误“参数不正确”。指纹没有空格,我使用了一个新的 GUID(包括破折号)作为 appId。
    • guid 应该用大括号括起来
    • 我有netsh http add sslcert ipport=localhost:44300 certhas=&lt;thethumbprint&gt; appid={22d80ae9-b4f7-4c41-b201-a34e2790b41e}
    • 将 ipport=localhost:44300 替换为 0.0.0.0:44300
    • 好的,我还必须将 certhas 更改为 certhash ;-) 但是,仍然无法正常工作:SSL Certificate add failed, Error: 183 Cannot create a file when that file already exists.
    猜你喜欢
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 2012-08-08
    • 2011-09-23
    • 1970-01-01
    • 2014-02-20
    相关资源
    最近更新 更多