/// <summary> /// /// </summary> /// <param name="tokensVector"></param> /// <returns></returns> private bool initElements(List <String> tokensVector) { String attribute, valueStr; bool isSuccess = true; int j; for (j = 0; j < tokensVector.Count; j += 2) { attribute = ((String)tokensVector[j]); valueStr = ((String)tokensVector[j + 1]); switch (attribute) { case ConstInterface.MG_TAG_USERNAME: UserName = valueStr; break; case ConstInterface.MG_ATTR_USERID: UserID = valueStr; ClientManager.Instance.setUsername(UserID); break; case ConstInterface.MG_ATTR_USERINFO: UserInfo = valueStr; break; case ConstInterface.MG_TAG_PASSWORD: Password = valueStr; byte[] passwordDecoded = Base64.decodeToByte(Password); string encryptedPassword = Encoding.UTF8.GetString(passwordDecoded, 0, passwordDecoded.Length); string decryptedPassword = Scrambler.UnScramble(encryptedPassword, 0, encryptedPassword.Length - 1); // At server side spaces are added at the end if the length of password is less than 4 characters. // Remove these extra spaces before setting the password. decryptedPassword = StrUtil.rtrim(decryptedPassword); // if the password is empty set a password containing one " ", as for userId, where if no userId // then a " " set to userId. if (String.IsNullOrEmpty(decryptedPassword)) { decryptedPassword = "******"; } ClientManager.Instance.setPassword(decryptedPassword); break; default: Logger.Instance.WriteExceptionToLog("in UserDetails.initElements(): unknown attribute: " + attribute); isSuccess = false; break; } } return(isSuccess); }
/// <summary> /// Initializes the encryptor that handles encryption/decryption of cached content (this functionality is currently embedded in the PersistentOnlyCacheManager..) /// </summary> internal void InitializeEncryptor() { // retrieve the required encryption state (enabled/disabled) and key: bool disableEncryption = GetLastOfflineExecutionPropertyBool(ConstInterface.DISABLE_ENCRYPTION); string encryptionKeyStr = LastOfflineExecutionProperties.getProperty(ConstInterface.ENCRYPTION_KEY); byte[] encryptionKey = null; if (!String.IsNullOrEmpty(encryptionKeyStr)) { // TODO: Scrambling the encryption key in the execution.properties_LastOffline file is not secured enough! encryptionKeyStr = Scrambler.UnScramble(encryptionKeyStr, 0, encryptionKeyStr.Length - 1); encryptionKey = Encoding.Default.GetBytes(encryptionKeyStr); } // initialize the encryptor: IEncryptor encryptor = PersistentOnlyCacheManager.CreateInstance(disableEncryption, encryptionKey); }
/// <summary> unscramble servers response</summary> /// <returns>unscrambled content</returns> protected static String UnScramble(String respBuf) { int openTagLocation = respBuf.IndexOf(XMLConstants.MG_TAG_OPEN); string core; if (openTagLocation != -1) { int start = openTagLocation + XMLConstants.MG_TAG_OPEN.Length; string openTag = respBuf.Substring(0, start); int finish = respBuf.LastIndexOf(XMLConstants.TAG_OPEN); string closeTag = respBuf.Substring(finish); core = openTag + Scrambler.UnScramble(respBuf, start, --finish) + closeTag; } // We got a scrambled error message, there is no open tag else { core = Scrambler.UnScramble(respBuf, 0, respBuf.Length - 1); } return(core); }