【问题标题】:Transport Security with Certificate Authentication具有证书身份验证的传输安全性
【发布时间】:2010-11-02 23:14:16
【问题描述】:

当我访问我的网络服务 localhost/MyService/MyService.svc 时出现以下错误

服务“SslRequireCert”的 SSL 设置与 IIS“Ssl,SslNegotiateCert”的设置不匹配。

我已按照http://msdn.microsoft.com/en-us/library/ms731074.aspx 中指定的 web.config 示例进行操作

这是我的 wcf 服务器 web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <appSettings />
  <system.web>
    <identity impersonate="false" />
    <roleManager enabled="true" />
    <authentication mode="Windows" />
    <customErrors mode="Off" />
    <webServices>
      <protocols>
        <add name="HttpGet" />
        <add name="HttpPost" />
      </protocols>
    </webServices>
  </system.web>
  <system.webServer>
    <directoryBrowse enabled="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <security>
      <authorization>
        <remove users="*" roles="" verbs="" />
        <add accessType="Allow" users="*" roles="" />
      </authorization>
    </security>
  </system.webServer>
  <system.serviceModel>
    <services>
      <service name="AspNetSqlProviderService" behaviorConfiguration="MyServiceBehavior">
        <endpoint binding="wsHttpBinding" contract="Interface1" bindingConfiguration="CertificateWithTransportWSHttpBinding" />
        <endpoint binding="wsHttpBinding" contract="Interface2" bindingConfiguration="CertificateWithTransportWSHttpBinding" />
        <endpoint address="mex" binding="wsHttpBinding" bindingConfiguration="CertificateWithTransportWSHttpBinding" name="Metadata_Exchange" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceMetadata />
          <serviceCredentials>
            <clientCertificate>
              <authentication trustedStoreLocation="LocalMachine"
                               revocationMode="Online"/>
            </clientCertificate>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="CertificateWithTransportWSHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

我的 IIS 配置如下:

  • 使用自签名证书添加了 https 绑定
  • 在 SSL 设置下,勾选需要 SSL 并接受客户端证书
  • 自签名证书已添加到本地计算机受信任的根 CA。

我可以浏览和执行 .asmx 服务定义,但是 .svc 给了我上述错误。

【问题讨论】:

    标签: wcf ssl ssl-certificate transport-security


    【解决方案1】:

    尝试注释掉你的 mex 端点。这应该让它工作

    【讨论】:

      【解决方案2】:

      流程如下

      1. 在 IIS 中创建自签名证书。
      2. 在 IIS 中创建站点。
      3. 将站点设置为需要 SSL。
      4. 当您在绑定中选择 https 协议时,IIS 7 中的一个故障不允许您指定站点的主机名。有说明 here 可以正确设置此绑定的主机名。
      5. 在你的网络配置中修改它

        <wsHttpBinding> 
           <binding name="CertificateWithTransportWSHttpBinding"> 
               <security mode="Transport"> 
                  <transport clientCredentialType="none" /> 
               </security> 
           </binding> 
        </wsHttpBinding>
        
        
        <serviceBehaviors>  
           <behavior name="MyServiceBehavior">  
              <serviceDebug includeExceptionDetailInFaults="True" />  
                 <serviceMetadata />   
           </behavior>  
        </serviceBehaviors>  
        
      6. 在您的 MEX 端点中设置 binding="wsHttpsBinding"

      如果您完成上述所有操作,您应该可以使用 SSL WCF 服务启动并运行。

      【讨论】:

        【解决方案3】:

        我为此苦苦思考了至少 2-3 个小时,并忽略了上面关于注释掉你的 mex 端点的回复。

        这被证明是我的答案,所以只是想重新执行上面的答案。请参阅上述帖子第 7 步底部的评论:

        http://consultingblogs.emc.com/matthall/archive/2009/10/22/client-certificate-authorisation-with-wcf-in-development-environments.aspx

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-09-16
          • 2010-12-06
          • 2011-06-08
          • 1970-01-01
          • 2010-10-27
          • 1970-01-01
          • 2014-04-30
          • 2015-09-15
          相关资源
          最近更新 更多