WCF与相互身份验证

时间:2018-03-01 19:58:57

标签: c# wcf ssl

我正在尝试帮助解决在WCF中编写的需要相互身份验证的第三方自托管Web服务的问题。问题是Web服务正在返回401 Unauthorized。我已经阅读了几篇关于如何在WCF中编写客户端和服务器部分以使用相互身份验证的文章,但我仍然有以下问题:

  1. 客户端发送客户端证书后,WCF服务如何确定是否接受它作为可访问给定资源的经过身份验证的端点。证书只需要能够在证书存储中找到证书的根CA作为受信任的根CA,或者是否有某种机制将证书映射到已被识别为允许的证书的实体列表中访问资源?

  2. 通常当我看到使用相互认证时,在Wireshark中我看到服务器响应客户端Hello和证书请求以及服务器Hello,证书和证书请求。但是,在我正在排除故障的情况下,我没有看到服务器发送证书请求。我相信客户端正在以加密数据发送其证书,但我无法解密数据以查看它。有没有办法强制WCF服务使用服务器Hello发送证书请求?

  3. 配置文件包含以下内容:

    <bindings>
      <webHttpBinding>
        <binding name="webHttpTransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings> 
    

    我认为这足以表明客户端应该使用证书进行身份验证,但现在该服务如何决定该证书是否是允许的证书?

1 个答案:

答案 0 :(得分:0)

您的binding定义看起来是正确的。证书在endpointBehaviors中定义。这有点难以理解,因为它在不同的XML组中被拆分。

以下是我的项目的一个例子:

<client>
  <endpoint address="(address to our)WebService.svc"
            behaviorConfiguration="behaviorConfig"
            binding="webHttpTransportSecurity"
            bindingConfiguration="bindingConfig"
            contract="((your contract name))"
            name="mainEndPoint">
    <identity>
      <certificateReference findValue="CN=((cert name like blah.blah.blah-blah.blah)), OU=((lookup)), O=((lookup))"
                            storeLocation="LocalMachine"
                            storeName="TrustedPeople"
                            x509FindType="FindBySubjectDistinguishedName" />
    </identity>
  </endpoint>
</client>
<bindings>
  <!-- you already have a good looking binding (above) -->
</bindings>
<behaviors>
  <serviceBehaviors ...etc  />
  <endpointBehaviors>
    <behavior name="behaviorConfig">
      <clientCredentials>
        <clientCertificate findValue="CN=((short name)), OU=((lookup)), O=((lookup))"
                           storeLocation="LocalMachine"
                           storeName="My"
                           x509FindType="FindBySubjectDistinguishedName" />
        <serviceCertificate>
          <defaultCertificate findValue="CN=((same content from certificateReference above)), OU=((lookup)), O=((lookup))"
                              storeLocation="LocalMachine"
                              storeName="TrustedPeople"
                              x509FindType="FindBySubjectDistinguishedName" />
          <authentication certificateValidationMode="PeerTrust"
                          revocationMode="NoCheck"
                          trustedStoreLocation="LocalMachine" />
        </serviceCertificate>
      </clientCredentials>
      <callbackTimeouts />
    </behavior>
  </endpointBehaviors>
</behaviors>