Esempio n. 1
0
 internal static string SerializeObjectToString <T>(T obj, string password)
 {
     try
     {
         //return Encryption.EncryptString(SerializeDeserializeObject.SerializeObject<T>(obj), password);
         return(SerializeDeserializeObject.SerializeObject <T>(obj));
     }
     catch (Exception ex)
     {
         return(Constants.ERROR);
     }
 }
Esempio n. 2
0
        public string SetupApplication(Guid toolId, Guid applicationKey, string prevToolVersion, string newToolVersion)
        {
            Guid userId = AuthenticateClient("SetupApplication");

            SetupAppObj returnObj = new SetupAppObj();

            try
            {
                // Link user to the application
                WebServiceDAL.LinkUserToApplication(applicationKey, userId);
                WebServiceDAL.UpgradeApplicationVersion(toolId, applicationKey, userId, prevToolVersion, newToolVersion);

                returnObj.IsApplicationUserValid = WebServiceDAL.IsApplicationUserValid(applicationKey, userId);
                returnObj.ToolLatestVersion      = WebServiceDAL.GetLatestToolVersion(toolId);
                returnObj.IsToolValid            = WebServiceDAL.IsToolValid(toolId, newToolVersion);

                if (returnObj.IsApplicationUserValid && returnObj.IsToolValid)
                {
                    returnObj.IsUserAllowedToUseThisTool = WebServiceDAL.IsUserAllowedToUseThisTool(toolId, userId);
                }

                if (returnObj.IsApplicationUserValid && returnObj.IsToolValid && returnObj.IsUserAllowedToUseThisTool)
                {
                    returnObj.CommunityData = WebServiceDAL.GetUserCommunityData(toolId, userId);

                    Int64 encryptionKeyId = WebServiceDAL.GetUserEncryptionKeyId(userId);

                    if (encryptionKeyId == 0)
                    {
                        returnObj.EncryptionKeysExists = WebServiceDAL.CreateUserEncryptionKey(userId, Credentials.Password);
                        encryptionKeyId = WebServiceDAL.GetUserEncryptionKeyId(userId);
                    }
                    else
                    {
                        returnObj.EncryptionKeysExists = true;
                    }

                    if (encryptionKeyId != 0)
                    {
                        DataTable encryptionKeys = WebServiceDAL.GetUserEncryptionKeys(encryptionKeyId);
                        string    serverKey      = "";
                        string    clientKey      = "";
                        try
                        {
                            serverKey = Encryption.DecryptString(UtilitiesBLL.DecryptEncryptionKeyHash(encryptionKeys.Rows[0]["ServerKey"].ToString()), Credentials.Password);
                            clientKey = Encryption.DecryptString(UtilitiesBLL.DecryptEncryptionKeyHash(encryptionKeys.Rows[0]["ClientKey"].ToString()), Credentials.Password);
                        }
                        catch (Exception ex)
                        {
                            WebServiceDAL.StoreException("Webservice", "SetupApplication - Keys encryption", ex);
                            // ServerKey or ClientKey is null/empty or something else went wrong when decrypting
                            // Therefore, create new keys
                            serverKey = UtilitiesBLL.CreateEncryptionKeyHash(Encryption.EncryptString(RandomPassword.Generate(15, 20), Credentials.Password));
                            clientKey = RandomPassword.Generate(15, 20);
                            returnObj.EncryptionKeysExists = WebServiceDAL.UpdateEncryptionKey(encryptionKeyId, serverKey, UtilitiesBLL.CreateEncryptionKeyHash(Encryption.EncryptString(clientKey, Credentials.Password)));
                            // Delete all saved passwords
                            WebServiceDAL.DeleteUserUniverseCredentialsPassword(userId);
                            serverKey = null;
                        }
                        if (!string.IsNullOrEmpty(clientKey))
                        {
                            returnObj.ClientEncryptionKey = clientKey;
                        }
                        else
                        {
                            throw new Exception("ClientKey cannot be empty or null");
                        }

                        if (!string.IsNullOrEmpty(serverKey))
                        {
                            returnObj.CredentialsList = WebServiceDAL.GetUserUniversesAccounts(userId, serverKey, clientKey);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WebServiceDAL.StoreException("Webservice", "SetupApplication", ex);
                returnObj.Error        = true;
                returnObj.ErrorMessage = ex.Message;
            }

            return(SerializeDeserializeObject.SerializeObject <SetupAppObj>(returnObj));;
        }