我有一个 WCF 客户端/服务应用程序,它依赖于两台计算机之间的安全通信,并且我想使用证书存储中安装的 x509 证书来相互识别服务器和客户端。我通过将绑定配置为来做到这一点 <security authenticationMode="MutualCertificate"/>. 。只有客户端机器。

服务器具有颁发给安装在本地计算机/个人存储中的 server.mydomain.com 的证书,客户端具有颁发给安装在同一位置的 client.mydomain.com 的证书。除此之外,服务器在本地计算机/受信任的人员中具有客户端的公共证书,并且客户端在本地计算机/受信任的人员中具有服务器的公共证书。

最后,客户端已配置为检查服务器的证书。我这样做是使用 system.servicemodel/behaviors/endpointBehaviors/clientCredentials/serviceCertificate/defaultCertificate 配置文件中的元素。

到目前为止一切顺利,这一切都有效。我的问题是,我想在服务器的配置文件中指定,仅允许使用受信任的人证书存储中的 client.mydomain.com 证书标识自己的客户端进行连接。

使用以下命令可以在服务器上获得正确的信息 ServiceSecurityContext, ,但我正在寻找一种方法来在 app.config 中指定 WCF 应该执行此检查,而不是必须从代码中检查安全上下文。

那可能吗?任何提示将不胜感激。

顺便说一句,到目前为止,我的服务器的配置文件如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="MyServer.Server" behaviorConfiguration="CertificateBehavior">
        <endpoint contract="Contracts.IMyService" binding="customBinding" bindingConfiguration="SecureConfig">
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/SecureWcf"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CertificateBehavior">
          <serviceCredentials>
            <serviceCertificate storeLocation="LocalMachine" x509FindType="FindBySubjectName" findValue="server.mydomain.com"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="SecureConfig">
          <security authenticationMode="MutualCertificate"/>
          <httpTransport/>
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>
</configuration>
有帮助吗?

解决方案

有没有出现有一种方法做我想要使用的web.config什么。

我结束了加入行为与该标记:

<clientCertificate>
  <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" revocationMode="NoCheck"/>
</clientCertificate>

然后在客户端的证书添加到服务器运行的用户的“信任的人”证书存储区。

其他提示

查看 WCF 安全指南 Codeplex 上的页面 - 优秀且非常有用的东西!

特别是,请查看操作方法,更具体地说

如何 - 在从 Windows 窗体进行 WCF 调用时使用证书身份验证和消息安全性

它详细解释了如何设置要求客户端提供有效证书的 WCF 服务以及如何检查该证书。如果您只想允许单个客户端,请仅将该证书专门部署到该单个客户端。

希望这可以帮助!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top