gpt4 book ai didi

c# - Lumesse Web 服务和 WSSE 纯文本安全问题

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:08 24 4
gpt4 key购买 nike

我们目前正在重新开发一个遗留项目,该项目使用 Lumesse 的 SOAP 网络服务,通过 HTTPS 调用。

http://developer.lumesse.com/Getting_Started

这是在 ASP.NET 应用程序中使用的;最初的开发人员(早已离开)从未利用过提供的 WSDL,而是更喜欢手动构造请求并解析响应。虽然这完全是疯狂的做法,但这是 Lumesse 的文档在从 .NET 使用时实际推荐的内容,因为他们的服务使用过时的 WSSE 纯文本安全性。

虽然我们通常不会违背常规,但我们更愿意使用内置支持来使用 SOAP Web 服务,而不是像以前的开发人员那样推出我们自己的解决方案。

我们已经遇到了一些问题,例如无法生成我们已破解的临时类。

不幸的是,我们现在无法发送成功的 SOAP 请求。

我们发起请求时抛出的异常是:

通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为它处于 Faulted 状态。

深挖,实际响应如下:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header />
<env:Body>
<env:Fault xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">wsse:FailedCheck</faultcode>
<faultstring>Expired message.</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>

这似乎是“签名或解密无效”。使用其他开发人员的解决方案,使用相同的凭据按预期工作。

为什么它会在这里失败,我们可以做些什么来修复它?是否可以不借助滚动我们自己的请求和响应(甚至推荐?)服务?

http://schemas.xmlsoap.org/specs/ws-security/ws-security.htm

我们使用的 WSDL,由 Lumesse 提供:

https://api3.lumesse-talenthub.com/CareerPortal/SOAP/FoAdvert?WSDL

我们到达的终点:

https://api3.lumesse-talenthub.com/CareerPortal/SOAP/FoAdvert?api_key=xxx

到目前为止,这是我们的代码,主要基于 With C#, WCF SOAP consumer that uses WSSE plain text authentication? - 这看起来是同一个问题。

Correct way communicate WSSE Usernametoken for SOAP webservice有同样的问题,但答案是我们将绑定(bind)详细信息存储在 web.config 中。

using (LumesseSoapTest.FoAdvert.FoAdvertWebServiceClient client = new LumesseSoapTest.FoAdvert.FoAdvertWebServiceClient())
{
client.ClientCredentials.UserName.UserName = "xxxx";

client.ClientCredentials.UserName.Password = "xxxx";

var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

client.Endpoint.Binding = binding;

var response = client.getAdvertisements(new LumesseSoapTest.FoAdvert.getAdvertisements());
}

Lumesse 期望的示例请求,取自之前开发人员自制解决方案的一部分 - 按预期工作:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.mrted.com/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-11">
<wsse:Username>xxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
xxxx
</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">5Xhsv3Yp2l1xGpL3pNYy6A==
</wsse:Nonce>
<wsu:Created>2012-06-22T09:07:26.631Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<getAdvertisements xmlns="http://ws.mrted.com/">
<firstResult>0</firstResult>
<maxResults>0</maxResults>
</getAdvertisements>
</soapenv:Body>
</soapenv:Envelope>

我们当前发送的示例请求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<ActivityId CorrelationId="d309ce44-ed91-4314-87ee-e3abee4f531e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">dd9a8c26-e673-464d-87e4-5cb8b76989c3</ActivityId>
<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>2014-09-30T16:15:47.426Z</u:Created>
<u:Expires>2014-09-30T16:20:47.426Z</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="uuid-c3275c63-6d98-4ae3-a7a7-afe314d23d6c-3">
<o:Username>xxxx</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxx</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getAdvertisements xmlns="http://ws.mrted.com/">
<firstResult>0</firstResult>
<maxResults>0</maxResults>
</getAdvertisements>
</s:Body>
</s:Envelope>

任何帮助将不胜感激。

更新

是的,使用这个拼凑在一起的 XML,我可以从 API 获得响应。

我只是不知道如何根据我们的请求生成它。再次感谢您的帮助。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="UsernameToken-11">
<o:Username>xxx</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxx
</o:Password>
<o:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">
5Xhsv3Yp2l1xGpL3pNYy6A==
</o:Nonce>
<o:Created>2012-06-22T09:07:26.631Z</o:Created>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getAdvertisements xmlns="http://ws.mrted.com/"><firstResult>0</firstResult><maxResults>10</maxResults>
</getAdvertisements>
</s:Body>
</s:Envelope>

更新 2(开始工作了!)

终于,在大约 9 小时后,我们到达了某个地方。我将把它留给那些不幸使用 Lumesse(或其他类似的 Java Web 服务)的其他人。

我们上面发送的 XML 的主要问题是安全节点下的时间戳节点。它将处理的无关 Nonce 节点,大概是因为它不是 Security 节点下的第一个节点?谁知道呢(这实际上是我第一次以任何形式使用 SOAP/WCF 哈哈!)。

因此,Timestamp 节点需要移除。如果您需要使用像 basicHttpBinding 这样的标准绑定(bind)或 wsHttpBinding,您需要创建自定义绑定(bind)。这是一个模仿 basicHttpBinding 的示例,显然取自 http://www.mikeobrien.net/blog/removing-wss-timestamp-from-wcf/

示例配置:

<customBinding>
<binding name="MyBinding">
<security authenticationMode="UserNameOverTransport" includeTimestamp="false" />
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport maxReceivedMessageSize="26214400" />
</binding>
</customBinding>

然后按原样调用该服务,传递凭据(您可能可以将这些与上面的凭据一起存储在 web.config 中,但如果我知道怎么做,我现在该死的)。

using (LumesseSoapTest.FoAdvert.FoAdvertWebServiceClient client = new LumesseSoapTest.FoAdvert.FoAdvertWebServiceClient())
{
client.ClientCredentials.UserName.UserName = "xxxx";

client.ClientCredentials.UserName.Password = "xxxx";

foreach (var ad in response.advertisementResult.advertisements)
{
@ad.jobTitle <br />
}

再次感谢。

最佳答案

我也在使用相同的 API,但遇到了同样的问题。如果向下滚动到本文底部:http://www.hanselman.com/blog/BreakingAllTheRulesWithWCF.aspx Scott Hanselman 通过代码而不是通过配置删除时间戳。

关于c# - Lumesse Web 服务和 WSSE 纯文本安全问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26126257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com