使用 WSSDecryption API 对 SOAP 消息进行解密

可通过使用 Web Service 安全性 API (WSS API) 保护 SOAP 消息,而不必对配置使用策略集。要配置客户机以便在响应(客户机)使用者端进行解密,请使用 WSSDecryption API 对 SOAP 消息进行解密。WSSDecryption API 指定配置客户机时要进行解密的请求 SOAP 消息部件。

开始之前

可以使用 WSS API 或者在管理控制台上使用策略集来启用解密并在 SOAP 消息中添加使用者安全性令牌。要保护 SOAP 消息,必须完成了下列解密任务:

  • 对 SOAP 消息进行加密。
  • 选择解密方法。

关于此任务

使用者端的解密信息用于对响应使用者(客户端)绑定的入局 SOAP 消息进行解密。客户机使用者配置必须与提供程序生成器的配置匹配。

机密性设置要求将机密性约束应用于生成的消息。

可以配置下列解密部件:

表 1. 解密部件. 使用解密部分来保护消息。
解密部件 描述
part 将 WSSDecryptPart 对象添加为解密部件的目标。
keyword 使用关键字添加解密部件。WebSphere® Application Server 支持以下关键字:
  • BODY_CONTENT
  • SIGNATURE
  • USERNAME_TOKEN
xpath 使用 XPath 表达式添加解密部件。
verification 将 WSSVerification 实例添加为解密部件的目标。
header 将由 QName 指定的 SOAP 头添加为解密部件的目标。

为了获取解密信息,将执行特定的缺省行为。使用 WSS API 进行解密的最简单方法是使用缺省行为(请参阅示例代码)。WSSDecryption 对密钥加密算法、数据加密算法以及诸如 SOAP 主体内容和签名之类的解密部件提供了缺省值。缺省解密行为包括:

表 2. 解密决定. 缺省情况下,已配置多个解密部分特征。
解密决定 缺省行为
要进行解密的部件

缺省解密部件是 BODY_CONTENT 和 SIGNATURE。WebSphere Application Server 支持使用下列关键字:

  • WSSDecryption.BODY_CONTENT
  • WSSDecryption.SIGNATURE
  • WSSDecryption.USERNAME_TOKEN

指定要进行解密的消息部件后,必须指定对使用者请求消息进行解密时使用的方法。例如,如果对签名和主体内容进行了加密,那么要进行解密的 SOAP 消息部件包括相同的部件。

是否对密钥进行加密 (isEncrypt) 缺省值是对密钥进行加密 (true)。
要选择的数据解密算法(方法)

缺省数据解密算法方法是 AES128。WebSphere Application Server 支持以下数据加密方法:

  • WSSDecryption.AES128:http://www.w3.org/2001/04/xmlenc#aes128-cbc
  • WSSDecryption.AES192:http://www.w3.org/2001/04/xmlenc#aes192-cbc
  • WSSDecryption.AES256:http://www.w3.org/2001/04/xmlenc#aes256-cbc
  • WSSDecryption.TRIPLE_DES:http://www.w3.org/2001/04/xmlenc#tripledes-cbc
要选择的密钥解密方法(算法)

缺省密钥解密算法方法是密钥合并 RSA OAEP。WebSphere Application Server 支持以下密钥加密方法:

  • WSSDecryption.KW_AES128:http://www.w3.org/2001/04/xmlenc#kw-aes128
  • WSSDecryption.KW_AES192:http://www.w3.org/2001/04/xmlenc#kw-aes192
  • WSSDecryption.KW_AES256:http://www.w3.org/2001/04/xmlenc#kw-aes256
  • WSSDecryption.KW_RSA_OAEP:http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p
  • WSSDecryption.KW_RSA15:http://www.w3.org/2001/04/xmlenc#rsa-1_5
  • WSSDecryption.KW_TRIPLE_DES:http://www.w3.org/2001/04/xmlenc#kw-tripledes
要指定的安全性令牌

缺省安全性令牌类型是 X509 令牌。WebSphere Application Server 提供以下预配置的使用者令牌类型:

  • 派生密钥令牌
  • X509 令牌

