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

本文关键字:密码 模式 WSE3 WC 转换 代码 绑定 定时 UserNameOverTransport WCF | 更新日期: 2023-09-27 18:04:51

我正在尝试将此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<UsernameToken>(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使用我的新序列化器,我很乐意听到它。

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

你找到我的问题了:)

这是个很有趣的问题。微软经常被指责生产不安全的系统和api,正因为如此,微软的一些工程师开始将一些关于新api安全与不安全的想法纳入其中。带有摘要密码的UserNameToken配置文件正是这一努力的结果。它被认为不够安全,因此在WCF中被完全忽略。嗯,如果WCF不是一个与其他平台和框架互操作性的API,那么它应该不是一个问题,其中UserNameToken配置文件与摘要密码非常流行。

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