Exemple #1
0
        public EmailViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _passwordBase         = stateService.Password;
            stateService.Password = null;

            _authorizationForm             = stateService.AuthorizationForm;
            stateService.AuthorizationForm = null;

            _secureValues             = stateService.SecureValues;
            stateService.SecureValues = null;

            _secureType             = stateService.SecureType;
            stateService.SecureType = null;

            _secureRequiredType             = stateService.SecureRequiredType;
            stateService.SecureRequiredType = null;

            var password = _passwordBase as TLPassword81;

            if (password != null)
            {
                var passwordSettings = password.Settings as TLPasswordSettings83;
                if (passwordSettings != null)
                {
                    CurrentEmail = TLString.IsNullOrEmpty(passwordSettings.Email)? string.Empty : passwordSettings.Email.ToString();
                }
            }

            _emailValue = _secureRequiredType != null ? _secureRequiredType.DataValue : null;
        }
        public PhoneNumberViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _passwordBase         = stateService.Password;
            stateService.Password = null;

            _authorizationForm             = stateService.AuthorizationForm;
            stateService.AuthorizationForm = null;

            _secureValues             = stateService.SecureValues;
            stateService.SecureValues = null;

            _secureType             = stateService.SecureType;
            stateService.SecureType = null;

            _secureRequiredType             = stateService.SecureRequiredType;
            stateService.SecureRequiredType = null;

            var user = CacheService.GetUser(new TLInt(StateService.CurrentUserId));

            if (user != null && user.HasPhone)
            {
                CurrentPhone = user.Phone.ToString();
            }

            _phoneNumberValue = _secureRequiredType != null ? _secureRequiredType.DataValue : null;
        }
Exemple #3
0
        public EmailCodeViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _passwordBase         = stateService.Password;
            stateService.Password = null;

            _authorizationForm             = stateService.AuthorizationForm;
            stateService.AuthorizationForm = null;

            _secureValues             = stateService.SecureValues;
            stateService.SecureValues = null;

            _secureType             = stateService.SecureType;
            stateService.SecureType = null;

            _secureRequiredType             = stateService.SecureRequiredType;
            stateService.SecureRequiredType = null;

            CurrentEmail = stateService.CurrentEmail;
            stateService.CurrentEmail = null;

            _emailValue = _secureRequiredType != null ? _secureRequiredType.DataValue : null;

            _sentCode = stateService.SentEmailCode;
            stateService.SentEmailCode = null;

            Subtitle = GetSubtitle();

            var length = _sentCode as ILength;

            CodeLength = length != null ? length.Length.Value : Constants.DefaultCodeLength;
        }
        private static void ResetSecureSecret(
            TLPasswordSettings passwordSettings, TLPassword passwordBase, TLString password,
            TLAuthorizationForm authorizationForm, IList <TLSecureValue> secureValues,
            IMTProtoService mtProtoService, IStateService stateService, INavigationService navigationService)
        {
            var passwordSettings83 = passwordSettings as TLPasswordSettings83;

            if (passwordSettings83 == null)
            {
                return;
            }

            var password84 = passwordBase as TLPassword84;

            if (password84 == null)
            {
                return;
            }

            var newSecureSettings = new TLSecureSecretSettings
            {
                SecureAlgo     = new TLSecurePasswordKdfAlgoUnknown(),
                SecureSecret   = TLString.Empty,
                SecureSecretId = new TLLong(0)
            };

            var newSettings = new TLPasswordInputSettings83
            {
                Flags             = new TLInt(0),
                NewSecureSettings = newSecureSettings,
            };

            mtProtoService.GetPasswordAsync(
                resul1 =>
            {
                var srpParams = resul1 as IPasswordSRPParams;
                if (srpParams == null)
                {
                    return;
                }

                var currentPasswordHash = passwordBase.CurrentPasswordHash ?? TLString.Empty;
                mtProtoService.UpdatePasswordSettingsAsync(SRP.GetCheck(currentPasswordHash, srpParams.SRPId, srpParams.SRPB, srpParams.CurrentAlgo), newSettings,
                                                           result2 =>
                {
                    passwordSettings83.SecureSettings = newSettings.NewSecureSettings;

                    NavigateToPassportCommon(
                        passwordSettings83, passwordBase, password,
                        authorizationForm, secureValues,
                        mtProtoService, stateService, navigationService);
                },
                                                           error2 => { });
            },
                error1 => { });
        }