过程

  1. 要使用 WSSDecryption API 对 SOAP 消息进行解密,请首先确保安装了应用程序服务器。
  2. 用于解密的 WSS API 过程执行以下过程步骤:
    1. 使用 WSSFactory.getInstance() 获取 WSS API 实现实例。
    2. 根据 WSSFactory 实例创建 WSSConsumingContext 实例。 必须始终在 JAX-WS 客户机应用程序中调用 WSSConsumingContext。
    3. 对使用者端创建回调处理程序。
    4. 根据 WSSFactory 实例使用安全性令牌和回调处理程序的类来创建 WSSDecryption。 WSSDecryption 的缺省行为是假定主体内容和签名已进行加密。
    5. 添加要进行解密的部件(如果缺省值不合适)。
    6. 添加数据加密方法的候选值以用于解密。
    7. 添加密钥加密方法的候选值以用于解密。
    8. 添加安全性令牌的候选值以用于解密。
    9. 调用 WSSDecryption.encryptKey(false)(如果应用程序不需要在入局消息中对密钥进行加密)。
    10. 将 WSSDecryption 添加至 WSSConsumingContext。
    11. 使用 SOAPMessageContext 调用 WSSConsumingContext.process()。

结果

如果在解密过程中存在错误情况,那么将提供 WSSException。如果成功,那么将调用 WSSConsumingContext.process() 并将 Web Service 安全性应用于 SOAP 消息。

示例

以下示例提供了样本代码,用于对 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 gencont = factory.newWSSConsumingContext();

// Generate the callback handler (step: c)
   X509ConsumeCallbackHandler callbackHandler = new
       X509ConsumeCallbackHandler(
                                  "",
                                  "enc-sender.jceks",
                                  "jceks",
                                  "storepass".toCharArray(),
                                  "alice",
                                  "keypass".toCharArray(),
	"CN=Alice, O=IBM, C=US");

// Generate the WSSDecryption instance (step: d)
   WSSDecryption dec = factory.newWSSDecryption(X509Token.class,
                                                callbackHandler);

// Set the part to be encrypted (step: e)
// DEFAULT: WSSEncryption.BODY_CONTENT and WSSEncryption.SIGNATURE

// Set the part to be encrypted (step: e)
// DEFAULT: WSSEncryption.BODY_CONTENT and WSSEncryption.SIGNATURE

// Set the part specified by the keyword (step: e)
      dec.addRequiredDecryptPart(WSSDecryption.BODY_CONTENT);

// Set the part in the SOAP Header specified by QName (step: e)
    dec.addRequiredDecryptHeader(new 
       QName("http://www.w3.org/2005/08/addressing", 
       "MessageID"));

// Set the part specified by WSSVerification  (step: e)
   X509ConsumeCallbackHandler verifyCallbackHandler = 
      getCallbackHandler();
   WSSVerification ver = factory.newWSSVerification(X509Token.class, 
                                                    verifyCallbackHandler);
      dec.addRequiredDecryptPart(ver);

// Set the part specified by XPath expression (step: e)
      		StringBuffer sb = new StringBuffer();
         sb.append("/*[namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/' 
            and local-name()='Envelope']");
         sb.append("/*[namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/' 
            and local-name()='Body']");
         sb.append("/*[namespace-uri()='http://xmlsoap.org/Ping' 
            and local-name()='Ping']");
         sb.append("/*[namespace-uri()='http://xmlsoap.org/Ping' 
            and local-name()='Text']");
      dec.addRequiredDecryptPartByXPath(sb.toString());

// Set the part in the SOAP header to be decrypted specified by QName (step: e)
      dec.addRequiredDecryptHeader(new 
          QName("http://www.w3.org/2005/08/addressing", 
          "MessageID"));

// Set the candidates for the data encryption method (step: f)
// DEFAULT : WSSDecryption.AES128
      dec.addAllowedEncryptionMethod(WSSDecryption.AES128);
      dec.addAllowedEncryptionMethod(WSSDecryption.AES192);

// Set the candidates for the key encryption method (step: g)
// DEFAULT : WSSDecryption.KW_RSA_OAEP
      dec.addAllowedKeyEncryptionMethod(WSSDecryption.KW_TRIPLE_DES);

// Set the candidate security token to used for the decryption (step: h)
   X509ConsumeCallbackHandler callbackHandler2 = getCallbackHandler2();
      dec.addToken(X509Token.class, callbackHandler2);

// Set whether or not the key should be encrypted in the incoming SOAP message (step: i) 
// DEFAULT: true
      dec.encryptKey(true);

// Add the WSSDecryption to the WSSConsumingContext (step: j)
   concont.add(dec);

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

下一步做什么

接下来,使用 WSSDecryptPart API,或者通过管理控制台配置策略集对使用者消息添加解密部件。


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



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