CLOUDSTACK-5241: Remove Rot13 cipher

This commit is contained in:
Sheng Yang 2014-12-03 19:30:31 -08:00
parent ab16011874
commit feeafa76a4
5 changed files with 3 additions and 42 deletions

View File

@ -50,7 +50,6 @@ import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.dao.NetworkDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.component.AdapterBase;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@ -215,8 +214,7 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
Commands cmds = new Commands(Command.OnError.Continue);
if (password != null && nic.isDefaultNic()) {
final String encodedPassword = PasswordGenerator.rot13(password);
SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd());
SavePasswordCommand cmd = new SavePasswordCommand(password, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd());
cmds.addCommand("password", cmd);
}
String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText();

View File

@ -200,7 +200,6 @@ import com.cloud.user.dao.UserStatsLogDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.ManagerBase;
@ -3642,9 +3641,8 @@ VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.
// password should be set only on default network element
if (password != null && nic.isDefaultNic()) {
final String encodedPassword = PasswordGenerator.rot13(password);
final SavePasswordCommand cmd =
new SavePasswordCommand(encodedPassword, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd());
new SavePasswordCommand(password, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());

View File

@ -40,9 +40,7 @@ do
case $OPTION in
v) VM_IP="$OPTARG"
;;
p)
ENCODEDPASSWORD="$OPTARG"
PASSWORD=$(echo $ENCODEDPASSWORD | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]')
p) PASSWORD="$OPTARG"
;;
?) echo "Incorrect usage"
unlock_exit 1 $lock $locked

View File

@ -77,22 +77,4 @@ public class PasswordGenerator {
return psk.toString();
}
public static String rot13(final String password) {
final StringBuilder newPassword = new StringBuilder(password.length());
for (int i = 0; i < password.length(); i++) {
char c = password.charAt(i);
if ((c >= 'a' && c <= 'm') || ((c >= 'A' && c <= 'M'))) {
c += 13;
} else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z')) {
c -= 13;
}
newPassword.append(c);
}
return newPassword.toString();
}
}

View File

@ -38,19 +38,4 @@ public class PasswordGeneratorTest {
// and the third is a digit
Assert.assertTrue(Character.isDigit(password.charAt(2)));
}
@Test
public void rot13() {
// only letters are handled, numbers are unchanged
Assert.assertEquals("1234", PasswordGenerator.rot13("1234"));
// letters are moved by +-13 characters
Assert.assertEquals("nop", PasswordGenerator.rot13("abc"));
// the transformation it is reversable
Assert.assertEquals("abc", PasswordGenerator.rot13("nop"));
// which means for any string
Assert.assertEquals("abcdefghijklmnooprstuvxyzuv1234?", PasswordGenerator.rot13(PasswordGenerator.rot13("abcdefghijklmnooprstuvxyzuv1234?")));
// same for capital letters
Assert.assertEquals("ABC", PasswordGenerator.rot13("NOP"));
Assert.assertEquals("NOP", PasswordGenerator.rot13("ABC"));
}
}