Skip to content

Commit

Permalink
[CVE-2015-0226] Some changes to random key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
coheigea committed Aug 29, 2014
1 parent 23e6ebd commit de5104b
Showing 1 changed file with 12 additions and 3 deletions.
Expand Up @@ -19,6 +19,7 @@

package org.apache.wss4j.dom.processor;

import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.security.spec.MGF1ParameterSpec;
Expand Down Expand Up @@ -244,7 +245,7 @@ public List<WSSecurityEngineResult> handleToken(
private static byte[] getRandomKey(List<String> dataRefURIs, Document doc, WSDocInfo wsDocInfo) throws WSSecurityException {
try {
String alg = "AES";
int size = 128;
int size = 16;
if (!dataRefURIs.isEmpty()) {
String uri = dataRefURIs.iterator().next();
Element ee = ReferenceListProcessor.findEncryptedDataElement(doc, wsDocInfo, uri);
Expand All @@ -256,8 +257,16 @@ private static byte[] getRandomKey(List<String> dataRefURIs, Document doc, WSDoc
kgen.init(size * 8);
SecretKey k = kgen.generateKey();
return k.getEncoded();
} catch (Exception ex) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, ex);
} catch (Throwable ex) {
// Fallback to just using AES to avoid attacks on EncryptedData algorithms
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128);
SecretKey k = kgen.generateKey();
return k.getEncoded();
} catch (NoSuchAlgorithmException e) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, e);
}
}
}

Expand Down

0 comments on commit de5104b

Please sign in to comment.