コード例 #1
0
        private async Task LogOutAsync(bool expired)
        {
            var userId = await _userService.GetUserIdAsync();

            await Task.WhenAll(
                _syncService.SetLastSyncAsync(DateTime.MinValue),
                _tokenService.ClearTokenAsync(),
                _cryptoService.ClearKeysAsync(),
                _userService.ClearAsync(),
                _settingsService.ClearAsync(userId),
                _cipherService.ClearAsync(userId),
                _folderService.ClearAsync(userId),
                _collectionService.ClearAsync(userId),
                _passwordGenerationService.ClearAsync(),
                _vaultTimeoutService.ClearAsync(),
                _stateService.PurgeAsync(),
                _deviceActionService.ClearCacheAsync());

            _vaultTimeoutService.BiometricLocked = true;
            _searchService.ClearIndex();
            _authService.LogOut(() =>
            {
                Current.MainPage = new HomePage();
                if (expired)
                {
                    _platformUtilsService.ShowToast("warning", null, AppResources.LoginExpired);
                }
            });
        }
コード例 #2
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();
        }