【问题标题】:How can I configure WCF to only sign the TimeStamp header如何将 WCF 配置为仅签署 TimeStamp 标头
【发布时间】:2011-05-09 10:43:30
【问题描述】:

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

安全要求是消息包含用户名令牌、时间戳,并且时间戳使用包含的 BinarySecurityToken 进行签名。

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

            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 地址和时间戳地址正在被签名。

有没有办法准确指定哪些 WCF 标头已签名?因为我需要限制客户端只签署 TimeStamp 标头。

【问题讨论】:

标签: c# .net wcf ws-security ws-i


【解决方案1】:

使用自定义邮件标题,您可以这样做:

//... rest of MessageContract

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

//... rest of MessageContract

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

【讨论】:

  • 我无法使用 ProtectionLevel 设置,因为我正在尝试签署以下链接 msdn.microsoft.com/en-us/library/aa347692.aspx#Y1432.How 中提到的基础设施数据的时间戳
  • 请查看答案中的 IClientMessageInspector 链接。它显示了如何在将soap 消息发送到服务之前对其进行修改。您可以访问 BeforeSendRequest 方法中的所有soap 标头。您只需要弄清楚如何对 wsa:To 标题项进行数字签名并覆盖肥皂消息中的现有项(尽管这可能是困难的部分)。
  • 我遇到的问题是,当我要求只对 wsu:TimeStamp 进行签名时,WCF 绑定会同时对 wsa:To 和 wsu:TimeStamp 进行签名。我可以手动操作消息以替换现有签名,但我想尽量减少我们对 SOAP 消息执行的自定义操作量。我设法通过将 messageVersion 指定为 Soap11 而不是 Soap11WSAddressing10 然后手动添加 WS-Addresing 标头来完成此操作,从而避免了手动实现签名机制的需要。
  • 这是一个有趣的方法。我没想过要玩消息版本控制。你应该回答你自己的问题以获得你的工作的荣誉。
【解决方案2】:

我知道这是一个老问题,但我已经被问过几次了。

我设法通过将 messageVersion 指定为 Soap11 而不是 Soap11WSAddressing10 然后手动添加 WS-Addresing 标头来实现这一点,从而避免了手动实现签名机制的需要。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 2011-01-27
    • 1970-01-01
    相关资源
    最近更新 更多