Example #1
0
        public static void AddSecureSecret(TLString secret, TLPasswordInputSettings83 inputSettings, IPasswordSecret passwordSecret, TLString password)
        {
            var newSecureAlgo = passwordSecret.NewSecureAlgo as TLSecurePasswordKdfAlgoPBKDF2HMACSHA512iter100000;

            if (newSecureAlgo == null)
            {
                return;
            }

            TLString newSecureSalt;
            TLString newSecureSecret;
            TLLong   newSecureSecretId;

            Passport.EncryptSecret(out newSecureSecret, out newSecureSalt, out newSecureSecretId, secret, passwordSecret.SecretRandom, newSecureAlgo, password);

            inputSettings.NewSecureSettings = new TLSecureSecretSettings
            {
                SecureAlgo = new TLSecurePasswordKdfAlgoPBKDF2HMACSHA512iter100000 {
                    Salt = newSecureSalt
                },
                SecureSecret   = newSecureSecret,
                SecureSecretId = newSecureSecretId
            };

            //inputSettings.NewSecureSalt = newSecureSalt;
            //inputSettings.NewSecureSecret = newSecureSecret;
            //inputSettings.NewSecureSecretId = newSecureSecretId;
        }
Example #2
0
        public void Create()
        {
            if (_passwordBase == null)
            {
                return;
            }

            HasError = false;
            Error    = " ";

            if (string.IsNullOrEmpty(_password))
            {
                HasError = true;
                Error    = "invalid_password";
                return;
            }

            if (!string.Equals(_password, _confirmPassword))
            {
                HasError = true;
                Error    = "invalid_confirmpassword";
                return;
            }

            if (!ChangePasswordEmailViewModel.IsValidEmail(_recoveryEmail))
            {
                HasError = true;
                Error    = "invalid_email";
                return;
            }

            var password84 = _passwordBase as TLPassword84;

            if (password84 == null)
            {
                return;
            }

            var newAlgo = password84.NewAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow;

            if (newAlgo == null)
            {
                return;
            }

            Utils.Password.AddClientSalt(newAlgo);

            var newSettings = new TLPasswordInputSettings83
            {
                Flags           = new TLInt(0),
                NewAlgo         = newAlgo,
                NewPasswordHash = null,
                Hint            = TLString.Empty,
                Email           = new TLString(RecoveryEmail),
                NewPassword     = _password
            };

            UpdatePasswordSettings(password84, newSettings);
        }
        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 => { });
        }
        public void ChangeRecoveryEmail()
        {
            if (IsWorking)
            {
                return;
            }
            if (!CanChangeRecoveryEmail)
            {
                return;
            }

            var password84 = _passwordBase as TLPassword84;

            if (password84 == null)
            {
                return;
            }

            TLPasswordInputSettings newSettings;

            if (_newPasswordSettings != null)
            {
                newSettings       = _newPasswordSettings;
                newSettings.Email = new TLString(RecoveryEmail);
            }
            else
            {
                newSettings = new TLPasswordInputSettings83
                {
                    Flags = new TLInt(0),
                    Email = new TLString(RecoveryEmail)
                };
            }

            UpdatePasswordSettings(password84, newSettings);
        }
