Пример #1
0
        public async Task UpdatePinAsync()
        {
            _pin = !_pin;
            if (_pin)
            {
                var pin = await _deviceActionService.DisplayPromptAync(AppResources.EnterPIN,
                                                                       AppResources.SetPINDescription, null, AppResources.Submit, AppResources.Cancel, true);

                if (!string.IsNullOrWhiteSpace(pin))
                {
                    var masterPassOnRestart = false;
                    if (!await _keyConnectorService.GetUsesKeyConnector())
                    {
                        masterPassOnRestart = await _platformUtilsService.ShowDialogAsync(
                            AppResources.PINRequireMasterPasswordRestart, AppResources.UnlockWithPIN,
                            AppResources.Yes, AppResources.No);
                    }

                    var kdf = await _stateService.GetKdfTypeAsync();

                    var kdfIterations = await _stateService.GetKdfIterationsAsync();

                    var email = await _stateService.GetEmailAsync();

                    var pinKey = await _cryptoService.MakePinKeyAysnc(pin, email,
                                                                      kdf.GetValueOrDefault(Core.Enums.KdfType.PBKDF2_SHA256),
                                                                      kdfIterations.GetValueOrDefault(5000));

                    var key = await _cryptoService.GetKeyAsync();

                    var pinProtectedKey = await _cryptoService.EncryptAsync(key.Key, pinKey);

                    if (masterPassOnRestart)
                    {
                        var encPin = await _cryptoService.EncryptAsync(pin);

                        await _stateService.SetProtectedPinAsync(encPin.EncryptedString);

                        await _stateService.SetPinProtectedKeyAsync(pinProtectedKey);
                    }
                    else
                    {
                        await _stateService.SetPinProtectedAsync(pinProtectedKey.EncryptedString);
                    }
                }
                else
                {
                    _pin = false;
                }
            }
            if (!_pin)
            {
                await _cryptoService.ClearPinProtectedKeyAsync();

                await _vaultTimeoutService.ClearAsync();
            }
            BuildList();
        }