wcf - 如果没有本地计算机上的服务器证书,客户端 WCF 无法连接到服务器 WCF

标签 wcf ssl certificate client-server x509

场景是这样的:有2个WCF Web Services,一个是客户端(WCFClient),一个是服务端(WCFServer),部署在不同的机器上。我需要他们两个之间的证书通信。

在服务器 WCF 上,我已将绑定(bind)设置为使用证书作为客户端凭据类型。

<security mode="Message">
      <message clientCredentialType="Certificate" />
</security>

此外,在行为部分,我还有其他设置

<serviceBehaviors>
      <behavior name="Server.ServiceBehavior">                  
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust"/>
            </clientCertificate>
            <serviceCertificate findValue="Server"
            storeLocation="LocalMachine"
            storeName="TrustedPeople"
            x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>
</serviceBehaviors>

在客户端 WCF 服务上,我添加了这个端点行为

<endpointBehaviors>
   <behavior name="CustomBehavior">
     <clientCredentials>
       <clientCertificate findValue="Client" 
                          x509FindType="FindBySubjectName" 
                          storeLocation="LocalMachine" 
                          storeName="TrustedPeople" />
       <serviceCertificate>            
         <authentication certificateValidationMode="PeerTrust"/>
       </serviceCertificate>
     </clientCredentials>
   </behavior>
 </endpointBehaviors>

当我想测试我的服务时,我收到一条错误消息:

没有为目标“http://blablabla...”提供服务证书。在 ClientCredentials 中指定服务证书。

所以我开始上网查资料。在尝试了很多事情之后,唯一真正起作用的是在我的客户端上添加这个:

<serviceCertificate>
         <defaultCertificate findValue="Server"
                             storeLocation="LocalMachine"
                             storeName="TrustedPeople"
                             x509FindType="FindBySubjectName" />
         <authentication certificateValidationMode="PeerTrust"/>
       </serviceCertificate>

如您所想,是的,这意味着我需要在我的客户端计算机上使用服务器证书。这显然是一件非常糟糕的事情。 它适用于我的测试目的,但对于部署来说是 Not Acceptable 。

我想了解究竟是什么导致了该错误消息以及可能的解决方案。

稍后编辑:在这个项目中,客户端不能有服务器证书(即使没有私钥)。这是系统的规范,要超越它是相当困难的(在 bureaucracy 术语中)。 将有多个客户端,每个客户端都运行着客户端 WCF 服务,每个客户端应该只知道自己的证书。服务器将知道服务器证书和所有客户端证书。

最佳答案

寻找 here上面写着,

When considering authentication, you may be used to thinking primarily of the client identity. However, in the context of WCF, authentication typically refers to mutual authentication. Mutual authentication not only allows positive identification of the clients, but also allows clients to positively identify the WCF services to which they are connected. Mutual authentication is especially important for Internet-facing WCF services, because an attacker may be able to spoof the WCF service and hijack the client’s calls in order to reveal sensitive data.

The service credentials to be used depend largely on the client authentication scheme you choose. Typically, if you are using non-Windows client authentication such as username or certificate authentication, a service certificate is used for both service authentication and message protection. If you are using Windows client authentication, the Windows credentials of the process identity can be used for both service authentication and message protection.

在我看来,您确实需要客户端计算机上的服务器证书,这是好事,而不是坏事。请注意,您不需要(也不应该将)服务器的私钥放在客户端机器上。私钥不包含在证书中——只有公钥包含。

在客户端机器上拥有服务器证书意味着在客户端机器上只有服务器的公钥。好处是客户端现在知道它正在与真实服务器对话。

我不熟悉 WCF 服务,但就证书的使用而言,这似乎没问题。

关于wcf - 如果没有本地计算机上的服务器证书,客户端 WCF 无法连接到服务器 WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9841284/

相关文章:

.htaccess - 强制特定 URL 为 HTTP 而不是 HTTPS

iOS 使用自签名 TLS/SSL 证书连接不起作用

wcf - 已超出传入消息的最大消息大小配额 (65536)

php - POST - 500(内部服务器错误)

.net - HTTP 方法 GET、POST、PUT 和 DELETE 之间有什么区别

api - 使用 java mail api 连接到 Exchange 服务器的 pop3 连接失败

web-services - 德尔福HTTPRIO : any way to disable certificate prompt?

certificate - 如何用通配符证书替换 "Kubernetes fake certificate"(在裸机私有(private)云上)Nginx Ingress 和证书管理器

.net - ADO .Net - 如何在具有多个 IP 地址的系统上的 SqlConnection 中指定源 IP 地址

.net - 为什么我发现 WCF 的性能比远程处理的性能慢?