我正在构建一个带有customBinding端点的WCF Web服务,并且受到另一方正在发送给我的WS-Security标头卡住。我们都遵循英国国家卫生局制定的规范,所以我无法修改这些要求。在WCF中接受UsernameToken和BinarySecurityToken customBinding
的<wsse:Security>
头的基本结构应该如下,根据本说明书中:
<wsse:Security>
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurityutility-1.0.xsd" wsu:Id="6CCF6A2B-11A6-11DF-86D1-236A99759561" >
<wsu:Created>2012-06-12T09:00:00Z</wsu:Created>
<wsu:Expires>2012-06-12T09:15:00Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken>
<wsse:Username>SomeUsername</wsse:Username>
</wsse:UsernameToken>
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsssoap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-
200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="30b91ede-35c2-11df-aac9-97f155153931 ">xxx...</wsse:BinarySecurityToken>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#RSA-SHA1" />
<Reference URI="#6CCF6A2B-11A6-11DF-86D1-236A99759561" />
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>xxx...</DigestValue>
</SignedInfo>
<SignatureValue>xxx...</SignatureValue>
<KeyInfo>
<wsse:SecurityTokenReference>
<wsse:Reference URI="#30b91ede-35c2-11df-aac9-97f155153931 "/>
</wsse:SecurityTokenReference>
</KeyInfo>
</Signature>
</wsse:Security>
在我的web服务,我已经尝试使用下面的结合:
<customBinding>
<binding name="wsHttpSoap11" >
<textMessageEncoding messageVersion="Soap11WSAddressingAugust2004" />
<security authenticationMode="MutualCertificate">
</security>
<httpTransport/>
</binding>
</customBinding>
(该我使用customBinding的原因是我必须支持WS-Addressing和WS-Security over SOAP 1。 1,并从this answer了咨询)
如果我运行通过提琴手样品的要求,我得到我的WCF跟踪以下错误:
Cannot find a token authenticator for the 'System.IdentityModel.Tokens.UserNameSecurityToken' token type. Tokens of that type cannot be accepted according to current security settings.
我相信这是因为它无法验证<UsernameToken>
。如果我更改绑定的安全性:
<security authenticationMode="UserNameForCertificate">
然后我得到这个错误:
Cannot find a token authenticator for the 'System.IdentityModel.Tokens.X509SecurityToken' token type. Tokens of that type cannot be accepted according to current security settings.
我相信这是因为它现在还无法验证<BinarySecurityToken>
!
的问题,因此,是:
- 都是我的假设是否正确有关错误信息 (即它只能处理在当前的配置中的一个令牌)的原因是什么?
- 如何将其配置为接受这两个令牌?
更新
感谢@Yaron我现在已经添加了一个自定义绑定扩展和两个UserNameSecurityToken和X509SecurityToken被验证。
但是,它现在在验证XML签名的阶段失败。在HTTP响应返回的例外是:
Message security verification failed.
如果我深入挖掘服务跟踪查看器堆栈跟踪,我看到:
System.Security.Cryptography.CryptographicException...
The signature verification failed.
at System.IdentityModel.SignedXml.VerifySignature(HashAlgorithm hash, AsymmetricSignatureDeformatter deformatter) at System.IdentityModel.SignedXml.StartSignatureVerification(SecurityKey verificationKey)...
谁能帮助我弄清楚为什么发生这种情况?我现在有点迷路了。我尝试使用some sample code尝试手动验证签名,但它表示签名无效。在回到供应商之前,我怎么能确定它是否是?这是应该工作吗?我们应该在线路上分享一些证书吗?
非常感谢您的回答 - 当我明天回到办公室时,我会试试这个。我在我的问题中提到我正在使用SOAP 1.1,是否对您的示例代码有任何影响? –
不影响,但如果我们处理也使用这可能会有影响。如果您有任何问题,请发布完整的肥皂或发送给我 –
请查看我的更新,希望得到任何进一步的建议。很高兴向您发送完整的请求,如果它有用。 –