【问题标题】:WCF service - security in SOAP headerWCF 服务 - SOAP 标头中的安全性
【发布时间】:2011-07-30 10:14:05
【问题描述】:

我正在尝试使用带有 UserNameOverTransport 绑定的 wcf 服务。我希望我的 Soap 标头看起来像这样:

<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> 
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-        
open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-14430313" xmlns:wsu="http://docs.oasis-   
open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
<wsse:Username>USERNAME</wsse:Username> 
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-    token-profile-1.0#PasswordText">PASSWORD</wsse:Password> 
<wsse:Nonce>OquGazmuMMHFrdeRQZGpkA==</wsse:Nonce> 
<wsu:Created>2009-08-25T19:17:07.369Z</wsu:Created> 
</wsse:UsernameToken> 
</wsse:Security>

我的 SOAP 如下所示:

<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-    200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2011-07-  
29T10:38:58.452Z</u:Created><u:Expires>2011-07-
29T10:43:58.452Z</u:Expires></u:Timestamp><o:UsernameToken u:Id="uuid-63332174-a7b4-  
4833-bd2e-32d0c0820f42-1"><o:Username>USERNAME</o:Username><o:Password 
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile- 
1.0#PasswordText">PASSWORD</o:Password></o:UsernameToken></o:Security>

我用过

proxyclient.ClientCredentials.UserName.UserName = "USERNAME" proxyclient.ClientCredentials.UserName.Password = "密码"

要在 SOAP 标头中插入用户名和密码,但我还需要插入 wsse:Nonce 和 wsu:Created,我该怎么做?使用 .ClientCredentials.UserName.UserName 和 ChannelFactory.Credentials.UserName.UserName 有什么区别?

我怎样才能让标签正确,wsse 而不是 o?

我正在使用 VS 2010 和 VB.NET,以及 UserNameOverTransport 绑定。我必须安装 wse 3.0 吗?

我的 app.config 文件如下所示:

<customBinding>
            <binding name="CustomBinding_IIntermediaryInboundExternal">
              <security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" 
                  requireDerivedKeys="true" securityHeaderLayout="Strict" includeTimestamp="true"
                  keyEntropyMode="CombinedEntropy" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
                <localClientSettings cacheCookies="true" detectReplays="false"
                        replayCacheSize="900000" maxClockSkew="00:05:00" maxCookieCachingTime="Infinite"
                        replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00"
                        sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true"
                        timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
                    <localServiceSettings detectReplays="false" issuedCookieLifetime="10:00:00"
                        maxStatefulNegotiations="128" replayCacheSize="900000" maxClockSkew="00:05:00"
                        negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00"
                        sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00"
                        reconnectTransportOnFailure="true" maxPendingSessions="128"
                        maxCachedCookies="1000" timestampValidityDuration="00:05:00" />
                    <secureConversationBootstrap />
                </security>
                <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                    messageVersion="Default" writeEncoding="utf-8">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </textMessageEncoding>
                <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
                    maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                    bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                    keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                    realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                    useDefaultWebProxy="true" />
            </binding>


<endpoint address="https://myendpointadress.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_mysevice"
            contract="myendpoint"
            name="CustomBinding_myendpoint" />

我希望有人可以帮助我!非常感谢!!

【问题讨论】:

  • 命名空间前缀无关。它们都具有相同的命名空间 uri,因此位于相同的命名空间中,无论一个使用 o 前缀而另一个使用 wsse

标签: wcf soap wcf-security


【解决方案1】:

WCF 中的标准 WCF UserNameToken 配置文件实现不使用 NonceCreated = 无法强制 WCF 包含它们。前缀无关紧要,它只是在包装器元素中定义的符号名称,所有正确的 XML 解析实现都应该适用于 wsseo

WCF 之所以不使用NonceCreated 元素是因为这些元素应该与#PasswordDigest 类型一起使用(WCF 不支持)。将它们与 #PasswordText 一起使用没有太大意义。

如果您的服务需要NonceCreated,您必须实现自己的令牌,而不是使用标准 WCF 的用户名实现。 Here is example 构建全新的 UserNameToken 配置文件实现以支持 #PasswordDigest。它还添加了NonceCreated 元素。

【讨论】:

  • 您好,非常感谢您的回复!我想即使我使用 PasswordText,我也必须使用 Nonce 和 Created。我是 WCF 的新手,我认为掌握所有安全知识有点困难。我将我的服务(WSHttpBinding)添加到项目中,当我查看 app.config 文件时,我的服务是 CustomBinding,可以吗?您是否可以给我一个代码示例,说明如何在 SOAP 标头(uname、passw、nonce、created)中获取我需要的所有信息,以及我的 app.config 文件的外观(根据我的app.config 文件现在看起来像我在上一篇文章中向您展示的那样)?
猜你喜欢
  • 2015-08-30
  • 1970-01-01
  • 2010-12-06
  • 2012-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
相关资源
最近更新 更多