mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	CLOUDSTACK-5241: Remove Rot13 cipher
This commit is contained in:
		
							parent
							
								
									ab16011874
								
							
						
					
					
						commit
						feeafa76a4
					
				| @ -50,7 +50,6 @@ import com.cloud.network.PhysicalNetworkServiceProvider; | |||||||
| import com.cloud.network.dao.NetworkDao; | import com.cloud.network.dao.NetworkDao; | ||||||
| import com.cloud.offering.NetworkOffering; | import com.cloud.offering.NetworkOffering; | ||||||
| import com.cloud.service.dao.ServiceOfferingDao; | import com.cloud.service.dao.ServiceOfferingDao; | ||||||
| import com.cloud.utils.PasswordGenerator; |  | ||||||
| import com.cloud.utils.component.AdapterBase; | import com.cloud.utils.component.AdapterBase; | ||||||
| import com.cloud.vm.NicProfile; | import com.cloud.vm.NicProfile; | ||||||
| import com.cloud.vm.ReservationContext; | import com.cloud.vm.ReservationContext; | ||||||
| @ -215,8 +214,7 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem | |||||||
| 
 | 
 | ||||||
|             Commands cmds = new Commands(Command.OnError.Continue); |             Commands cmds = new Commands(Command.OnError.Continue); | ||||||
|             if (password != null && nic.isDefaultNic()) { |             if (password != null && nic.isDefaultNic()) { | ||||||
|                 final String encodedPassword = PasswordGenerator.rot13(password); |                 SavePasswordCommand cmd = new SavePasswordCommand(password, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd()); | ||||||
|                 SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd()); |  | ||||||
|                 cmds.addCommand("password", cmd); |                 cmds.addCommand("password", cmd); | ||||||
|             } |             } | ||||||
|             String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText(); |             String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText(); | ||||||
|  | |||||||
| @ -200,7 +200,6 @@ import com.cloud.user.dao.UserStatsLogDao; | |||||||
| import com.cloud.uservm.UserVm; | import com.cloud.uservm.UserVm; | ||||||
| import com.cloud.utils.NumbersUtil; | import com.cloud.utils.NumbersUtil; | ||||||
| import com.cloud.utils.Pair; | import com.cloud.utils.Pair; | ||||||
| import com.cloud.utils.PasswordGenerator; |  | ||||||
| import com.cloud.utils.StringUtils; | import com.cloud.utils.StringUtils; | ||||||
| import com.cloud.utils.component.ComponentContext; | import com.cloud.utils.component.ComponentContext; | ||||||
| import com.cloud.utils.component.ManagerBase; | 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 |         // password should be set only on default network element | ||||||
|         if (password != null && nic.isDefaultNic()) { |         if (password != null && nic.isDefaultNic()) { | ||||||
|             final String encodedPassword = PasswordGenerator.rot13(password); |  | ||||||
|             final SavePasswordCommand cmd = |             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_IP, getRouterControlIp(router.getId())); | ||||||
|             cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId())); |             cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(nic.getNetworkId(), router.getId())); | ||||||
|             cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); |             cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); | ||||||
|  | |||||||
| @ -40,9 +40,7 @@ do | |||||||
|   case $OPTION in |   case $OPTION in | ||||||
|   v)	VM_IP="$OPTARG" |   v)	VM_IP="$OPTARG" | ||||||
| 		;; | 		;; | ||||||
|   p)	 |   p)    PASSWORD="$OPTARG" | ||||||
| 		ENCODEDPASSWORD="$OPTARG" |  | ||||||
| 		PASSWORD=$(echo $ENCODEDPASSWORD | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]') |  | ||||||
| 		;; | 		;; | ||||||
|   ?)	echo "Incorrect usage" |   ?)	echo "Incorrect usage" | ||||||
|                 unlock_exit 1 $lock $locked |                 unlock_exit 1 $lock $locked | ||||||
|  | |||||||
| @ -77,22 +77,4 @@ public class PasswordGenerator { | |||||||
|         return psk.toString(); |         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(); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -38,19 +38,4 @@ public class PasswordGeneratorTest { | |||||||
|         // and the third is a digit |         // and the third is a digit | ||||||
|         Assert.assertTrue(Character.isDigit(password.charAt(2))); |         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")); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user