使用UserNameOverTransport绑定时,如何让WCF以摘要模式发送密码? (将WSE3.0代码转换为WCF)

我正在尝试将此WSE3.0代码转换为WCF:

// we use Microsoft WSE 3.0 to insert the username token in the soap header. // This strategy takes care of creating and inserting the Nonce and Created elements // for us, as well as creating a password digest based on Nonce, Created, and // the password itself. Refer to the WS-Secutiry UsernameToken Profile 1.1 // specification at http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=wss. Microsoft.Web.Services3.Security.Tokens.UsernameToken nametoken; nametoken = new Microsoft.Web.Services3.Security.Tokens.UsernameToken(username, password, Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendHashed); Microsoft.Web.Services3.Design.Policy ClientPolicy = new Microsoft.Web.Services3.Design.Policy(); ClientPolicy.Assertions.Add(new UsernameOverTransportAssertion()); this._proxy.SetPolicy(ClientPolicy); this._proxy.SetClientCredential(nametoken); 

除了以摘要模式发送密码(上面代码中的Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendHashed )之外,我已经非常接近了:

 TransportSecurityBindingElement transportBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement(); transportBindingElement.AllowInsecureTransport = true; transportBindingElement.EnableUnsecuredResponse = true; transportBindingElement.IncludeTimestamp = true; var binding = new CustomBinding(new BindingElement[] { // transportBindingElement, // new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Soap11 }, // new HttpTransportBindingElement() { AuthenticationScheme = AuthenticationSchemes.Digest, }, // }); 

以上仍然以纯文本(未散列)发送密码。 我找到了这个链接 ,试图转换类似的代码,有人说,如果不编写自定义令牌序列化器,就无法设置WCF来执行此操作。

这个陈述准确吗?

如果是,我需要做什么才能创建和使用这个自定义序列化程序?

看起来这个链接可能是一个很好的起点,当与评论中链接的网站中的PDF结合使用时,会给出以下公式Password_Digest = Base64 ( SHA-1 ( nonce + created + password ) )但是如果有人有更好的解释正是我需要从中得到的以及如何让WCF使用我的新序列化器,我很乐意听到它。

你找到了我的问题:)

这是一个非常有趣的问题。 MS经常被指责他们生产不安全的系统和API,因此MS中的一些工程师开始融入关于什么是安全的,什么不适用于新API的一些想法。 具有消化密码的UserNameToken配置文件正是这项工作的结果。 它被认为是不够安全的,因此它完全从WCF中省略。 好吧,如果WCF不是与其他平台和框架互操作的API,那么它应该不是问题,其中UserNameToken配置文件和消化密码非常受欢迎。

是的,当我们解决问题时,我们做了自定义令牌序列化器。 它不仅仅是令牌序列化器。 你实际上必须实现很多类才能使它工作。 我不会分享我们的实现,因为它不是我的代码,但你可以尝试这个 。