简体   繁体   English

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

[英]How do I get WCF to send the password in digest mode when using UserNameOverTransport binding? (Converting WSE3.0 code to WCF)

I'm trying to convert this WSE3.0 code to 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<UsernameToken>(nametoken);

I have gotten pretty close except for sending the password in digest mode ( Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendHashed in the above code`): 除了以摘要模式发送密码(上面代码中的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,
    }, //
});

The above still sends the password in plain text (unhashed). 以上仍然以纯文本(未散列)发送密码。 I found this link to somebody trying to convert similar code with somebody stating that it was not possible to set up WCF to do this without writing a custom token serializer. 我找到了这个链接 ,试图转换类似的代码,有人说,如果不编写自定义令牌序列化程序就无法设置WCF来执行此操作。

Is this statement accurate? 这个陈述准确吗?

If it is, what do I need to do to create and use this custom serializer? 如果是,我需要做什么才能创建和使用此自定义序列化程序?

It looks like this link might be a good starting place when combined with the PDF from the site linked in the comments that gives the following formula Password_Digest = Base64 ( SHA-1 ( nonce + created + password ) ) but if anybody has a better explanation of exactly what I need to derive from and how to get WCF to use my new serializer I'd love to hear it. 看起来这个链接可能是一个很好的起点,当与评论中链接的网站的PDF结合使用时,会给出以下公式Password_Digest = Base64 ( SHA-1 ( nonce + created + password ) )但是如果有人有更好的解释正是我需要从中得到的以及如何让WCF使用我的新序列化器,我很乐意听到它。

You found my question :) 你找到了我的问题:)

This is very interesting problem. 这是一个非常有趣的问题。 MS was often blamed that they produce insecure systems and APIs and because of that some engineers in MS became incorporating some ideas about what is secure and what is not to new APIs. MS经常被指责他们生产不安全的系统和API,因此MS的一些工程师开始纳入一些关于什么是安全的,哪些不适用于新API的想法。 UserNameToken profile with digested password is exactly result of this effort. 具有消化密码的UserNameToken配置文件正是这项工作的结果。 It is considered as not secure enough and because of that it is completely omitted from WCF. 它被认为不够安全,因此它完全从WCF中省略。 Well, it should not be a problem if WCF would not be an API for interoperability with other platforms and frameworks where UserNameToken profile with digested password is very popular. 好吧,如果WCF不是与其他平台和框架互操作的API,那么它应该不是问题,其中带有消化密码的UserNameToken配置文件非常受欢迎。

Yes we did custom token serializer when we solved the problem. 是的,当我们解决问题时,我们做了自定义令牌序列化器。 It is not only about token serializer. 它不仅仅是令牌序列化器。 You actually have to implement quite lot of classes to make it work. 你实际上必须实现很多类才能使它工作。 I will not share our implementation because it wasn't my code but you can try this one . 我不会分享我们的实现,因为它不是我的代码,但你可以尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM