4

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

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

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

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

正确的信息在使用ServiceSecurityContext.

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

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

<?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>
4

2 回答 2

2

似乎没有办法使用 web.config 做我想做的事。

我最终用这个标签添加了一个行为:

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

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

于 2010-04-08T08:07:26.923 回答
1

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

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

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

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

希望这可以帮助!

于 2010-02-16T21:51:49.743 回答