0

我正在编写一个必须调用使用 WS-Security 的 .NET Web 服务的 JAXWS-RI 客户端。服务的 WSDL 不包含任何 WS-Security 信息,但我有一个来自服务作者的示例 soap 消息,并且知道我必须包含 wsse:Security 标头,包括 X:509 令牌。

我一直在研究,我看到人们从 Axis 和 CXF(与 Rampart 和/或 WSS4J 一起)调用这种类型的 Web 服务的例子,但没有使用普通的 JAXWS-RI 本身。但是,我(不幸地)受制于我的政府客户使用 JAXWS-RI。有没有人有任何来自 JAXWS-RI 的示例/文档?

我最终需要生成一个类似于下面的 SOAP 标头 - 这是一个示例 soap:header,来自服务作者编写的 .NET 客户端。(注意:我已将“VALUE_HERE”字符串放在需要提供自己的值的地方)

<soapenv:Envelope xmlns:iri="http://EOIR/IRIES" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
  <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401- wss-wssecurity-secext-1.0.xsd">
     <xenc:EncryptedKey Id="VALUE_HERE">
       <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
       <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference>
             <wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">
             VALUE_HERE
            </wsse:KeyIdentifier>
         </wsse:SecurityTokenReference>
       </ds:KeyInfo>
       <xenc:CipherData>
          <xenc:CipherValue>VALUE_HERE</xenc:CipherValue>
       </xenc:CipherData>
       <xenc:ReferenceList>
         <xenc:DataReference URI="#EncDataId-8"/>
       </xenc:ReferenceList>
    </xenc:EncryptedKey>
  </wsse:Security>
4

3 回答 3

1

尝试使用

com.sun.xml.ws.api.security.CallbackHandlerFeature

使用自定义实现

javax.security.auth.callback.CallbackHandler

接受一个

java.security.PrivateKey

java.security.cert.X509Certificate

您从类路径上的资源加载。我刚刚在这里写了一篇博客:http: //upthescala.blogspot.com/2010/03/essential-sources-for-jax-ws-x509.html

有关配置端口的示例(包括从文件加载私钥和 X.509 证书),请参阅 com.sun.xml.ws.commons.EC2(在上述博客条目中链接的源下载中)。

我会发布更多代码,但我没有我的开发盒,所以我无法真正测试。

祝你好运!

于 2010-03-03T03:10:11.980 回答
1

经过一段时间的努力,我们这里的开发团队已经确定我们无法做到这一点。我们根本无法编写一个 Metro(JAXWS-RI+WSIT) 客户端来正确调用和处理来自使用 WS-Security 的 .NET WSE 3.0 Web 服务的响应。不过,我想写下我们不同的方法,以供将来可能尝试类似方法的人使用。

回顾一下: 1. 我们的第一道关卡:具有 MutualCerticates11 安全性的 WSE 3.0 Web 服务(WS-Addressing、加密、签名、安全对话 (ws-trust))。我们逆向设计了一个 WS-Policy 片段以放置在 WSDL 的本地副本中以处理此问题,但无法让安全对话初始握手请求被 WSE 接受。

  1. 接下来,他们降级到 WSE 3.0 MutualCerticates10,因为有人说它“更具互操作性”。同样,我们无法让安全对话握手工作。

  2. 我们要求 .NET 团队关闭 SecureConversation (WS-Trust) 层(仍然存在加密和签名要求)。同样,我们对 WS-Policy 文件进行了逆向工程(本质上,只是删除了处理 WS-Trust/SC 的“BootstrapPolicy”部分)。此时,我们能够向他们发送加密、签名的消息,他们收到并发回消息。我们认为这是一场胜利,但不幸的是,WSIT 因规范化错误而对他们的响应消息感到窒息。在这一点上,我认为我们遇到了 WSIT 的限制,因为它没有声称与 WSE 3.0(仅 WCF)互操作,所以我们在他们的论坛上与 WSIT 人员进行了交谈并记录了他们的问题。这是那个链接

  3. 因此,我们得出结论,.NET 团队不可能保留加密/签名层(目前,无论如何 - WSIT 团队可能会在某个时候修复该错误)。不幸的是,从他们的角度来看,您不能只关闭签名并留下加密。

  4. 我们还要求他们完全关闭他们 (.NET) 端的 WS-Security 设置,此时,他们能够使用 JAXWS-RI 从他们的服务发送请求和接收响应就好了。但是,他们可能无法在生产中以这种方式部署。

  5. 因此,现在我们处于 .NET 团队必须确定是否允许他们在没有 WS-Security 设置的情况下在生产环境中运行 Web 服务的阶段。如果没有,那么在他们升级到 WCF 之前,我们将无法连接到他们的服务。而且,事实上,这一直是我们对他们的建议——他们升级到 WCF——现在我们比我们想知道的原因更熟悉了!

于 2010-05-18T21:30:19.480 回答
0

我仍在努力解决一些问题,试图解决这个问题,但我想更新我已经确定的方法的一些细节。我意识到的第一件事是我必须从使用 JAXWS-RI 2.1 升级到 Metro 2.0。我们以前在这个项目中使用过 JAXWSRI-2.1,但我们以前从未处理过任何 WS-Security。无论如何,我意识到我需要升级,所以我这样做是为了利用 Metro 2.0 和其中包含的 WSIT jar。然后,我仍然对如何在没有来自服务的 WSDL 文件的 WS-Policy 信息的情况下生成我需要的 WS-Security 标头感到困惑。我曾尝试使用 LES2 建议的 API 设置 CallbackHandlerFeature,但这并没有为我生成标头。所以,我在 java 的 Metro/JAXB 板上发布了一个问题。

