Skip to content

Commit feeafa7

Browse files
author
Sheng Yang
committed
CLOUDSTACK-5241: Remove Rot13 cipher
1 parent ab16011 commit feeafa7

5 files changed

Lines changed: 3 additions & 42 deletions

File tree

server/src/com/cloud/network/element/CloudZonesNetworkElement.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.cloud.network.dao.NetworkDao;
5151
import com.cloud.offering.NetworkOffering;
5252
import com.cloud.service.dao.ServiceOfferingDao;
53-
import com.cloud.utils.PasswordGenerator;
5453
import com.cloud.utils.component.AdapterBase;
5554
import com.cloud.vm.NicProfile;
5655
import com.cloud.vm.ReservationContext;
@@ -215,8 +214,7 @@ public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMa
215214

216215
Commands cmds = new Commands(Command.OnError.Continue);
217216
if (password != null && nic.isDefaultNic()) {
218-
final String encodedPassword = PasswordGenerator.rot13(password);
219-
SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd());
217+
SavePasswordCommand cmd = new SavePasswordCommand(password, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd());
220218
cmds.addCommand("password", cmd);
221219
}
222220
String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText();

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@
200200
import com.cloud.uservm.UserVm;
201201
import com.cloud.utils.NumbersUtil;
202202
import com.cloud.utils.Pair;
203-
import com.cloud.utils.PasswordGenerator;
204203
import com.cloud.utils.StringUtils;
205204
import com.cloud.utils.component.ComponentContext;
206205
import com.cloud.utils.component.ManagerBase;
@@ -3642,9 +3641,8 @@ private void createPasswordCommand(final VirtualRouter router, final VirtualMach
36423641

36433642
// password should be set only on default network element
36443643
if (password != null && nic.isDefaultNic()) {
3645-
final String encodedPassword = PasswordGenerator.rot13(password);
36463644
final SavePasswordCommand cmd =
3647-
new SavePasswordCommand(encodedPassword, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd());
3645+
new SavePasswordCommand(password, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd());
36483646
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
36493647
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId()));
36503648
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());

systemvm/patches/debian/config/opt/cloud/bin/savepassword.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ do
4040
case $OPTION in
4141
v) VM_IP="$OPTARG"
4242
;;
43-
p)
44-
ENCODEDPASSWORD="$OPTARG"
45-
PASSWORD=$(echo $ENCODEDPASSWORD | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]')
43+
p) PASSWORD="$OPTARG"
4644
;;
4745
?) echo "Incorrect usage"
4846
unlock_exit 1 $lock $locked

utils/src/com/cloud/utils/PasswordGenerator.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,4 @@ public static String generatePresharedKey(int numChars) {
7777
return psk.toString();
7878

7979
}
80-
81-
public static String rot13(final String password) {
82-
final StringBuilder newPassword = new StringBuilder(password.length());
83-
84-
for (int i = 0; i < password.length(); i++) {
85-
char c = password.charAt(i);
86-
87-
if ((c >= 'a' && c <= 'm') || ((c >= 'A' && c <= 'M'))) {
88-
c += 13;
89-
} else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z')) {
90-
c -= 13;
91-
}
92-
93-
newPassword.append(c);
94-
}
95-
96-
return newPassword.toString();
97-
}
9880
}

utils/test/com/cloud/utils/PasswordGeneratorTest.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,4 @@ public void generateRandomPassword() {
3838
// and the third is a digit
3939
Assert.assertTrue(Character.isDigit(password.charAt(2)));
4040
}
41-
42-
@Test
43-
public void rot13() {
44-
// only letters are handled, numbers are unchanged
45-
Assert.assertEquals("1234", PasswordGenerator.rot13("1234"));
46-
// letters are moved by +-13 characters
47-
Assert.assertEquals("nop", PasswordGenerator.rot13("abc"));
48-
// the transformation it is reversable
49-
Assert.assertEquals("abc", PasswordGenerator.rot13("nop"));
50-
// which means for any string
51-
Assert.assertEquals("abcdefghijklmnooprstuvxyzuv1234?", PasswordGenerator.rot13(PasswordGenerator.rot13("abcdefghijklmnooprstuvxyzuv1234?")));
52-
// same for capital letters
53-
Assert.assertEquals("ABC", PasswordGenerator.rot13("NOP"));
54-
Assert.assertEquals("NOP", PasswordGenerator.rot13("ABC"));
55-
}
5641
}

0 commit comments

Comments
 (0)