| Code with Misuse: |
class EncryptedKeyProcessor {
/**
* Decrypt an EncryptedData element referenced by dataRefURI
*/
private WSDataRef decryptDataRef(
Document doc,
String dataRefURI,
WSDocInfo docInfo,
byte[] decryptedData,
RequestData data
) throws WSSecurityException {
if (LOG.isDebugEnabled()) {
LOG.debug("found data reference: " + dataRefURI);
}
//
// Find the encrypted data element referenced by dataRefURI
//
Element encryptedDataElement =
ReferenceListProcessor.findEncryptedDataElement(doc, docInfo, dataRefURI);
if (encryptedDataElement != null && data.isRequireSignedEncryptedDataElements()) {
WSSecurityUtil.verifySignedElement(encryptedDataElement, doc, docInfo.getSecurityHeader());
}
//
// Prepare the SecretKey object to decrypt EncryptedData
//
String symEncAlgo = X509Util.getEncAlgo(encryptedDataElement);
// EncryptionAlgorithm cannot be null
if (symEncAlgo == null) {
data.getBSPEnforcer().handleBSPRule(BSPRule.R5601);
}
// EncryptionAlgorithm must be 3DES, or AES128, or AES256
if (!WSConstants.TRIPLE_DES.equals(symEncAlgo)
&& !WSConstants.AES_128.equals(symEncAlgo)
&& !WSConstants.AES_128_GCM.equals(symEncAlgo)
&& !WSConstants.AES_256.equals(symEncAlgo)
&& !WSConstants.AES_256_GCM.equals(symEncAlgo)) {
data.getBSPEnforcer().handleBSPRule(BSPRule.R5620);
}
SecretKey symmetricKey = null;
try {
symmetricKey = KeyUtils.prepareSecretKey(symEncAlgo, decryptedData);
} catch (IllegalArgumentException ex) {
throw new WSSecurityException(
WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "badEncAlgo",
ex, symEncAlgo);
}
// Check for compliance against the defined AlgorithmSuite
AlgorithmSuite algorithmSuite = data.getAlgorithmSuite();
if (algorithmSuite != null) {
AlgorithmSuiteValidator algorithmSuiteValidator = new
AlgorithmSuiteValidator(algorithmSuite);
algorithmSuiteValidator.checkSymmetricKeyLength(symmetricKey.getEncoded().length);
algorithmSuiteValidator.checkSymmetricEncryptionAlgorithm(symEncAlgo);
}
return ReferenceListProcessor.decryptEncryptedData(
doc, dataRefURI, encryptedDataElement, symmetricKey, symEncAlgo, data
);
}
}
|