diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java index 05e5fe4d2ce..7a22b20ffdb 100644 --- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java +++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java @@ -139,7 +139,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler maxSizeInGB) { String errorMessage = "Maximum file upload size exceeded. Content Length received: " + contentLengthInGB + "GB. Maximum allowed size: " + maxSizeInGB + "GB."; @@ -2772,7 +2773,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S if (extension.equals("iso")) { templateName = uploadEntity.getUuid().trim().replace(" ", "_"); } else { - templateName = java.util.UUID.nameUUIDFromBytes((uploadEntity.getFilename() + System.currentTimeMillis()).getBytes()).toString(); + try { + templateName = UUID.nameUUIDFromBytes((uploadEntity.getFilename() + System.currentTimeMillis()).getBytes("UTF-8")).toString(); + } catch (UnsupportedEncodingException e) { + templateName = uploadEntity.getUuid().trim().replace(" ", "_"); + } } // run script to mv the temporary template file to the final template diff --git a/utils/src/com/cloud/utils/EncryptionUtil.java b/utils/src/com/cloud/utils/EncryptionUtil.java index 28d781fcadb..e3ca4b0964e 100644 --- a/utils/src/com/cloud/utils/EncryptionUtil.java +++ b/utils/src/com/cloud/utils/EncryptionUtil.java @@ -18,6 +18,7 @@ */ package com.cloud.utils; +import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import org.jasypt.encryption.pbe.PBEStringEncryptor; @@ -25,6 +26,7 @@ import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -56,14 +58,14 @@ public class EncryptionUtil { public static String generateSignature(String data, String key) { try { final Mac mac = Mac.getInstance("HmacSHA1"); - final SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1"); + final SecretKeySpec keySpec = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA1"); mac.init(keySpec); mac.update(data.getBytes()); final byte[] encryptedBytes = mac.doFinal(); return Base64.encodeBase64String(encryptedBytes); - } catch (NoSuchAlgorithmException | InvalidKeyException e) { - s_logger.error("exception occurred which encoding the data.", e); - return null; + } catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) { + s_logger.error("exception occurred which encoding the data." + e.getMessage()); + throw new CloudRuntimeException("unable to generate signature", e); } } }