如何在WCF上设置SSL?

时间:2015-02-13 15:12:00

标签: c# asp.net wcf ssl

我在生产环境中收到的错误:

  

根据验证程序,远程证书无效   [AuthenticationException:根据验证过程,远程证书无效。]     System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message,AsyncProtocolRequest asyncRequest,Exception exception)+2755308
  System.Net.Security.SslState.StartSendBlob(Byte [] incoming,Int32 count,AsyncProtocolRequest asyncRequest)+470

生产环境使用三层架构,Web与App和App对话与数据库对话。 Web和App使用WCF服务层通过SSL进行通信(443)。我们认为它可能是IIS7中的SSL证书或WCF配置问题中的配置。

我们尝试了什么: 我将App和Web中的证书添加到了Trusted Authority中,用于本地计算机和#34;和"当前用户"。

如果需要,我可以添加我的WCF Web配置。

我尝试了以下建议:

https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/ms734695.aspx

"The remote certificate is invalid according to the validation procedure." using Gmail SMTP server

How do I know what the storeName of a certificate?

https://msdn.microsoft.com/en-us/library/ms733813(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/hh556232%28v=vs.110%29.aspx

Self-Hosted WCF Service with Mutual SSL (between Service and Client) fails with 403 Forbidden

1 个答案:

答案 0 :(得分:1)

此答案适用于您将有效负载的证书发送到HTTPS端点的客户端证书。

您需要确保信任该证书,您信任创建该证书的证书颁发机构,并确保您在受信任的商店中拥有该CA的证书。

您是否可以访问您需要提供证书的系统(而非WCF服务)上的简单网页? 即:https://mysite/test.aspx 这将允许您测试WCF之外的证书,并让您将WCF问题与IIS问题分开。

1)确保在IIS中设置证书映射。 http://www.iis.net/configreference/system.webserver/security/authentication/clientcertificatemappingauthentication http://blogs.msdn.com/b/asiatech/archive/2014/02/13/how-to-configure-iis-client-certificate-mapping-authentication-for-iis7.aspx

短暂的;博士;我们做了什么:

  • 将您的客户端证书添加到您的证书存储区(私钥)
  • 将用户添加到本地用户
  • 转到IIS并将证书映射到您创建的用户
  • 运行winhttpcfg.exe以提供App Pool的用户 访问该证书

https://msdn.microsoft.com/en-us/library/windows/desktop/aa384088%28v=vs.85%29.aspx

2)确保您的web.config设置正确 (来自我们的样本,允许通过HTTP和HTTPS命中终点)

<bindings>
   <basicHttpBinding>
     <!-- Secure Bindings -->
     <binding name="secureHttpBinding">
       <security mode="Transport">
         <transport clientCredentialType="Certificate" />
       </security>
      </binding>

      <binding name="httpBinding">
        <security mode="None" />
      </binding>
   </basicHttpBinding>
</bindings> 

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
         <!-- Person Revised Service-->
        <service name="Services.PRPA_AR101202" behaviorConfiguration="ServiceBehaviour">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="Services.IPRPA_AR101202"></endpoint>
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpBinding" contract="Services.IPRPA_AR101202" />
        </service>
</services>

同样,这个答案是针对带有消息的客户端证书,如果它只是普通的HTTP,你可以忽略它