Esempio n. 1
0
        public bool SynchronizeCredentials(Guid universeId, Int64 playerId, string playerName, string password)
        {
            Guid userId = AuthenticateClient("SynchronizeCredentials");

            try
            {
                if (string.IsNullOrEmpty(password))
                {
                    return(WebServiceDAL.LinkUserToUniverseAccount(userId, universeId, playerId, playerName, password));
                }
                else
                {
                    Int64 encryptionKeyId = WebServiceDAL.GetUserEncryptionKeyId(userId);
                    if (encryptionKeyId != 0)
                    {
                        DataTable encryptionKeys = WebServiceDAL.GetUserEncryptionKeys(encryptionKeyId);

                        string serverKey = Encryption.DecryptString(UtilitiesBLL.DecryptEncryptionKeyHash(encryptionKeys.Rows[0]["ServerKey"].ToString()), Credentials.Password);
                        string clientKey = Encryption.DecryptString(UtilitiesBLL.DecryptEncryptionKeyHash(encryptionKeys.Rows[0]["ClientKey"].ToString()), Credentials.Password);

                        password = Encryption.EncryptString(Encryption.DecryptString(password, clientKey), serverKey);
                        return(WebServiceDAL.LinkUserToUniverseAccount(userId, universeId, playerId, playerName, password));
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                // Log it
                WebServiceDAL.StoreException("Webservice", "SynchronizeCredentials", ex);
                return(false);
            }
        }
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));;
        }