为客户机配置响应签名验证方法

使用 WSSVerification 和 WSSVerifyPart API 来选择签署验证方法。请求签署验证方法包括摘要算法和传输方法。

开始之前

要完成对签名验证信息的配置以保护 SOAP 消息,必须执行下列算法任务:
  • 使用 WSSVerification API 来配置规范方法和签名方法。
  • 使用 WSSVerifyPart API 来配置摘要方法和变换方法。
配置算法方法以便在配置客户机进行请求签署时使用。

关于此任务

下表描述了此信息的用途。这些定义中的一些基于 XML 签名规范,此规范位于以下 Web 站点 http://www.w3.org/TR/xmldsig-core

表 1. 签署验证方法. 使用签名验证信息来保护消息。
方法名称 用途
摘要算法 应用转换后(如果指定的话)应用到数据,以生成 <DigestValue> 元素。<DigestValue> 元素的签署将资源内容绑定到签署者密钥。为客户机请求发送方配置选择的算法必须与在客户机请求接收方配置中选择的算法匹配。
变换算法 应用于 <Transform> 元素。
签名算法 指定签名验证方法的统一资源标识 (URI)。
规范化算法 指定规范方法的统一资源标识 (URI)。

配置客户机以便对消息进行数字签署后,必须配置客户机以验证数字签名。可以使用 WSS API 或通过管理控制台配置策略集来验证数字签名以及选择验证和验证部件算法。如果使用 WSS API 来配置,请使用 WSSVerification 和 WSSVerifyPart API 来指定配置客户机进行请求签署时要验证的数字签署消息部件及要使用的算法方法。

WSSVerification 和 WSSVerifyPart API 执行以下步骤以配置签名验证和验证部件算法方法:

过程

  1. 对于使用者绑定,WSSVerification API 指定签名方法以允许签名验证。 WebSphere® Application Server 支持以下预配置的签名方法:
    • WSSVerification.RSA_SHA1(缺省值):http://www.w3.org/2000/09/xmldsig#rsa-sha1
    • WSSVerification.HMAC_SHA1:http://www.w3.org/2000/09/xmldsig#hmac-sha1
    不支持 DSA-SHA1 数字签名方法 (http://www.w3.org/2000/09/xmldsig#dsa-sha1)。
  2. 对于使用者绑定,WSSVerification API 指定规范方法以允许签名验证。 WebSphere Application Server 缺省情况下支持以下预配置的规范方法:
    • WSSVerification.EXC_C14N(缺省值):http://www.w3.org/2001/10/xml-exc-c14n#
    • WSSVerification.C14N:http://www.w3.org/2001/10/xml-c14n#
  3. 对于使用者绑定,WSSVerifyPart API 根据需要指定摘要方法。 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
  4. 对于使用者绑定,WSSVerifyPart API 指定变换方法。 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
    • 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

    对于 WSS API,WebSphere Application Server 不支持以下算法:

    • http://www.w3.org/2002/07/decrypt#XML
    • http://www.w3.org/TR/1999/REC-xpath-19991116

结果

指定了在验证数字签名及客户机发送消息时要使用的方法。

示例

以下示例提供了样本 WSS API 代码,这段代码指定了验证信息:将主体指定为要验证的部件、将 HMAC_SHA1 指定为签名方法、将 C14N 和 EXC_C14N 指定为规范方法的候选值、将 TRANSFORM_STRT10 指定为变换方法以及将 SHA256 指定为摘要方法。

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

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

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

// Generate the certificate list
   String certpath = "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 the 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 the callback handler
   X509ConsumeCallbackHandler callbackHandler = new
      X509ConsumeCallbackHandler(
                                 "dsig-receiver.ks", 
                                 "jks",
                                 "server".toCharArray(), 
                                 certList, 
                                 java.security.Security.getProvider(
                                       "IBMCertPath")
                                 );

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

// Set one or more candidates of the signature method used for 
//    verification (step. 1)
// DEFAULT : WSSVerification.RSA_SHA1
      ver.addAllowedSignatureMethod(WSSVerification.HMAC_SHA1);

// Set one or more candidates of the canonicalization method used for 
//    verification (step. 2)
// DEFAULT : WSSVerification.EXC_C14N 
      ver.addAllowedCanonicalizationMethod(WSSVerification.C14N);
      ver.addAllowedCanonicalizationMethod(WSSVerification.EXC_C14N);

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

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

// Set the candidates of digest methods to use for verification (step. 3)
// DEFAULT : WSSVerifypart.TRANSFORM_EXC_C14N : String
      verPart.addAllowedTransform(WSSVerifyPart.TRANSFORM_STRT10);

// Set the candidates of digest methods to use for verification (step. 4)
// DEFAULT : WSSVerifyPart.SHA1
      verPart.addAllowedDigestMethod(WSSVerifyPart.SHA256);

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

// Add the WSSVerification to the WSSConsumingContext
   concont.add(ver);

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

下一步做什么

您完成了配置签名验证算法。接下来,配置加密或解密算法(如果尚未配置)。或者,根据需要配置安全性令牌信息。


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



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