Exemple #5
0
        public PasswordIntroViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _passwordBase         = StateService.Password;
            StateService.Password = null;

            _authorizationForm             = StateService.AuthorizationForm;
            StateService.AuthorizationForm = null;

            _secureValues             = StateService.SecureValues;
            StateService.SecureValues = null;
        }
        protected ChangePasswordViewModelBase(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _passwordBase         = StateService.Password;
            StateService.Password = null;

            _newPasswordSettings             = StateService.NewPasswordSettings;
            StateService.NewPasswordSettings = null;

            _authorizationForm             = StateService.AuthorizationForm;
            StateService.AuthorizationForm = null;

            _secureValues             = StateService.SecureValues;
            StateService.SecureValues = null;
        }
        public EnterPasswordViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _authorizationForm             = stateService.AuthorizationForm;
            stateService.AuthorizationForm = null;

            _secureValues             = stateService.SecureValues;
            stateService.SecureValues = null;

            if (_authorizationForm != null)
            {
                Bot = _authorizationForm.Users.LastOrDefault();
            }
            else
            {
                Bot = CacheService.GetUser(new TLInt(StateService.CurrentUserId));
            }
        }
Exemple #8
0
        public PasswordViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _checkPasswordSettingsTimer.Tick    += OnCheckPasswordSettings;
            _checkPasswordSettingsTimer.Interval = TimeSpan.FromSeconds(5.0);

            _password             = StateService.Password;
            StateService.Password = null;

            _authorizationForm             = StateService.AuthorizationForm;
            StateService.AuthorizationForm = null;

            _secureValues             = StateService.SecureValues;
            StateService.SecureValues = null;

            if (_password != null)
            {
                PasswordEnabled = _password.IsAvailable;
                RecoveryEmailUnconfirmedVisibility = !TLString.IsNullOrEmpty(_password.EmailUnconfirmedPattern) || (_password is TLPassword && ((TLPassword)_password).HasRecovery.Value)
                    ? Visibility.Visible
                    : Visibility.Collapsed;
            }

            PropertyChanged += (o, e) =>
            {
                if (Property.NameEquals(e.PropertyName, () => PasswordEnabled) && !_suppressPasswordEnabled)
                {
                    if (PasswordEnabled)
                    {
                        ChangePassword();
                    }
                    else
                    {
                        ClearPassword();
                    }
                }
            };
        }
