使用 WSSVerifyPart API 验证签署部件

要在使用者端保护 SOAP 消息,请使用 Web Service 安全性 API (WSS API) 来配置响应使用者(客户端)的使用者绑定的验证部件信息。可以指定要进行验证的算法方法和要进行验证的 SOAP 消息的部件。使用 WSSVerifyPart API 来更改摘要方法或变换方法。WSSVerifyPart API 是 com.ibm.websphere.wssecurity.wssapi.verification 包的一部分。

开始之前

要使用签名验证信息保护 SOAP 消息,必须完成下列其中一个任务:

  • 使用 WSSVerification API 配置签名验证信息。
  • 根据需要使用 WSSVerifyPart API 配置验证部件。
WSSVerifyPart 用于对验证指定变换方法或摘要方法。使用 WSSVerifyPart API,或者通过管理控制台来配置策略集。

关于此任务

WebSphere® Application Server 使用签名信息,供缺省使用者用于对消息的签署部件进行验证。仅响应使用者(请求者)支持 WSSVerifyPart API。

下表显示了定义数字签名安全性约束(完整性)时的必需验证部件:

表 1. 验证部件信息. 使用验证部件来保护具有签名验证信息的消息。
验证部件信息 描述
keyword 使用下列关键字设置验证部件:
  • BODY
  • ADDRESSING_HEADERS
  • TIMESTAMP

WS-Addressing 头未进行解密,但可以签署和验证。

xpath 使用 XPath 表达式设置验证部件。
header 将由 QName 指定的头设置为必需验证部件。

为了进行签名验证,将执行特定的缺省行为。使用 WSSVerification API 的最简单方法是使用缺省行为(请参阅示例代码)。WSS API 为签名算法、规范算法和验证部件定义了缺省值。

表 2. 验证缺省部件行为. 缺省情况下,已配置验证部分的若干特征。
验证部件决定 缺省行为
要指定的关键字

要进行签署及用于消息保护的不同 SOAP 消息部件。WebSphere Application Server 支持以下关键字:

  • WSSVerification.BODY
  • WSSVerification.ADDRESSING_HEADERS
  • WSSVerification.TIMESTAMP
要使用的变换方法(算法) 添加变换方法。变换算法是在 <Transform> 元素中指定的算法,并指定签名的变换算法。缺省变换方法是 TRANSFORM_EXC_C14N。

WebSphere Application Server 支持以下预先配置的变换算法:

  • WSSVerifyPart.TRANSFORM_EXC_C14N(缺省值):http://www.w3.org/2001/10/xml-exc-c14n#
  • WSSVerifyPart.TRANSFORM_XPATH2_FILTER:http://www.w3.org/2002/06/xmldsig-filter2

    使用此变换方法来确保与基本安全概要文件 (BSP) 的一致性。

  • WSSVerifyPart.TRANSFORM_STRT10:http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform
  • WSSVerifyPart.TRANSFORM_ENVELOPED_SIGNATURE:http://www.w3.org/2000/09/xmldsig#enveloped-signature
要使用的摘要方法(算法) 设置摘要算法方法。在 <SigningInfo> 元素中使用在 <DigestMethod> 元素中指定的摘要方法算法。缺省摘要方法是 SHA1。
WebSphere Application Server 支持以下摘要方法算法:
  • WSSVerifyPart.SHA1:http://www.w3.org/2000/09/xmldsig#sha1
  • WSSVerifyPart.SHA256:http://www.w3.org/2001/04/xmlenc#sha256
  • WSSVerifyPart.SHA512:http://www.w3.org/2001/04/xmlenc#sha512

过程

  1. 要通过使用 WSSVerifyPart API 验证签署的部件,请首先确保安装了应用程序服务器。
  2. 使用 Web Service 安全性 API 对 SOAP 消息中的验证进行验证。 用于验证签名的 WSS API 过程遵循以下过程步骤:
    1. 使用 WSSFactory.getInstance() 获取 WSS API 实现实例。
    2. 根据 WSSFactory 实例创建 WSSConsumingContext 实例。 确保在 JAX-WS 提供程序实现类中调用了 WSSConsumingContext。由于 JAX-WS 编程模型的特征,需要实现 JAX-WS 提供程序并且该提供程序必须调用 WSSConsumingContext 以验证 SOAP 消息签名。
    3. 创建 CallbackHandler 用于验证。
    4. 根据 WSSFactory 实例创建 WSSVerification 对象。
    5. 根据 WSSFactory 实例创建 WSSVerifyPart。
    6. 设置要验证的部件(如果缺省值不合适)。
    7. 设置摘要方法的候选值(如果缺省值不合适)。
    8. 设置变换方法的候选值(如果缺省值不合适)。
    9. 将 WSSVerifyPart 添加至 WSSVerification。
    10. 将 WSSVerification 添加至 WSSConsumingContext。
    11. 使用 SOAPMessageContext 调用 WSSConsumingContext.process()。

