【问题标题】:WCF showing 403 Forbidden using SSL and client certificatesWCF 显示 403 禁止使用 SSL 和客户端证书
【发布时间】:2014-12-05 19:26:56
【问题描述】:

我们遇到了 WCF 问题 - 尝试连接时出现以下错误。有很多关于各种配置的建议,在尝试了所有这些之后,我们可以使用一些帮助。

我们使用 HTTPS 来确保传输安全,使用从 GoDaddy 获得的真实 SSL 证书。当我们浏览网站上的网页时,它似乎已安装并正常工作。无需身份验证,我们就可以正确连接到我们的 WCF 服务。

对于身份验证,我们使用的是我们自己创建的客户端证书。这些客户端证书在我们切换到 HTTPS 之前运行良好,当时我们正在使用带有自签名服务器证书的消息安全性(这很痛苦,因为我们必须让客户端安装服务器证书)。

错误 客户端身份验证方案“匿名”禁止 HTTP 请求。 内部异常:远程服务器返回错误:(403) Forbidden

服务器配置文件

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="NewBinding0">
        <security mode="Transport">
          <transport clientCredentialType="Certificate" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
  <services>
    <service name="WcfService1.Service1">
      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="NewBinding0" contract="WcfService1.IService1" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceCredentials>
          <clientCertificate>
            <authentication certificateValidationMode="PeerTrust" />
          </clientCertificate>
          <serviceCertificate findValue="....." x509FindType="FindByThumbprint" />
        </serviceCredentials>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <protocolMapping>
    <add scheme="https" binding="wsHttpBinding" bindingConfiguration="NewBinding0" />
  </protocolMapping>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

客户端配置文件

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="NewBehavior0">
                <clientCredentials>
                    <clientCertificate findValue="customuser1"
                        storeName="TrustedPeople" x509FindType="FindBySubjectName" />
                </clientCredentials>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <wsHttpBinding>
            <binding name="NewBinding0">
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://www.insertoursitename.com/WcfService1/Service1.svc"
            behaviorConfiguration="NewBehavior0" binding="wsHttpBinding"
            bindingConfiguration="NewBinding0" contract="ServiceReference1.IService1"
            name="wsHttpBinding_IService1" />
    </client>
</system.serviceModel>

【问题讨论】:

  • 服务器日志没有任何错误,客户端日志有:HTTP请求被客户端身份验证方案“匿名”禁止。
  • 完整的 WCF 跟踪会在客户端和服务器端产生大量信息。如果您的服务器没有日志,那么您实际上并没有打开 WCF 跟踪。或者问题出在 IIS 中,请求甚至没有到达 WCF 服务,但即便如此,您应该在客户端上有更多日志。无论如何,请检查 IIS 服务器是否信任客户端证书(只需在服务器上打开客户端证书)。

标签: c# wcf ssl


【解决方案1】:

我的问题和你的很相似,在回答问题之前我会先描述一下我的情况。

  1. 创建了一个简单的 WCF 服务(使用自定义绑定,但这无关紧要)。
  2. 使用makecert创建了一个自签名的RootCA,并生成了两个证书tempCertServer.cer用于SSL加密,配置IIS需要https等。 --> 测试了这部分,在另一台计算机的浏览器上运行正常。
  3. 第二个证书 tempCertClient.cer 被用作提交给 IIS 的客户端证书,将 IIS 配置为需要客户端证书等 --> 从浏览器测试这部分(最好使用 IE,因为您可以轻松清除 SSL 状态)。我收到选择客户端证书的提示,但从未连接,错误与问题完全相同: “HTTP 请求被客户端身份验证方案‘匿名’禁止。内部异常:远程服务器返回错误:(403) Forbidden。”
  4. 将 tempCertClient 替换为适当的证书(来自已知 CA),没有问题,已建立连接并显示 WCF 页面;无论我尝试使用自签名客户端证书做什么,总是会出现错误。

浪费了一整天++尝试各种设置,阅读有关注册表更改的博客,将证书服务器端放在不同的证书存储区,更改配置文件设置等,但没有解决。

答案很简单,检查 LocalComputer\Trusted Root Certification Authorities 服务器端,并删除任何非根 CA(即那些不应该存在的 CA,IssedTo NOT EQUALS IssuedBy)

client-cert 本身不需要安装在服务器上,只需在 LocalComputer\Trusted Root Certification Authorities 服务器端安装一个可以验证它的根 CA。

【讨论】:

  • 非常感谢,我们遇到了完全相同的问题。按照您的描述清理受信任的根证书为我们解决了这个问题。重新启动 WCF 服务(无需重新启动系统)后,我们能够使用客户端证书进行连接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-16
  • 1970-01-01
  • 1970-01-01
  • 2017-06-01
  • 2012-07-19
相关资源
最近更新 更多