Exemple #9
0
        public PhoneNumberCodeViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            _passwordBase         = stateService.Password;
            stateService.Password = null;

            _authorizationForm             = stateService.AuthorizationForm;
            stateService.AuthorizationForm = null;

            _secureValues             = stateService.SecureValues;
            stateService.SecureValues = null;

            _secureType             = stateService.SecureType;
            stateService.SecureType = null;

            _secureRequiredType             = stateService.SecureRequiredType;
            stateService.SecureRequiredType = null;

            _phoneNumberValue = _secureRequiredType != null ? _secureRequiredType.DataValue : null;

            _type             = stateService.Type;
            stateService.Type = null;

            _nextType             = stateService.NextType;
            stateService.NextType = null;

            Subtitle = GetSubtitle();

            var length = _type as ILength;

            CodeLength = length != null ? length.Length.Value : Constants.DefaultCodeLength;

            Timeout = stateService.SendCallTimeout;
            ResendCodeVisibility = stateService.SendCallTimeout != null && stateService.SendCallTimeout.Value > 0
                ? Visibility.Collapsed
                : Visibility.Visible;

            SuppressUpdateStatus = true;

            EventAggregator.Subscribe(this);

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => Code))
                {
                    NotifyOfPropertyChange(() => CanConfirm);

                    if (!string.IsNullOrEmpty(Code) && Code.Length == CodeLength)
                    {
                        Confirm();
                    }
                }
            };

            _callTimer.Tick += (sender, args) =>
            {
                _timeCounter = Timeout == null? 0 : (int)(Timeout.Value - (DateTime.Now - _startTime).TotalSeconds);

                if (_timeCounter > 0)
                {
#if DEBUG
                    TimeCounterString = _timeCounter.ToString(CultureInfo.InvariantCulture);
#endif

                    if (_nextType is TLCodeTypeCall)
                    {
                        TimeCounterString = string.Format(AppResources.WeWillCallYou, TimeSpan.FromSeconds(TimeCounter).ToString(@"m\:ss"));
                    }
                }
                else
                {
                    _timeCounter = 0;
                    if (_nextType is TLCodeTypeCall)
                    {
                        TimeCounterString = AppResources.TelegramDialedYourNumber;
                    }

                    HelpVisibility       = Visibility.Visible;
                    ResendCodeVisibility = Visibility.Visible;
                    _callTimer.Stop();
                }

                NotifyOfPropertyChange(() => TimeCounter);
            };
        }
        public static void NavigateToPassportCommon(
            TLPasswordSettings passwordSettings, TLPassword passwordBase, TLString password,
            TLAuthorizationForm authorizationForm, IList <TLSecureValue> secureValues,
            IMTProtoService mtProtoService, IStateService stateService, INavigationService navigationService)
        {
            var passwordSettings83 = passwordSettings as TLPasswordSettings83;

            if (passwordSettings83 == null)
            {
                return;
            }

            var secureSettings = passwordSettings83.SecureSettings;

            passwordBase.Settings = passwordSettings83;

            var password84 = passwordBase as TLPassword84;

            if (password84 == null)
            {
                return;
            }

            var algo = password84.CurrentAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow;

            if (algo == null)
            {
                return;
            }

            //passwordBase.CurrentPasswordHash = Utils.Password.GetHash(passwordBase.CurrentSalt, password);
            var passwordHash = SRP.GetX(password, algo);

            passwordBase.CurrentPasswordHash = passwordHash;

            // create secure_secret
            if (secureSettings == null || TLString.IsNullOrEmpty(secureSettings.SecureSecret))
            {
                AddSecureSecret(passwordSettings, passwordBase, password, authorizationForm, secureValues, mtProtoService, stateService, navigationService);
                return;
            }

            var values = authorizationForm != null ? authorizationForm.Values : secureValues;

            if (values == null)
            {
                return;
            }

            var decrypted = SetSecretAndDecryptSecureValues(passwordSettings83, password, values);

            if (!decrypted)
            {
                Execute.BeginOnUIThread(() =>
                {
                    ShellViewModel.ShowCustomMessageBox(
                        AppResources.PassportDataCorrupted, AppResources.AppName,
                        AppResources.Reset, AppResources.Cancel,
                        dismissed =>
                    {
                        if (dismissed == CustomMessageBoxResult.RightButton)
                        {
                            ResetSecureSecret(passwordSettings, passwordBase, password, authorizationForm, secureValues, mtProtoService, stateService, navigationService);
                            values.Clear();
                        }
                    });
                });

                return;
            }

            stateService.RemoveBackEntry   = true;
            stateService.AuthorizationForm = authorizationForm;
            stateService.SecureValues      = secureValues;
            stateService.Password          = passwordBase;
            Execute.BeginOnUIThread(() =>
            {
                if (authorizationForm != null)
                {
                    navigationService.UriFor <PassportViewModel>().Navigate();
                }
                else if (secureValues != null)
                {
                    navigationService.UriFor <PassportSettingsViewModel>().Navigate();
                }
            });
        }