WCF net.tcp SSL,证书和用户名密码身份验证

WCF net.tcp SSL, certificate and username + password authentication

我想构建一个满足以下要求的客户端服务器WPF-WCF应用程序:

  • 快速地
  • 客户端和服务器之间的安全通信
  • 如果用户要使用客户端应用程序,则应在其计算机上安装特定证书,并提供有效的用户名/密码对。
  • 一切都应该通过互联网进行

所以我两天前就开始研究它,在经历了几乎所有示例/教程之后,我发现它都接近于我的情况,我设法用IIS(托管在net.tcp绑定中构建了WCF服务(我认为是8),并通过mex端点和一个小的客户端控制台应用程序公开其元数据,该控制台应用程序可以连接到该服务并调用其唯一的HelloWorld方法。

一切都很好,直到我开始尝试添加基于证书的安全性为止。我尝试了无数的配置组合和技术,但仍然无法正常工作。

起初,我收到一些特定的错误消息,这些错误消息告诉我有关服务器或客户端证书不是有效,受信任或以任何方式对任何事物都有益的各种事情。
然后,我遵循了这些文章,因为在开发时我需要自签名证书。

  • http://msdn.microsoft.com/en-us/library/ff647171.aspx
  • http://msdn.microsoft.com/zh-CN/library/ms733813(v=vs.110).aspx
  • http://msdn.microsoft.com/en-us/library/ff648498.aspx

然后,我开始收到越来越多的模糊错误消息,直到我放弃。
很可能是我误解了WCF的工作原理,因为我没有太多的经验。

有效的配置是这样的:

  • 服务配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <configuration>
      <system.web>
        <httpRuntime targetFramework="4.5.1"/>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="TcpServiceBehaviour">
              <serviceMetadata />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <services>
          <service behaviorConfiguration="TcpServiceBehaviour" name="WcfTcpServer.TcpService">
            <endpoint address="net.tcp://serverName/wcftcpserver/TcpService.svc" binding="netTcpBinding" name="TcpServiceEndpoint" contract="WcfTcpServer.ITcpService" />
            <endpoint address="SME" binding="mexTcpBinding" bindingConfiguration="" name="ServiceMetadataEndpoint" contract="IMetadataExchange" />
          </service>
        </services>
      </system.serviceModel>
    </configuration>
  • 客户端配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
      </startup>
      <system.serviceModel>
        <client>
          <endpoint address="net.tcp://serverName/wcftcpserver/TcpService.svc" binding="netTcpBinding" contract="WcfTcpServer.ITcpService" name="TcpServiceEndpoint">
            <identity>
              <servicePrincipalName value="host/serverName.smth.smthElse.ro" />
            </identity>
          </endpoint>
        </client>
      </system.serviceModel>
    </configuration>

如您所见,这就是无证书配置。
我在此配置中使用我的自签名证书所采取的任何步骤都会破坏应用程序。

我对所有内容都使用.NetFramework 4.5.1。

非常感谢您提供有关此问题的帮助。如果需要,我可以提供尝试的其他配置。

这甚至有可能还是我徒劳地尝试吗?

谢谢!


简而言之,是的,您可以使用所谓的"支持令牌"来支持多个客户端凭据。

从链接的文章中:

The example adds an X.509 binary security token in addition to a
username security token. The token is passed in a WS-Security message
header from the client to the service and part of the message is
signed with the private key associated with the X.509 security token
to prove the possession of the X.509 certificate to the receiver. This
is useful in the case when there is a requirement to have multiple
claims associated with a message to authenticate or authorize the
sender.

关于在Internet上使用NetTcpBinding的主题:

对于内部网方案,通常建议使用

NetTcpBinding。根据我的大量阅读建议,根据您的要求在Internet场景中使用WsHttpBindingBasicHttpBinding。如果安全是您的头等大事-推荐的选择是具有Message级安全性的WsHttpBinding

有关为Internet方案选择绑定的指南:Internet绑定方案。