结果

您完成了相应的步骤来验证使用者端的签署部件。如果在验证签名信息时存在错误情况,那么将提供 WSSException。如果成功,那么将调用 WSSConsumingContext.process() 并对 SOAP 消息验证 Web Service 安全性。

示例

以下示例提供了 WSSVerification API 过程的样本代码,用于验证 SOAP 消息中的签名信息:

// Get the message context
   Object msgcontext = getMessageContext();

// Generate the WSSFactory instance (step: a)
   WSSFactory factory = WSSFactory.getInstance();		

// Generate the WSSConsumingContext instance (step: b)
   WSSConsumingContext concont = factory.newWSSConsumingContext(); 

// Generate the certificate list
   String certpath = 
   "c:/WebSphere/AppServer/etc/ws-security/samples/intca2.cer";
// The location of the X509 certificate file
   X509Certificate x509cert = null;
      try {          
          InputStream is = new FileInputStream(certpath);
          		  CertificateFactory cf = CertificateFactory.getInstance("X.509");
          x509cert = (X509Certificate)cf.generateCertificate(is);
      } catch(FileNotFoundException e1){
            		  throw new WSSException(e1);
      } catch (CertificateException e2) {
            throw new WSSException(e2);
      }

      Set<Object> eeCerts = new HashSet<Object>();
      eeCerts.add(x509cert);  
// create certStore
      java.util.List<CertStore> certList = new 
          java.util.ArrayList<CertStore>();
      CollectionCertStoreParameters certparam = new 
          CollectionCertStoreParameters(eeCerts);
      CertStore cert = null;
      try {          
	        	        cert = CertStore.getInstance("Collection", 
              certparam, "IBMCertPath");
      } catch (NoSuchProviderException e1) {
           		  throw new WSSException(e1);
      } catch (InvalidAlgorithmParameterException e2) {
           throw new WSSException(e2);
      } catch (NoSuchAlgorithmException e3) {
           throw new WSSException (e3);
      }
      if(certList != null ){
      certList.add(cert);
      }

// generate callback handler (step: c)  
   X509ConsumeCallbackHandler callbackHandler = new
       X509ConsumeCallbackHandler(
                                  "dsig-receiver.ks", 
                                  "jks",
                                  "server".toCharArray(), 
                                  certList, 
       java.security.Security.getProvider("IBMCertPath")
);

// Generate the WSSVerification instance (step: d)
   WSSVerification ver = factory.newWSSVerification(X509Token.class, 
       callbackHandler);

// Set the part to be specified by WSSVerifyPart (step: e)
   WSSVerifyPart verPart = factory.newWSSVerifyPart();

// Set the part to be specified by the keyword (step: f)
   verPart.setRequiredVerifyPart(WSSVerification.BODY);

// Set the candidates for the digest method for verification (step: g)
// DEFAULT : WSSVerifyPart.SHA1
   verPart.addAllowedDigestMethod(WSSVerifyPart.SHA256);

// Set the candidates for the transform method for verification (step: h)
// DEFAULT : WSSVerifypart.TRANSFORM_EXC_C14N : String
   verPart.addAllowedTransform(WSSVerifyPart.TRANSFORM_STRT10);

// Set WSSVerifyPart to WSSVerification (step: i)
   ver.addRequiredVerifyPart(verPart);

// Add WSSVerification to WSSConsumingContext (step: j)
   concont.add(ver);

//Validate the WS-Security header (step: k)
concont.process(msgcontext);

下一步做什么

您完成了对要验证的签署部件的配置。

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_confsignaturepartcon
文件名:twbs_confsignaturepartcon.html