Esempio n. 1
0
 internal void RunElevation(String disablerMessage, Action <ElevateToken> successMethod, String actionDescription)
 {
     try
     {
         _disabler.DisableInputs(true, disablerMessage);
         try
         {
             ElevateToken token = GwupeClientAppContext.CurrentAppContext.Elevate();
             successMethod(token);
         }
         catch (Exception ex)
         {
             _validator.SetError("Failed to authorise " + actionDescription + ".");
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Failed to elevate privileges for " + actionDescription + " : " + ex.Message, ex);
         _validator.SetError("Failed to elevate privileges for " + actionDescription + ".");
     }
     finally
     {
         _disabler.DisableInputs(false);
     }
 }
 internal ElevateToken Elevate(String message)
 {
     if (CurrentToken == null || CurrentToken.IsExpired())
     {
         Logger.Debug("We don't have an elevation token or it has expired, requesting from server.");
         ElevateTokenRq erq = new ElevateTokenRq();
         try
         {
             String password = UIManager.RequestElevation(message);
             // Make sure password isn't empty and conforms to the current password.
             if (!String.IsNullOrWhiteSpace(password) &&
                 Util.getSingleton().hashPassword(password).Equals(Reg.PasswordHash))
             {
                 ElevateTokenRs ers = ConnectionManager.Connection.Request <ElevateTokenRq, ElevateTokenRs>(erq);
                 CurrentToken = new ElevateToken(ers.tokenId, ers.token, password, ers.expires);
             }
             else
             {
                 Logger.Error("Entered password for elevation is invalid.");
                 CurrentToken = null;
                 throw new ElevationException();
             }
         }
         finally
         {
             UIManager.CompleteElevation();
         }
     }
     else
     {
         Logger.Debug("Reusing elevate token " + CurrentToken.TokenId);
     }
     return(CurrentToken);
 }
Esempio n. 3
0
        public void UpdateTeam(string username)
        {
            Team team = null;

            try
            {
                team = GetTeamByUsername(username);
            }
            catch (Exception e)
            {
                Logger.Error("Failed to find team " + username);
                var exception = new DataSubmissionException();
                exception.SubmitErrors.Add(new DataSubmitError()
                {
                    FieldName = "username",
                    ErrorCode = DataSubmitErrorCode.InvalidKey
                });
                throw exception;
            }
            ElevateToken token   = GwupeClientAppContext.CurrentAppContext.Elevate("In order to update this team, please enter your current password.");
            var          request = new UpdateTeamRq()
            {
                teamElement = new TeamElement()
                {
                    avatarData  = team.Avatar == null ? null : Convert.ToBase64String(team.Avatar),
                    description = team.Description,
                    email       = team.Email,
                    firstname   = team.Firstname,
                    location    = team.Location,
                    supporter   = team.Supporter,
                    user        = team.Username
                },
                playerRequest = team.PlayerRequest,
                admin         = team.Admin,
                securityKey   = token.SecurityKey,
                tokenId       = token.TokenId
            };

            try
            {
                var response = GwupeClientAppContext.CurrentAppContext.ConnectionManager.Connection
                               .Request <UpdateTeamRq, UpdateTeamRs>(
                    request);
                GwupeClientAppContext.CurrentAppContext.PartyManager.AddUpdatePartyFromElement(response.teamElement);
            }
            catch (MessageException <UpdateTeamRs> ex)
            {
                Logger.Error("Failed to update team", ex);
                var exception = CompileDataSubmissionException(ex.Response.validationErrors);
                throw exception;
            }
        }
Esempio n. 4
0
 private void ElevatedRequestRdpSession()
 {
     try
     {
         ElevateToken token = GwupeClientAppContext.CurrentAppContext.Elevate(
             "This connection requires you to verify your identity, please enter your Gwupe password to connect to " +
             _engagement.SecondParty.Party.Name + ".");
         RequestRdpSession(token);
     }
     catch (Exception ex)
     {
         Chat.LogErrorMessage("Failed to elevate privileges to connect to " + _engagement.SecondParty.Party.Name);
         throw new Exception("Failed to gain unattended access through elevation");
     }
 }
 private void UpdateRelationship(ElevateToken token)
 {
     try
     {
         var relationship = new Relationship
         {
             IHaveUnattendedAccess = GwupeClientAppContext.CurrentAppContext.RelationshipManager.GetRelationship(_dataContext.Engagement.SecondParty.Party.Username).IHaveUnattendedAccess
         };
         Dispatcher.Invoke(new Action(() => { relationship.TheyHaveUnattendedAccess = (UnattendedAccessCheckbox.IsChecked == true); }));
         GwupeClientAppContext.CurrentAppContext.RelationshipManager.UpdateRelationship(
             _dataContext.Engagement.SecondParty.Party.Username,
             relationship, token.TokenId, token.SecurityKey);
         _updatedRelationship = true;
     }
     catch (Exception ex)
     {
         Logger.Error("Failed to update the relationship to " + _dataContext.Engagement.SecondParty.Party.Username + " : " + ex.Message, ex);
         UiHelper.Validator.SetError("Failed to save changes to server");
     }
 }
Esempio n. 6
0
 private void SaveCurrentUser(ElevateToken token)
 {
     try
     {
         String password = GetPasswordChange();
         _appContext.CurrentUserManager.SaveCurrentUser(token.TokenId, token.SecurityKey, password);
         // save the password if it was changed. (for auto login)
         if (password != null)
         {
             GwupeUserRegistry.getInstance().PasswordHash = Util.getSingleton().hashPassword(password);
         }
         _uiHelper.Validator.SetStatus("Saved changes to server.");
         Dispatcher.Invoke(new Action(() =>
         {
             Password.Password        = "";
             PasswordChange.IsChecked = false;
             Password.IsEnabled       = false;
         }));
     }
     catch (ElevationException ex)
     {
         _uiHelper.Validator.SetError("Incorrect password, please try again");
     }
     catch (MessageException <UpdateUserRs> ex)
     {
         Logger.Error("Attempt to update user failed : " + ex.Message, ex);
         if ("WILL_NOT_PROCESS_AUTH".Equals(ex.Response.error))
         {
             _uiHelper.Validator.SetError("Incorrect password, please try again");
         }
         else
         {
             _uiHelper.Validator.SetError("Failed to save changes to server");
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Failed to save the current user : "******"Failed to save changes to server");
     }
 }
Esempio n. 7
0
 // Called When this user send a rdp request to the second party
 private void RequestRdpSession(ElevateToken token)
 {
     // now we compile the request to second party to control his desktop
     RDPRequestRq request = new RDPRequestRq()
     {
         shortCode = _engagement.SecondParty.ActiveShortCode,
         username = _engagement.SecondParty.Party.Username,
         interactionId = _engagement.Interactions.CurrentOrNewInteraction.Id,
         securityKey = token?.SecurityKey,
         tokenId = token?.TokenId,
     };
     try
     {
         // Actually send the message asynchronously
         //_appContext.ConnectionManager.Connection.RequestAsync<RDPRequestRq, RDPRequestRs>(request, (req, res, ex) => ProcessRequestRDPSessionResponse(req, res, ex, chatElement));
         try
         {
             // if its unattended, indicate this
             if (token != null)
             {
                 Chat.LogSystemMessage("You have unattended access to their desktop, you will be granted access automatically after 10 seconds.");
             }
             else
             {
                 // Print in chat that we sent the second party a rdp request
                 Chat.LogSystemMessage("You sent " + _engagement.SecondParty.Party.Firstname + " a request to control their desktop.");
             }
             var response = _appContext.ConnectionManager.Connection.Request<RDPRequestRq, RDPRequestRs>(request);
             // The message was delivered
             IsActive = true;
             // Raise an activity that we managed to send a rdp request to second party successfully.
             OnNewActivity(new RemoteDesktopActivity(_engagement, RemoteDesktopActivity.REMOTE_DESKTOP_REQUEST) { From = "_SELF", To = _engagement.SecondParty.Party.Username });
         }
         catch (MessageException<RDPRequestRs> e)
         {
             if ("WILL_NOT_PROCESS_ELEVATE".Equals(e.ErrorCode) && (token == null))
             {
                 // need elevation
                 ElevatedRequestRdpSession();
             }
             else if ("WILL_NOT_PROCESS_AUTH".Equals(e.ErrorCode))
             {
                 Chat.LogErrorMessage("Sorry, you entered your password incorrectly.  Please try again.");
             }
             else if ("KEY_NOT_FOUND".Equals(e.ErrorCode))
             {
                 // sometimes the user disappears and comes back with another shortcode, lets try that
                 if (_engagement.SecondParty.Presence.IsOnline &&
                     !_engagement.SecondParty.ActiveShortCode.Equals(_engagement.SecondParty.Presence.ShortCode))
                 {
                     Logger.Debug("ActiveShortCode is different from current presence shortcode, trying the new one");
                     _engagement.SecondParty.ActiveShortCode = _engagement.SecondParty.Presence.ShortCode;
                     RequestRdpSession(token);
                 }
                 else
                 {
                     throw;
                 }
             }
             else
             {
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Error during request for RDP Session : " + ex.Message, ex);
         Chat.LogErrorMessage("An error occured trying to send " + _engagement.SecondParty.Party.Firstname + " a request to control their desktop.");
     }
 }
Esempio n. 8
0
        // Called When this user send a rdp request to the second party
        private void RequestRdpSession(ElevateToken token)
        {
            // now we compile the request to second party to control his desktop
            RDPRequestRq request = new RDPRequestRq()
            {
                shortCode     = _engagement.SecondParty.ActiveShortCode,
                username      = _engagement.SecondParty.Party.Username,
                interactionId = _engagement.Interactions.CurrentOrNewInteraction.Id,
                securityKey   = token?.SecurityKey,
                tokenId       = token?.TokenId,
            };

            try
            {
                // Actually send the message asynchronously
                //_appContext.ConnectionManager.Connection.RequestAsync<RDPRequestRq, RDPRequestRs>(request, (req, res, ex) => ProcessRequestRDPSessionResponse(req, res, ex, chatElement));
                try
                {
                    // if its unattended, indicate this
                    if (token != null)
                    {
                        Chat.LogSystemMessage("You have unattended access to their desktop, you will be granted access automatically after 10 seconds.");
                    }
                    else
                    {
                        // Print in chat that we sent the second party a rdp request
                        Chat.LogSystemMessage("You sent " + _engagement.SecondParty.Party.Firstname + " a request to control their desktop.");
                    }
                    var response = _appContext.ConnectionManager.Connection.Request <RDPRequestRq, RDPRequestRs>(request);
                    // The message was delivered
                    IsActive = true;
                    // Raise an activity that we managed to send a rdp request to second party successfully.
                    OnNewActivity(new RemoteDesktopActivity(_engagement, RemoteDesktopActivity.REMOTE_DESKTOP_REQUEST)
                    {
                        From = "_SELF", To = _engagement.SecondParty.Party.Username
                    });
                }
                catch (MessageException <RDPRequestRs> e)
                {
                    if ("WILL_NOT_PROCESS_ELEVATE".Equals(e.ErrorCode) && (token == null))
                    {
                        // need elevation
                        ElevatedRequestRdpSession();
                    }
                    else if ("WILL_NOT_PROCESS_AUTH".Equals(e.ErrorCode))
                    {
                        Chat.LogErrorMessage("Sorry, you entered your password incorrectly.  Please try again.");
                    }
                    else if ("KEY_NOT_FOUND".Equals(e.ErrorCode))
                    {
                        // sometimes the user disappears and comes back with another shortcode, lets try that
                        if (_engagement.SecondParty.Presence.IsOnline &&
                            !_engagement.SecondParty.ActiveShortCode.Equals(_engagement.SecondParty.Presence.ShortCode))
                        {
                            Logger.Debug("ActiveShortCode is different from current presence shortcode, trying the new one");
                            _engagement.SecondParty.ActiveShortCode = _engagement.SecondParty.Presence.ShortCode;
                            RequestRdpSession(token);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error during request for RDP Session : " + ex.Message, ex);
                Chat.LogErrorMessage("An error occured trying to send " + _engagement.SecondParty.Party.Firstname + " a request to control their desktop.");
            }
        }