Author: alessio.soldano(a)jboss.com
Date: 2012-11-20 07:44:54 -0500 (Tue, 20 Nov 2012)
New Revision: 17028
Modified:
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/util/WSSecurityUtil.java
Log:
[JBPAPP-10420] Backporting commit 1202218 from upstream
Modified:
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java
===================================================================
---
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java 2012-11-18
19:09:55 UTC (rev 17027)
+++
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java 2012-11-20
12:44:54 UTC (rev 17028)
@@ -161,6 +161,9 @@
* @see WSConstants#AES_256
*/
public void setSymmetricEncAlgorithm(String algo) {
+ if (symEncAlgo != null && !symEncAlgo.equals(algo)) {
+ symmetricKey = null;
+ }
symEncAlgo = algo;
}
Modified:
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/util/WSSecurityUtil.java
===================================================================
---
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/util/WSSecurityUtil.java 2012-11-18
19:09:55 UTC (rev 17027)
+++
thirdparty/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/util/WSSecurityUtil.java 2012-11-20
12:44:54 UTC (rev 17028)
@@ -741,10 +741,31 @@
return doc.createTextNode(Base64.encode(data));
}
+ /**
+ * Convert the raw key bytes into a SecretKey object of type symEncAlgo.
+ */
public static SecretKey prepareSecretKey(String symEncAlgo, byte[] rawKey) {
- SecretKeySpec keySpec =
- new SecretKeySpec(rawKey, JCEMapper.getJCEKeyAlgorithmFromURI(symEncAlgo));
- return (SecretKey) keySpec;
+ // Do an additional check on the keysize required by the encryption algorithm
+ int size = 0;
+ try {
+ size = JCEMapper.getKeyLengthFromURI(symEncAlgo) / 8;
+ } catch (Exception e) {
+ // ignore - some unknown (to JCEMapper) encryption algorithm
+ if (log.isDebugEnabled()) {
+ log.debug(e.getMessage());
+ }
+ }
+ String keyAlgorithm = JCEMapper.getJCEKeyAlgorithmFromURI(symEncAlgo);
+ SecretKeySpec keySpec;
+ if (size > 0) {
+ keySpec =
+ new SecretKeySpec(
+ rawKey, 0, ((rawKey.length > size) ? size : rawKey.length),
keyAlgorithm
+ );
+ } else {
+ keySpec = new SecretKeySpec(rawKey, keyAlgorithm);
+ }
+ return (SecretKey)keySpec;
}
public static SOAPConstants getSOAPConstants(Element startElement) {
Show replies by date