WCF net.tcp SSL、证书和用户名+密码认证

标签 wcf ssl forms-authentication net.tcp .net-4.5

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

  • 客户端和服务器之间的安全通信
  • 如果用户想使用客户端应用程序,他应该在他的机器上安装某个证书并提供有效的用户名/密码对
  • 一切都应该在互联网上发生

所以我两天前开始研究它,在浏览了几乎所有我能找到的与我的场景接近的示例/教程之后,我设法构建了一个带有 net.tcp 绑定(bind)的 WCF 服务,该服务托管在 IIS 中( 8 我认为)并通过一个 mex 端点和一个微型客户端控制台应用程序公开其元数据,该应用程序可以连接到该服务并调用其唯一的 HelloWorld 方法。

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

起初,我收到一些特定的错误消息,告诉我有关服务器或客户端证书无效、不可信或对任何方面都没有好处的各种信息。 然后我按照这些文章,因为我在开发时需要自签名证书。

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

有效的配置是这样的:

  • 服务配置

    <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>
    
  • 客户端配置

    <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。

我非常感谢帮助解决这个问题。如果需要,我可以提供我尝试过的其他配置。

这是可能的还是我的尝试是徒劳的?

谢谢!

最佳答案

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

来自链接的文章:

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 一般推荐用于内网场景。我读过的大部分内容都建议根据您的要求将 WsHttpBindingBasicHttpBinding 用于 Internet 场景。如果安全是您最关心的问题 - 推荐的选择是具有 Message 级别安全性的 WsHttpBinding

为互联网场景选择绑定(bind)的指南:Internet Binding Scenarios .

关于WCF net.tcp SSL、证书和用户名+密码认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22249973/

相关文章:

ssl - WebSockets : wss from client to Amazon AWS EC2 instance through ELB

tomcat 不使用 JDBCRealm,而是坚持使用 UserDatabaseRealm

asp.net - Facebook Connect 和 ASP.NET 表单例份验证 - 计时/Cookie 问题

c# - 为什么向我的 WCF 服务操作添加参数会起作用?

c# - 在第一次尝试使用 WCF 失败后,客户端如何尝试重新连接到服务器?

WCF REST 缓存 - 客户端和服务器端

asp.net - IIS - 需要特定 MVC Controller 的 SSL 客户端证书

node.js - 无法验证第一个证书 - Nodejs TLS

c# - 用户名上的 SharePoint 表单例份验证提供程序名称前缀

c# - 如何使用来自不同项目的模型类通过反射提供程序创建 WCF 数据服务 OData?