CLOUDSTACK-8070: during 4.3.1 to 4.3.2 upgrade encrypt config that are hidden

In case there is an encryption key/password is provided the value, specifically
for router.ram.size will be encrypted otherwise it will remain plain text.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2014-12-12 20:33:16 +05:30
parent 485c76a2f8
commit 5519095a29
1 changed files with 7 additions and 1 deletions

View File

@ -18,6 +18,7 @@
package com.cloud.upgrade.dao;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -28,6 +29,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.log4j.Logger;
@ -65,10 +67,14 @@ public class Upgrade431to432 implements DbUpgrade {
private void updateMaxRouterSizeConfig(Connection conn) {
PreparedStatement updatePstmt = null;
try {
updatePstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value='256' WHERE name='router.ram.size'");
String encryptedValue = DBEncryptionUtil.encrypt("256");
updatePstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value=? WHERE name='router.ram.size' AND category = 'Hidden'");
updatePstmt.setBytes(1, encryptedValue.getBytes("UTF-8"));
updatePstmt.executeUpdate();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to upgrade max ram size of router in config.", e);
} catch (UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable encrypt configuration values ", e);
} finally {
try {
if (updatePstmt != null) {