【问题标题】:MessageSecurityException: The security header element 'Timestamp' with the '' id must be signedMessageSecurityException:必须对具有“”标识的安全标头元素“时间戳”进行签名
【发布时间】:2010-06-18 09:40:43
【问题描述】:

我在这里问的问题与我已经在 msdn 论坛 http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/70f40a4c-8399-4629-9bfc-146524334daf987654321@ 上问过的问题相同

我正在使用一个(很可能是基于 Java 的)Web 服务,但我完全没有修改权限。即使我会问他们也不会修改(这是一个全国性的系统)。

我已经用 WCF 编写了客户端。这是一些代码:

CustomBinding binding = new CustomBinding();
AsymmetricSecurityBindingElement element = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
element.AllowSerializedSigningTokenOnReply = true;
element.SetKeyDerivation(false);
element.IncludeTimestamp = true;
element.KeyEntropyMode = SecurityKeyEntropyMode.ClientEntropy;
element.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.SignBeforeEncrypt;
element.LocalClientSettings.IdentityVerifier = new CustomIdentityVerifier();
element.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
element.IncludeTimestamp = false;

binding.Elements.Add(element);
binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
binding.Elements.Add(new HttpsTransportBindingElement());

EndpointAddress address = new EndpointAddress(new Uri("url"));

ChannelFactory<MyPortTypeChannel> factory = new ChannelFactory<MyPortTypeChannel>(binding, address);

ClientCredentials credentials = factory.Endpoint.Behaviors.Find<ClientCredentials>();

credentials.ClientCertificate.Certificate = myClientCert;
credentials.ServiceCertificate.DefaultCertificate = myServiceCert;
credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;

service = factory.CreateChannel();

在此之后,对服务的每个请求都在客户端失败(我可以确认我的请求已被服务接受并且正在返回一个理智的响应)

我总是遇到以下异常

MessageSecurityException:安全性 带有 '' 的标头元素 'Timestamp' id 必须签名。

通过查看跟踪,我可以看到在响应中确实有一个时间戳元素,但在安全部分中只有一个正文的签名。

我可以让 WCF 忽略时间戳未签名的事实吗?

【问题讨论】:

    标签: c# wcf wcf-client


    【解决方案1】:

    您可以尝试使用 WCF 消息协定。当你有一个消息合约时,你可以指定标题中的项目应该被签名:

    [MessageContract]
    public class CustomType
    {
    [MessageHeader(ProtectionLevel = ProtectionLevel.Sign)]
    string name;
    
    [MessageHeader(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
    string secret;
    

    【讨论】:

    • 这可能只是为了解决问题。现在我只是在语法上苦苦挣扎。 xml 如下所示: docs.oasis-open.org/wss/2004/01/…"> 2010-06-21T06:53:57Z2010-06-21T06 :58:57Z 不知道怎么在自定义类型中定义这个。
    【解决方案2】:

    我已经解决了这个问题,答案可以在这里找到: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/371184de-5c05-4c70-8899-13536d8f5d16

    要点:在自定义绑定中添加一个自定义的 StrippingChannel 以从 securityheader 中剥离时间戳,并将 WCF 配置为不检测回复。

    【讨论】:

      猜你喜欢
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-27
      • 2013-08-07
      • 2020-07-07
      • 1970-01-01
      相关资源
      最近更新 更多