5

我一直在努力使用 WCF 一段时间,但我似乎无法弄清楚。我有一个启用 SSL 的自托管 WCF 服务(使用来自自签名根 CA 的签名证书),到目前为止一切顺利。该服务用于企业对企业的通信,因此证书似乎是最佳解决方案。

(我目前正在使用 WS 绑定,但这只是出于开发目的,因为所有绑定方法都支持(据我所知)客户端证书的传输级安全性。)

服务的一些相关配置位:

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

<!-- snip -->

<serviceCredentials>
  <clientCertificate>
     <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
  </clientCertificate>
</serviceCredentials>

当我让客户端使用运行 WCF 服务的用户的“受信任的人”存储中的自签名证书时,它会失败。当我使用由我自己的根 CA 签名的证书时,即使它不在“受信任的人”存储中,它也可以工作。

我期待我能够使用自签名证书,将它们存储在“受信任的人”存储中,并且一切正常。但似乎有一些额外的验证正在进行,我错过了什么吗?有没有更好的办法?

4

3 回答 3

3

我遇到了同样的问题,其中我的自签名客户端证书将被验证,即使它不在“受信任的人”存储中,尽管“PeerTrust”的验证模式。通过使用以下服务行为,我终于能够将服务限制为仅接受特定的客户端证书:

<behaviors>
   <serviceBehaviors>
      <behavior ...>
      ...
         <serviceCredentials>
            <clientCertificate>
               <authentication certificateValidationMode="PeerTrust"
                               revocationMode="NoCheck" 
                               trustedStoreLocation="LocalMachine" />
               <certificate findValue="NameOfClientCertificate"
                            x509FindType="FindBySubjectName"
                            storeLocation="LocalMachine"
                            storeName="TrustedPeople" />
            </clientCertificate>
         </serviceCredentials>
         ...
      </behavior>
      ...

身份验证元素和证书元素都需要指向正确的存储,在本例中为“LocalMachine”。

于 2016-03-16T17:55:47.593 回答
0

对,因此,传输安全和证书验证在 WCF 无法控制的较低级别处理。所以所有那些带有自定义验证器等的花哨的东西都不适用于传输安全,只有消息安全。要在仅使用传输安全性的同时限制来自客户端的访问,您需要设置 CTL(证书信任列表)。以下网站应该给你一些指导。

http://www.leastprivilege.com/CertificateBasedAuthenticationAndWCFTransportSecurity.aspx http://viisual.net/configuration/IIS7-CTLs.htm

于 2010-07-13T10:05:23.817 回答
0

我设法使用这些代码行使其工作:

m_host = gcnew WebServiceHost( IService::typeid, baseAddress );
....
m_host->Credentials->ClientCertificate->Authentication->CertificateValidationMode = X509CertificateValidationMode::Custom;  //PeerTrust did not work here
m_host->Credentials->ClientCertificate->Authentication->CustomCertificateValidator = System::IdentityModel::Selectors::X509CertificateValidator::PeerTrust;

对我来说看起来像 WCF 错误。

于 2018-11-06T22:21:24.783 回答