如何修复HTTPS Silverlight应用程序上下文中的WCF maxClockSkew问题?

如何修复HTTPS Silverlight应用程序上下文中的WCF maxClockSkew问题?,第1张

概述情况:Silverlight 4应用程序通过WCF与服务器组件通信,使用basicHttpBinding和HTTPS. 这是绑定使用的服务器端: <basicHttpBinding><binding name="DefaultSecuredBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"> 情况:Silverlight 4应用程序通过WCF与服务器组件通信,使用basichttpBinding和httpS.

这是绑定使用的服务器端:

<basichttpBinding><binding name="DefaultSecuredBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">      <readerQuotas maxDepth="50" maxArrayLength="2147483647" maxStringContentLength="2147483647" />      <security mode="TransportWithMessageCredential">        <message clIEntCredentialType="Username"/>        <transport clIEntCredentialType="None" proxyCredentialType="None"/>      </security>    </binding></basichttpBinding>

请注意,我们使用TransportWithMessageCredential作为安全模式.
证书已在IIS上正确安装.

应用程序在本地运行时运行顺畅

但是,我们现在有外部用户连接到我们的应用程序.
他们中的一些人遇到了困难,并查看服务器日志,我们发现了这个错误:

“MessageSecurityException”
安全时间戳是陈旧的,因为其过期时间(‘2010-10-18T22:37:58.198Z’)已过去.当前时间是’2010-10-18T22:43:18.850Z’并允许时钟偏差是’00:05:00′.

我们对网络上的主题(StackoverFlow& Google ……和Bing)进行了常规研究,以阅读有关该主题的更多信息.
我们联系了用户,以确保他们与我们的服务器的时间偏移,后来得到确认.

这篇MSDN文章的开头是:
http://msdn.microsoft.com/en-us/library/aa738468.aspx

在现有绑定上使用CustomBinding,并在自定义绑定的SecurityBindingElement上设置MaxClockSkew属性.
我们实现了这个解决方案,将SymmetricSecurityBindingElement更改为TransportSecurityBindingElement,因为我们绑定了与Silverlight的安全通信
是使用httpS的basichttpBinding.

Web上的一些文章(包括上面列出的这篇MSDN文章)显示了代码片段,它还将maxClockSkew属性设置为从ProtectionTokenParameters获取的引导元素.
我从未成功在代码中应用此部分,因为TransportSecurityBindingElement似乎没有任何ProtectionTokenParameters.

这是我们用maxClockSkew包装绑定的代码:

protected virtual System.ServiceModel.Channels.Binding WrapClockSkew(System.ServiceModel.Channels.Binding currentBinding)    {        // Set the maximum difference in minutes        int maxDifference = 300;        // Create a custom binding based on an existing binding        CustomBinding myCustomBinding = new CustomBinding(currentBinding);        // Set the maxClockSkew        var security = myCustomBinding.Elements.Find<TransportSecurityBindingElement>();        if (security != null)        {            security.LocalClIEntSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);            security.LocalServiceSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);        }        return myCustomBinding;    }

‘security.LocalClIEntSettings’在这里可能没用,因为这段代码是服务器端的.

这段代码没有做到这一点,当我们与服务器的差异超过5分钟时,我们仍然在服务器上有相同的错误消息.
我仍然记得我们没有应用MSDN代码片段的引导技巧..所以我们继续我们关于该主题的网络搜索.

我们发现了一个整洁的wcf行为,我们认为,这将解决我们的问题.

看起来它处理bootstrap绑定问题!

以下是在TransportSecurityBindingElement的上下文中搜索令牌参数的部分:

//If the securityBindingElement's type is TransportSecurityBindingElementif (securityBindingElement is TransportSecurityBindingElement){foreach (SecurityTokenParameters securityTokenParameters in     securityBindingElement.EndpointSupportingTokenParameters.Endorsing){    //Gets it from the EndpointSupportingTokenParameters.Endorsing property    if (securityTokenParameters is SecureConversationSecurityTokenParameters)    {        secureConversationSecurityTokenParameters =            securityTokenParameters as SecureConversationSecurityTokenParameters;        break;    }}}

请注意’securityBindingElement.EndpointSupportingTokenParameters.Endorsing’…
在我们的情况下(basichttpBinding,TransportWithMessageCredential,https …),这个集合是空的!

因此,无法检索securityTokenParameters,因此无法设置maxClockSkew.

问题:

>我们的绑定在SL WCF httpS上下文中是否不正确?
>找不到任何方法在TransportSecurityBindingElement中的bootstrap元素上设置maxClockSkew是否正常?
>我们是唯一一家与客户进行httpS Silverlight应用程序的公司,可能不是在同一时间(偏差为5分钟)吗?
>为什么修复这种简单的配置似乎是一次冒险?

任何帮助,将不胜感激!

解决方法 以下代码段允许您在TransportSecurityBindingElement上设置maxClockSkew.我的解决方案是在http和https上下文中运行的Outlook加载项WCF,因此尽管与您的上下文不同,但它的相似之处.

>你的绑定对我来说是正确的.
>这是代码片段

WShttpBinding wsSecureBinding = new WShttpBinding(SecurityMode.TransportWithMessageCredential,false);wsSecureBinding.Security.Message.ClIEntCredentialType = MessageCredentialType.Username;wsSecureBinding.Security.Message.EstablishSecurityContext = true;wsSecureBinding.Security.Message.NegotiateServiceCredential = true;wsSecureBinding.Security.Transport.ClIEntCredentialType = httpClIEntCredentialType.Certificate;wsSecureBinding.ReaderQuotas.MaxStringContentLength = 500000;wsSecureBinding.ReceiveTimeout =wsSecureBinding.SendTimeout = new TimeSpan(0,5,0);CustomBinding secureCustomBinding = new CustomBinding(wsSecureBinding);TimeSpan clockSkew = new TimeSpan(0,15,0);TransportSecurityBindingElement tsecurity = secureCustomBinding.Elements.Find();SecureConversationSecurityTokenParameters securetokenParams = (SecureConversationSecurityTokenParameters)tsecurity.EndpointSupportingTokenParameters.Endorsing.OfType().FirstOrDefault();if (securetokenParams != null){    SecurityBindingElement bootstrap = securetokenParams.bootstrapSecurityBindingElement;    // Set the MaxClockSkew on the bootstrap element.    bootstrap.LocalClIEntSettings.MaxClockSkew = clockSkew;    bootstrap.LocalServiceSettings.MaxClockSkew = clockSkew;}

>时钟偏差仅在您使用Username客户端凭据时很重要,而某些用户要么计算机时钟不正确,要么他们不在乎>是的,WCF配置总是一个你不想做的冒险.

总结

以上是内存溢出为你收集整理的如何修复HTTPS Silverlight应用程序上下文中的WCF maxClockSkew问题?全部内容,希望文章能够帮你解决如何修复HTTPS Silverlight应用程序上下文中的WCF maxClockSkew问题?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1000925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存