gpt4 book ai didi

WCF - 使用 SSL 的加密(可能还有身份验证)

转载 作者:太空宇宙 更新时间:2023-11-03 15:06:52 25 4
gpt4 key购买 nike

这是我的场景和问题:

  • 我们有一个 Windows 2008 R2 服务器 (IIS7)
  • SSL 认证
  • .NET 4

我试着在网上寻找一个好的资源,但其中大部分都不完整,而且彼此之间差异很大,以至于它们无法真正混合搭配。我希望使用 WCF 服务来传递来 self 的客户端/服务器的加密消息。我也将实现一些自定义身份验证方案。身份验证方案将在第一次身份验证时验证用户/通过。然后从那时起,客户端将使用随机生成的代码作为他们的身份验证。

根据我收集到的信息,我需要执行以下操作:

  • [ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
  • 使用 WSHttpBinding

这是我有点不知所措的地方。有太多的资源说明服务器和客户端的配置文件应该如何,我真的很困惑。我的服务器/客户端配置文件应该是什么样子,以便我的服务发送/接收加密消息并可以指向自定义身份验证?


或者,如果我不能将此自定义身份验证用作 WCF 客户端对象的参数,只要消息已加密,我将只将身份验证凭据作为消息本身的一部分传递。

如果那里有一个实际的、完全完整的(即不是部分信息)资源,那就太好了。或者,如果有人知道要使用的必要客户端/服务器 App.config/Web.config 设置,那也很好。

最佳答案

我相信您希望使用 HTTPS 来确保传输级别的加密和签名。您需要首先使用 SSL 证书配置 IIS7.5,并在托管服务的应用程序中允许 https。检查this tutorial但您将使用现有证书而不是创建自签名证书。您的证书应该为您网站的主机 header (例如 mydomain.com)或直接公开的服务器名称创建。

在您的服务中,您需要带有传输安全和消息凭证的 basicHttpBinding 以进行身份​​验证。

<bindings>
<basicHttpBinding>
<binding name="secured">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="securedService">
<serviceMetadata httpsGetEnabled="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" userNamePasswordValidator="..." />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="..." behaviorConfiguration="securedService">
<endpoint address="" contract="..." binding="basicHttpBinding" bindingConfiguration="secured" />
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpsBinding" />
</service>
</services>

客户端将使用类似的设置:

<bindings>
<basicHttpBinding>
<binding name="secured">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="..." address="https://..." contract="..." binding="basicHttpBinding" bindingConfiguration="secured" />
</client>

此配置定义了 SOAP 1.1 服务,该服务符合通过 HTTPS 传输保护并受用户名和密码保护。服务还通过 HTTPS 公开其元数据 (WSDL)。用户名和密码由自定义密码验证器验证(您必须 implement one )。

您将在客户端设置凭据(由添加服务引用生成):

var client = new MyServiceClient();
client.ClientCredentials.UserName.UserName = "Name";
client.CleintCredentials.UserName.Password = "Password";

消息的加密是在传输层完成的。每次创建新代理时都必须配置凭据,但它们会重复用于来自代理的所有调用。

您的方案可能不需要 WsHttpBinding。设置 ProtectionLevel 仅用于消息级安全性 - 我认为这不是您要找的。

不要使用您描述的自定义身份验证:

The authentication scheme will verify the user/pass on the first time authentication. Then from then on the client will use a randomly generated code as their authentication instead.

要复杂得多。您将推出自己的非标准解决方案,或者您将使用 WCF 的内置实现(安全对话),但并非每个客户端 SOAP 堆栈都能够使用此类服务​​(它完全依赖于高级消息安全性)。

关于WCF - 使用 SSL 的加密(可能还有身份验证),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5861086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com