Example #5
0
        private void ClearPassword()
        {
            var password = _password as TLPassword84;

            if (password == null)
            {
                return;
            }

            IsWorking = true;
            BeginOnThreadPool(() =>
            {
                var newSettings = new TLPasswordInputSettings83
                {
                    Flags           = new TLInt(0),
                    NewAlgo         = new TLPasswordKdfAlgoUnknown(),
                    NewPasswordHash = TLString.Empty,
                    Hint            = TLString.Empty,
                    Email           = TLString.Empty
                };

                MTProtoService.GetPasswordAsync(
                    result1 =>
                {
                    var srpParams = result1 as IPasswordSRPParams;
                    if (srpParams == null)
                    {
                        BeginOnUIThread(() => IsWorking = false);
                        return;
                    }

                    var currentPasswordHash = password.CurrentPasswordHash ?? TLString.Empty;
                    MTProtoService.UpdatePasswordSettingsAsync(SRP.GetCheck(currentPasswordHash, srpParams.SRPId, srpParams.SRPB, srpParams.CurrentAlgo), newSettings,
                                                               result => BeginOnUIThread(() =>
                    {
                        StopTimer();

                        IsWorking      = false;
                        var noPassword = new TLPassword84
                        {
                            Flags = new TLInt(0),
                            EmailUnconfirmedPattern = TLString.Empty,
                            NewSecureSalt           = TLString.Empty,
                            SecretRandom            = TLString.Empty
                        };

                        var password81 = _password as TLPassword84;
                        if (password81 != null)
                        {
                            noPassword.NewAlgo       = password81.NewAlgo;
                            noPassword.NewSecureSalt = password81.NewSecureSalt;
                            noPassword.SecretRandom  = password81.SecretRandom;
                        }

                        _password = noPassword;
                        if (_password != null)
                        {
                            PasswordEnabled = _password.IsAvailable;
                            RecoveryEmailUnconfirmedVisibility = !TLString.IsNullOrEmpty(_password.EmailUnconfirmedPattern) || (_password is TLPassword && ((TLPassword)_password).HasRecovery.Value)
                                        ? Visibility.Visible
                                        : Visibility.Collapsed;
                            NotifyOfPropertyChange(() => RecoveryEmailLabel);
                            NotifyOfPropertyChange(() => CompletePasswordLabel);
                            NotifyOfPropertyChange(() => ChangePasswordVisibility);
                            NotifyOfPropertyChange(() => CompletePasswordVisibility);
                        }
                        EventAggregator.Publish(_password);
                    }),
                                                               error => BeginOnUIThread(() =>
                    {
                        IsWorking          = false;
                        var messageBuilder = new StringBuilder();
                        //messageBuilder.AppendLine(AppResources.ServerErrorMessage);
                        //messageBuilder.AppendLine();
                        messageBuilder.AppendLine("Method: account.updatePasswordSettings");
                        messageBuilder.AppendLine("Result: " + error);

                        if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD))
                        {
                            Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK));
                        }
                        else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL))
                        {
                            Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK));
                        }
                        else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST))
                        {
                            if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_HASH_INVALID))
                            {
                                Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                            }
                            else if (TLRPCError.TypeEquals(error, ErrorType.NEW_PASSWORD_BAD))
                            {
                                Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                            }
                            else if (TLRPCError.TypeEquals(error, ErrorType.NEW_SALT_INVALID))
                            {
                                Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                            }
                            else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_INVALID))
                            {
                                Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK));
                            }
                            else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_UNCONFIRMED))
                            {
                                Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                            }
                            else
                            {
                                Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                            }
                        }
                        else
                        {
                            Execute.ShowDebugMessage("account.updatePasswordSettings error " + error);
                        }
                    }));
                },
                    error1 => BeginOnUIThread(() =>
                {
                    IsWorking = false;
                }));
            });
        }
        public void ChangePassword()
        {
            if (!CanChangePassword)
            {
                return;
            }

            var password84 = _passwordBase as TLPassword84;

            if (password84 == null)
            {
                return;
            }

            var newAlgo = password84.NewAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow;

            if (newAlgo == null)
            {
                return;
            }

            Utils.Password.AddClientSalt(newAlgo);

            //var newPasswordHash = SRP.GetX(new TLString(_password), newAlgo);
            //var newPasswordInputHash = SRP.GetVBytes(new TLString(_password), newAlgo);
            //Utils.Password.GetHash(newSalt, new TLString(_password));

            var inputSettings = new TLPasswordInputSettings83
            {
                Flags           = new TLInt(0),
                NewAlgo         = newAlgo,
                NewPasswordHash = null,
                Hint            = TLString.Empty,
                NewPassword     = _password
            };

            // reencrypt secure_secret
            var passwordSecret = _passwordBase as IPasswordSecret;

            if (passwordSecret != null)
            {
                TLPasswordSettings83 passwordSettings = null;
                var password = _passwordBase as TLPassword81;
                if (password != null)
                {
                    passwordSettings = password.Settings as TLPasswordSettings83;
                }
                if (passwordSettings == null || passwordSettings.SecureSettings == null)
                {
                    Utils.Password.AddRandomSecureSecret(inputSettings, passwordSecret, new TLString(_password));
                }
                else
                {
                    var secret = Utils.Passport.DecryptSecureSecret(passwordSettings.SecureSettings.SecureSecret, new TLString(PasswordViewModel.Password), passwordSettings.SecureSettings.SecureAlgo);
                    Utils.Password.AddSecureSecret(secret, inputSettings, passwordSecret, new TLString(_password));
                }
            }

            PasswordViewModel.TempNewPassword = Password;

            StateService.Password            = _passwordBase;
            StateService.NewPasswordSettings = inputSettings;
            StateService.RemoveBackEntry     = true;
            StateService.AuthorizationForm   = _authorizationForm;
            StateService.SecureValues        = _secureValues;
            NavigationService.UriFor <ChangePasswordHintViewModel>().Navigate();

            return;
        }