|
18 | 18 | package com.cloud.upgrade.dao; |
19 | 19 |
|
20 | 20 | import java.io.File; |
| 21 | +import java.io.UnsupportedEncodingException; |
21 | 22 | import java.sql.Connection; |
22 | 23 | import java.sql.PreparedStatement; |
23 | 24 | import java.sql.ResultSet; |
@@ -72,6 +73,7 @@ public void performDataMigration(Connection conn) { |
72 | 73 | fixForeignKeys(conn); |
73 | 74 | setupExternalNetworkDevices(conn); |
74 | 75 | fixZoneUsingExternalDevices(conn); |
| 76 | + encryptConfig(conn); |
75 | 77 | } |
76 | 78 |
|
77 | 79 | @Override |
@@ -1079,4 +1081,43 @@ private void fixZoneUsingExternalDevices(Connection conn) { |
1079 | 1081 | s_logger.info("Successfully upgraded networks using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); |
1080 | 1082 | } |
1081 | 1083 | } |
| 1084 | + |
| 1085 | + private void encryptConfig(Connection conn){ |
| 1086 | + //Encrypt config params and change category to Hidden |
| 1087 | + s_logger.debug("Encrypting Config values"); |
| 1088 | + PreparedStatement pstmt = null; |
| 1089 | + ResultSet rs = null; |
| 1090 | + try { |
| 1091 | + pstmt = conn.prepareStatement("select name, value from `cloud`.`configuration` where name in ('router.ram.size', 'secondary.storage.vm', 'security.hash.key') and category <> 'Hidden'"); |
| 1092 | + rs = pstmt.executeQuery(); |
| 1093 | + while (rs.next()) { |
| 1094 | + String name = rs.getString(1); |
| 1095 | + String value = rs.getString(2); |
| 1096 | + if (value == null) { |
| 1097 | + continue; |
| 1098 | + } |
| 1099 | + String encryptedValue = DBEncryptionUtil.encrypt(value); |
| 1100 | + pstmt = conn.prepareStatement("update `cloud`.`configuration` set value=?, category = 'Hidden' where name=?"); |
| 1101 | + pstmt.setBytes(1, encryptedValue.getBytes("UTF-8")); |
| 1102 | + pstmt.setString(2, name); |
| 1103 | + pstmt.executeUpdate(); |
| 1104 | + } |
| 1105 | + } catch (SQLException e) { |
| 1106 | + throw new CloudRuntimeException("Unable encrypt configuration values ", e); |
| 1107 | + } catch (UnsupportedEncodingException e) { |
| 1108 | + throw new CloudRuntimeException("Unable encrypt configuration values ", e); |
| 1109 | + } finally { |
| 1110 | + try { |
| 1111 | + if (rs != null) { |
| 1112 | + rs.close(); |
| 1113 | + } |
| 1114 | + |
| 1115 | + if (pstmt != null) { |
| 1116 | + pstmt.close(); |
| 1117 | + } |
| 1118 | + } catch (SQLException e) { |
| 1119 | + } |
| 1120 | + } |
| 1121 | + s_logger.debug("Done encrypting Config values"); |
| 1122 | + } |
1082 | 1123 | } |
0 commit comments