http://forums.java.net/jive/message.jspa?messageID=392451#392451

在对此的回复中,一位回答者建议使用 NetBeans 编写一个虚拟 Web 服务并设置我认为 .NET 服务正在使用的安全设置。一旦我这样做了,NetBeans 就会在 wsit-.xml 文件中生成一个我可以使用的 WS-Policy 部分。我将该 WS-Policy 部分插入到 .NET 服务的 WSDL 的本地副本中,并使用它来创建一个 wsit-client.xml 文件,该文件放在我的 WEB-INF/classes 目录中。

一旦我这样做了,Metro/WSIT 就开始添加 WS-Security 标头来为我请求。然后我遇到了一些问题,因为 Metro 使用的 WS-Addressing 版本与 .NET 服务所需的版本不同(它们使用 MemberSubmissionAddressing)。所以,我最终调整了我的 WS-Policy 设置以使用

<wsap:UsingAddressing                   xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" />

现在,我的 SOAP 请求如下所示:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
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" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:exc14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<S:Header>
<To xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" wsu:Id="_5003">https://10.49.38.78/2009/12/CaseDetailsService.asmx</To>
<Action xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" wsu:Id="_5004">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT</Action>
<ReplyTo xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" wsu:Id="_5002">
    <Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</Address>
</ReplyTo>
<MessageID xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" wsu:Id="_5005">uuid:89a0dfdf-014c-4be7-a677-ab1b4d30cdb5</MessageID>
<wsse:Security S:mustUnderstand="1">
  <wsu:Timestamp xmlns:ns10="http://www.w3.org/2003/05/soap-envelope" 
       xmlns:ns11="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns12="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" wsu:Id="_3">
       <wsu:Created>2010-03-22T19:48:04Z</wsu:Created>
       <wsu:Expires>2010-03-22T19:53:04Z</wsu:Expires> 
    </wsu:Timestamp>
    <wsse:BinarySecurityToken xmlns:ns10="http://www.w3.org/2003/05/soap-envelope" 
    xmlns:ns11="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" 
    xmlns:ns12="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" 
    wsu:Id="uuid_e861f15d-dd66-4b05-b101-c9fed7feda38" 
    EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">DATA_HERE
</wsse:BinarySecurityToken>
<xenc:EncryptedKey xmlns:ns10="http://www.w3.org/2003/05/soap-envelope" xmlns:ns11="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns12="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" Id="_5007">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
<ds:KeyInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="KeyInfoType">
<wsse:SecurityTokenReference>
<ds:X509Data>
<ds:X509IssuerSerial>
<ds:X509IssuerName>CN=server</ds:X509IssuerName>
<ds:X509SerialNumber>-24583240032357195994117623470001087391</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue></xenc:CipherValue>
</xenc:CipherData>
<xenc:ReferenceList>
<xenc:DataReference URI="#_5008"/>
</xenc:ReferenceList>
</xenc:EncryptedKey>
<ds:Signature xmlns:ns10="http://www.w3.org/2003/05/soap-envelope" 
xmlns:ns11="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns12="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" Id="_1">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<exc14n:InclusiveNamespaces PrefixList="wsse S"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#_5002">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<exc14n:InclusiveNamespaces PrefixList="S"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>vtf9n+OcI1nT0exavD4/ZQy6jm8=</ds:DigestValue></ds:Reference>
<ds:Reference URI="#_5003">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><exc14n:InclusiveNamespaces PrefixList="S"/></ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>
</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#_5004"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<exc14n:InclusiveNamespaces PrefixList="S"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue></ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#_5005"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><exc14n:InclusiveNamespaces PrefixList="S"/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>hn2umVvzokVW6dgXUzXcG00vfq8=</ds:DigestValue>
</ds:Reference><ds:Reference URI="#_5006"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><exc14n:InclusiveNamespaces PrefixList="S"/>
</ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>MIH/94A7R2iHn/und3ElJLRTWKY=</ds:DigestValue>
</ds:Reference><ds:Reference URI="#_3"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<exc14n:InclusiveNamespaces PrefixList="wsu wsse S"/></ds:Transform></ds:Transforms>
<ds:DigestMethodAlgorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>olcbTjCNnXuZ5eVR1glEWRJxQpw=</ds:DigestValue>
</ds:Reference></ds:SignedInfo><ds:SignatureValue>
</ds:SignatureValue><ds:KeyInfo>
<wsse:SecurityTokenReference><wsse:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#uuid_e861f15d-dd66-4b05-b101-c9fed7feda38"/>
</wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature>
</wsse:Security>
</S:Header>

而且,虽然这与 .NET 团队给我的示例不完全匹配,但我认为它是正确的。但是,当我调用 .NET 服务时,我仍然收到错误消息。这是他们在 SOAPFault 中返回的错误消息:

System.Web.Services.Protocols.SoapHeaderException:服务器不可用,请稍后再试---> System.ApplicationException:WSE841:处理传出故障响应时发生错误。---> System.Web.Services.Protocols.SoapHeaderException: Microsoft.Web.Services3.Security.SecurityFault: 无法对安全令牌进行身份验证或授权 ---> System.Security.SecurityException: WSE3003: 证书的信任链可以不被验证。请检查证书是否已正确安装在受信任的人证书存储中。或者,如果这是一个测试证书,您可能希望将 allowTestRoot 配置部分设置为 true。

因此,我目前正在与他们合作,以找出为什么无法验证证书的信任链 - 我不清楚该特定问题是我的问题还是他们的问题。任何建议,将不胜感激!

于 2010-03-23T15:23:33.973 回答