2014-12-05 138 views
0

我们遇到了WCF的问题 - 尝试连接时出现以下错误。对于各种配置有很多建议,尝试过所有我们可以使用的帮助。WCF显示403禁止使用SSL和客户端证书

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

对于认证,我们使用我们自己创建的客户端证书。在我们切换到HTTPS之前,这些客户端证书工作正常,当时我们正在使用自签名服务器证书的消息安全性(这很痛苦,因为我们必须让客户端安装服务器证书)。

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

服务器配置文件

<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> 
+0

打开WCF日志记录:http://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx – fejesjoco 2014-12-05 19:47:30

+0

服务器日志没有任何错误,客户端日志有:客户端认证方案“匿名”禁止HTTP请求。 – John 2014-12-05 22:38:28

+0

完整的WCF跟踪会在客户端和服务器端产生大量的信息。如果您的服务器没有日志,那么您实际上并未打开WCF跟踪。或者问题出现在IIS中,并且请求甚至不能到达WCF服务,但即使如此,您应该在客户端上拥有更多的日志。无论如何,请检查IIS服务器是否信任客户端证书(只需在服务器上打开客户端证书)。 – fejesjoco 2014-12-05 23:17:41

回答

0

我的问题是你的差不多,并在回答问题之前描述我的情景。

  1. 创建一个简单的WCF服务(通过自定义绑定,但是这无关紧要)。
  2. 创建使用makecert自签名的根CA,并且产生了两个证书tempCertServer.cer用于SSL加密,IIS配置为需要HTTPS等 - >测试这一部分的工作确定从浏览器从不同电脑。
  3. 第二个证书tempCertClient.cer被用作提交给IIS的客户端证书,配置IIS以要求client-cert等。 - >从浏览器测试此部分(最好使用IE,因为你可以轻松清除SSL状态)。我得到一个提示选择一个客户端证书,但从来没有连接,错误是完全一样的每个问题: “HTTP请求被禁止客户端身份验证方案'匿名'。内部异常:远程服务器返回一个错误:(403)禁止。“
  4. 用正确证书(来自已知CA)替换了tempCertClient,没有问题,建立了连接并显示了WCF页面;无论我用自签名客户端证书尝试了什么,总会遇到以上错误。

浪费一整天试图++各种设置,在注册表更改阅读博客,根据不同的证书存储放置证书服务器端,更改配置文件的设置等,有没有解决方案。

答案很简单,检查LocalComputer \ Trusted Root Certification Authorities服务器端,并删除任何非ROOT CA(即:那些不应该在那里,颁发给不等于已颁发)

客户端证书本身并不需要安装在服务器上,只有可以验证它的根CA必须安装在LocalComputer \ Trusted Root Certification Authorities服务器端。