首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将WCF配置为仅对TimeStamp标头进行签名

如何将WCF配置为仅对TimeStamp标头进行签名
EN

Stack Overflow用户
提问于 2011-05-09 10:43:31
回答 2查看 3.1K关注 0票数 4

我正在尝试配置我的WCF客户端,以创建包含WS-Addressing、WS-Security和TLS的SOAP 1.1请求。

安全性要求是消息包含用户名令牌TimeStamp,并且使用包含的BinarySecurityToken对TimeStamp进行签名。

我使用了以下link中的示例来创建我的WCF客户端绑定。我稍微修改了示例(见下文),以便使用HTTPS作为传输机制,并且MessageSecurity是基于UsernameOverTransport的。

代码语言:javascript
运行
AI代码解释
复制
            HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();            
        // the message security binding element will be configured to require 2 tokens:
        // 1) A username-password encrypted with the service token
        // 2) A client certificate used to sign the message

        // Instantiate a binding element that will require the username/password token in the message (encrypted with the server cert)
        TransportSecurityBindingElement messageSecurity = SecurityBindingElement.CreateUserNameOverTransportBindingElement();

        // Create supporting token parameters for the client X509 certificate.
        X509SecurityTokenParameters clientX509SupportingTokenParameters = new X509SecurityTokenParameters();
        // Specify that the supporting token is passed in message send by the client to the service
        clientX509SupportingTokenParameters.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;
        // Turn off derived keys
        clientX509SupportingTokenParameters.RequireDerivedKeys = false;
        // Augment the binding element to require the client's X509 certificate as an endorsing token in the message
        messageSecurity.EndpointSupportingTokenParameters.Endorsing.Add(clientX509SupportingTokenParameters);

        // Create a CustomBinding based on the constructed security binding element.
        return new CustomBinding(messageSecurity, httpsTransport);

这个客户端生成的SOAP消息非常接近于满足我调用的服务的要求,唯一的问题是wsa:To地址和TimeStamp地址都要签名。

有没有一种方法可以精确地指定哪些WCF头是签名的?因为我需要限制客户端只对TimeStamp头进行签名。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-14 11:36:11

我知道这是个老生常谈的问题,但我已经被问过好几次了。

我设法做到了这一点,方法是将messageVersion指定为Soap11而不是Soap11WSAddressing10,然后手动添加WS-Addresing头,这样就无需手动实现签名机制。

票数 0
EN

Stack Overflow用户

发布于 2011-05-09 14:20:53

使用自定义消息标头,您可以执行以下操作:

代码语言:javascript
运行
AI代码解释
复制
//... rest of MessageContract

[MessageHeader(ProtectionLevel = ProtectionLevel.Sign)]
string MyCustomHeader;

//... rest of MessageContract

但我认为这不适合您的情况,因为您试图对自定义绑定插入的soap标头进行签名。要修改这些标头,您可能需要实现IClientMessageInspector interface,并向客户端配置中添加一个自定义行为来签署TimeStamp标头。不确定如何访问证书来进行签名,但this may give you a good start.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5935741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档