def testDirectEncryption(self): copy2(self._src_model_file_wo_variables, self._target_model_test1) args = list() args.append( 'encrypt') # dummy arg for args[0] to get arg padding right args.append(CommandLineArgUtil.ORACLE_HOME_SWITCH) args.append(self._oracle_home) args.append(CommandLineArgUtil.MODEL_FILE_SWITCH) args.append(self._target_model_test1) args.append(CommandLineArgUtil.PASSPHRASE_SWITCH) args.append(self._passphrase) exit_code = encrypt._process_request(args) self.assertEquals(exit_code, 0) model = FileToPython(self._target_model_test1).parse() passphrase_array = String(self._passphrase).toCharArray() admin_pass = model['domainInfo']['AdminPassword'] self.assertEquals(admin_pass.startswith('{AES}'), True) _decrypted_admin_pass = EncryptionUtils.decryptString( admin_pass, passphrase_array) self.assertEquals(str(String(_decrypted_admin_pass)), self._unencrypted_password) nm_pass = model['topology']['SecurityConfiguration'][ 'NodeManagerPasswordEncrypted'] self.assertEquals(nm_pass.startswith('{AES}'), True) _decrypted_nm_pass = EncryptionUtils.decryptString( nm_pass, passphrase_array) self.assertEquals(str(String(_decrypted_nm_pass)), self._unencrypted_password) ds1_pass = model['resources']['JDBCSystemResource']['Generic1'][ 'JdbcResource']['JDBCDriverParams']['PasswordEncrypted'] self.assertEquals(ds1_pass.startswith('{AES}'), True) _decrypted_ds1_pass = EncryptionUtils.decryptString( ds1_pass, passphrase_array) self.assertEquals(str(String(_decrypted_ds1_pass)), self._unencrypted_password) ons_pass = \ model['resources']['JDBCSystemResource']['Generic1']['JdbcResource']['JDBCOracleParams']['OnsWalletPasswordEncrypted'] self.assertEquals(ons_pass.startswith('{AES}'), True) _decrypted_ons_pass = EncryptionUtils.decryptString( ons_pass, passphrase_array) self.assertEquals(str(String(_decrypted_ons_pass)), self._unencrypted_password) ds2_pass = model['resources']['JDBCSystemResource']['Generic2'][ 'JdbcResource']['JDBCDriverParams']['PasswordEncrypted'] self.assertEquals(ds2_pass.startswith('{AES}'), True) _decrypted_ds2_pass = EncryptionUtils.decryptString( ds2_pass, passphrase_array) self.assertEquals(str(String(_decrypted_ds2_pass)), self._unencrypted_password) return
def testMultipleModelsIndirectEncryptionVariables(self): copy2(self._src_model_file_w_variables, self._target_model_test2) copy2(self._src_model_file_w_variables_multi, self._target_model_test3) copy2(self._src_variable_file, self._target_variables_test3) args = list() args.append( 'encrypt') # dummy arg for args[0] to get arg padding right args.append(CommandLineArgUtil.ORACLE_HOME_SWITCH) args.append(self._oracle_home) args.append(CommandLineArgUtil.MODEL_FILE_SWITCH) args.append(self._target_model_test2 + ',' + self._target_model_test3) args.append(CommandLineArgUtil.VARIABLE_FILE_SWITCH) args.append(self._target_variables_test3) args.append(CommandLineArgUtil.PASSPHRASE_SWITCH) args.append(self._passphrase) exit_code = encrypt._process_request(args) self.assertEquals(exit_code, 0) model2 = FileToPython(self._target_model_test2).parse() model3 = FileToPython(self._target_model_test3).parse() variables = variables_helper.load_variables( self._target_variables_test3) passphrase_array = String(self._passphrase).toCharArray() admin_pass = model2['domainInfo']['AdminPassword'] self.assertNotEquals(admin_pass.startswith('{AES}'), True) admin_pass = model3['domainInfo']['AdminPassword'] self.assertNotEquals(admin_pass.startswith('{AES}'), True) admin_pass = variables['admin.password'] self.assertEquals(admin_pass.startswith('{AES}'), True) _decrypted_admin_pass = EncryptionUtils.decryptString( admin_pass, passphrase_array) self.assertEquals(str(String(_decrypted_admin_pass)), self._unencrypted_password) nm_pass = model2['topology']['SecurityConfiguration'][ 'NodeManagerPasswordEncrypted'] self.assertNotEquals(nm_pass.startswith('{AES}'), True) nm_pass = variables['nm.password'] self.assertEquals(nm_pass.startswith('{AES}'), True) _decrypted_nm_pass = EncryptionUtils.decryptString( nm_pass, passphrase_array) self.assertEquals(str(String(_decrypted_nm_pass)), self._unencrypted_password) ds1_pass = model2['resources']['JDBCSystemResource']['Generic1'][ 'JdbcResource']['JDBCDriverParams']['PasswordEncrypted'] self.assertEquals(ds1_pass.startswith('{AES}'), True) _decrypted_ds1_pass = EncryptionUtils.decryptString( ds1_pass, passphrase_array) self.assertEquals(str(String(_decrypted_ds1_pass)), self._unencrypted_password) return
def testMultipleModelsDirectAndVariables(self): copy2(self._src_model_file_w_variables, self._target_model_test1) copy2(self._src_model_file_wo_variables_for_multi, self._target_model_test2) copy2(self._src_variable_file, self._target_variables_test3) args = list() args.append( 'encrypt') # dummy arg for args[0] to get arg padding right args.append(CommandLineArgUtil.ORACLE_HOME_SWITCH) args.append(self._oracle_home) args.append(CommandLineArgUtil.MODEL_FILE_SWITCH) args.append(self._target_model_test1 + ',' + self._target_model_test2) args.append(CommandLineArgUtil.VARIABLE_FILE_SWITCH) args.append(self._target_variables_test3) args.append(CommandLineArgUtil.PASSPHRASE_SWITCH) args.append(self._passphrase) exit_code = encrypt._process_request(args) self.assertEquals(exit_code, 0) model2 = FileToPython(self._target_model_test1).parse() model3 = FileToPython(self._target_model_test2).parse() variables = variables_helper.load_variables( self._target_variables_test3) passphrase_array = String(self._passphrase).toCharArray() admin_pass = model2['domainInfo']['AdminPassword'] self.assertNotEquals(admin_pass.startswith('{AES}'), True) admin_pass = variables['admin.password'] self.assertEquals(admin_pass.startswith('{AES}'), True) _decrypted_admin_pass = EncryptionUtils.decryptString( admin_pass, passphrase_array) self.assertEquals(str(String(_decrypted_admin_pass)), self._unencrypted_password) admin_pass = model3['domainInfo']['AdminPassword'] self.assertEquals(admin_pass.startswith('{AES}'), True) _decrypted_admin_pass = EncryptionUtils.decryptString( admin_pass, passphrase_array) self.assertEquals(str(String(_decrypted_admin_pass)), self._unencrypted_password_second) return
def decrypt_file(cipher_text, password, outputfile): try: pwd = String(password) x = EncryptionUtils.decryptString(cipher_text, pwd.toCharArray()) restored_text = String(x) fh = open(outputfile, "w") fh.write(str(restored_text)) fh.close() System.exit(0) except EncryptionException, e: # Catch the exact exception to get the real cause trace("SEVERE", "Error in decrypting file: %s" % e.getCause()) System.exit(-1)
def decrypt_file(cipher_text, password, outputfile): try: pwd = String(password) x = EncryptionUtils.decryptString(cipher_text, pwd.toCharArray()) restored_text = String(x) fh = open(outputfile, "w") fh.write(str(restored_text)) fh.close() System.exit(0) except: exc_type, exc_obj, exc_tb = sys.exc_info() eeString = traceback.format_exception(exc_type, exc_obj, exc_tb) print eeString System.exit(-1)