为客户机配置请求签名方法

使用 WSSSignature 和 WSSSignPart API 来选择签署方法。请求签署方法包括签名、规范、摘要和变换方法。

开始之前

首先,应该指定了必须使用 WSS API 或者通过管理控制台配置策略集对哪些由客户机发送的消息部件进行数字签署。

关于此任务

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

表 1. 签署方法. 使用签名方法来保护消息。
方法名称 描述
规范化算法 在将信息摘要为签名操作部分前,规范 <SignedInfo> 元素。
签名算法 计算规范 <SignedInfo> 元素的签名值。为客户机请求发送方配置选择的算法必须与在服务器请求接收方配置中选择的算法匹配。
变换方法 在执行签名操作过程中将信息处理为摘要时,对要签署的部件进行变换。
摘要方法 计算已变换部件的摘要值。为客户机请求发送方配置选择的算法必须与在服务器请求接收方配置中选择的算法匹配。

可以使用 WSS API,或者通过管理控制台配置策略集来配置签署算法方法。如果使用的是 WSS API,请使用 WSSSignature 和 WSSSignPart API 来指定配置客户机进行请求签署时要进行数字签署的消息部件。

WSSSignature 和 WSSSignPart API 完成以下步骤来配置签名和签署部件算法方法:

过程

  1. 对于生成器绑定,WSSSignature API 指定签名方法。 WebSphere® Application Server 支持以下预配置的签名方法:
    • WSSSignature.RSA_SHA1(缺省值):http://www.w3.org/2000/09/xmldsig#rsa-sha1
    • WSSSignature.HMAC_SHA1:http://www.w3.org/2000/09/xmldsig#hmac-sha1
    对于 WSS API,WebSphere Application Server 不支持 DSA-SHA1 数字签名方法 http://www.w3.org/2000/09/xmldsig#dsa-sha1。
  2. 对于生成器绑定,WSSSignature API 指定规范方法。 WebSphere Application Server 支持以下预配置的规范算法:
    • WSSSignature.EXC_C14N(缺省值):排斥规范算法 http://www.w3.org/2001/10/xml-exc-c14n#
    • WSSSignature.C14N:包含规范算法 http://www.w3.org/2001/10/xml-c14n#
  3. 对于生成器绑定,WSSSignPart API 指定摘要方法。 WebSphere Application Server 支持以下预配置的摘要方法:
    • WSSSignPart.SHA1(缺省值):http://www.w3.org/2000/09/xmldsig#sha1
    • WSSSignPart.SHA256:http://www.w3.org/2001/04/xmlenc#sha256
    • WSSSignPart.SHA512:http://www.w3.org/2001/04/xmlenc#sha512
  4. 对于生成器绑定,WSSSignPart API 指定变换方法。 WebSphere Application Server 支持以下预先配置的变换算法:
    • WSSSignPart.TRANSFORM_EXC_C14N(缺省值):http://www.w3.org/2001/10/xml-exc-c14n#
    • WSSSignPart.TRANSFORM_XPATH2_FILTER:http://www.w3.org/2002/06/xmldsig-filter2
    • WSSSignPart.TRANSFORM_STRT10:http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform
    • WSSSignPart.TRANSFORM_ENVELOPED_SIGNATURE:http://www.w3.org/2000/09/xmldsig#enveloped-signature
    对于 WSS API,WebSphere Application Server 不支持下列变换算法:
    • http://www.w3.org/TR/1999/REC-xpath-19991116
    • http://www.w3.org/2002/07/decrypt#XML

结果

通过 WSS API 指定了客户机将消息发送至服务器时用于对消息进行数字签署的算法方法。

示例

以下示例是用于指定签名信息的样本代码:指定 HMAC_SHA1 作为签名方法、指定 C14N 作为规范方法、指定 SHA256 作为摘要方法以及指定 EXC_C14N 和 TRANSFORM_STRT10 作为变换方法:

	  	  // get the message context
	  Object msgcontext = getMessageContext();
	  
	  	  // generate WSSFactory instance
	  WSSFactory factory = WSSFactory.getInstance();		
	  	  
	  	  // generate WSSGenerationContext instance
	  WSSGenerationContext gencont = factory.newWSSGenerationContext();
		
	  	  // generate callback handler
	  	  X509GenerateCallbackHandler callbackHandler = new X509GenerateCallbackHandler(
			  "",
			  "dsig-sender.ks",
			  "jks",
			  "client".toCharArray(),
			  "soaprequester",
			  "client".toCharArray(),
			  			  "CN=SOAPRequester, OU=TRL, O=IBM, ST=Kanagawa, C=JP", 
			  null);
	  
	  	  //generate the security token used to the signature 
	  SecurityToken token = factory.newSecurityToken(X509Token.class, callbackHandler);

	  	  //generate WSSSignature instance 
	  WSSSignature sig = factory.newWSSSignature(token);
	  
	  	  //set the canonicalization method
	  // DEFAULT: WSSSignature.EXC_C14N
	  sig.setCanonicalizationMethod(WSSSignature.C14N);
	  
	  	  //set the signature method  
	  // DEFAULT: WSSSignature.RSA_SHA1
	  sig.setSignatureMethod(WSSSignature.HMAC_SHA1);

	  	  //set the part specified by WSSSignPart 
	  WSSSignPart sigPart = factory.newWSSSignPart();
	
	  	  //set the digest method
 	  // DEFAULT: WSSSignPart.SHA1
	  sigPart.setDigestMethod(WSSSignPart.SHA256);

	  	  //add the transform method
	  // DEFAULT: WSSSignPart.TRANSFORM_EXC_C14N
	  	  sigPart.addTransformMethod(WSSSignPart.TRANSFORM_EXC_C14N);
	  	  sigPart.addTransformMethod(WSSSignPart.TRANSFORM_STRT10);

    // add the WSSSignPart to the WSSSignature
    sig.addSignPart(sigPart);
		  
	  	  //add the WSSSignature to the WSSGenerationContext 
	  gencont.add(sig);
		
	  	  //generate the WS-Security header
	  gencont.process(msgcontext);

下一步做什么

配置客户机对消息进行数字签署及选择算法方法后,必须配置服务器以便对请求签署验证数字签名及选择算法方法。

通过管理控制台配置策略集以便在服务器上配置签名验证信息和方法。


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



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