Beispiel #1
0
        public async Task LockAsync(bool allowSoftLock = false, bool userInitiated = false, string userId = null)
        {
            var authed = await _stateService.IsAuthenticatedAsync(userId);

            if (!authed)
            {
                return;
            }

            var isActiveAccount = await _stateService.IsActiveAccountAsync(userId);

            if (userId == null)
            {
                userId = await _stateService.GetActiveUserIdAsync();
            }

            if (await _keyConnectorService.GetUsesKeyConnector())
            {
                var(isPinProtected, isPinProtectedWithKey) = await IsPinLockSetAsync(userId);

                var pinLock = (isPinProtected && await _stateService.GetPinProtectedKeyAsync(userId) != null) ||
                              isPinProtectedWithKey;

                if (!pinLock && !await IsBiometricLockSetAsync())
                {
                    await LogOutAsync(userInitiated, userId);

                    return;
                }
            }

            if (allowSoftLock)
            {
                var isBiometricLockSet = await IsBiometricLockSetAsync(userId);

                await _stateService.SetBiometricLockedAsync(isBiometricLockSet, userId);

                if (isBiometricLockSet)
                {
                    _lockedCallback?.Invoke(new Tuple <string, bool>(userId, userInitiated));
                    return;
                }
            }
            await Task.WhenAll(
                _cryptoService.ClearKeyAsync(userId),
                _cryptoService.ClearOrgKeysAsync(true, userId),
                _cryptoService.ClearKeyPairAsync(true, userId),
                _cryptoService.ClearEncKeyAsync(true, userId));

            if (isActiveAccount)
            {
                _folderService.ClearCache();
                await _cipherService.ClearCacheAsync();

                _collectionService.ClearCache();
                _searchService.ClearIndex();
            }
            _lockedCallback?.Invoke(new Tuple <string, bool>(userId, userInitiated));
        }
Beispiel #2
0
        public async Task LockAsync(bool allowSoftLock = false, bool userInitiated = false)
        {
            var authed = await _userService.IsAuthenticatedAsync();

            if (!authed)
            {
                return;
            }

            if (await _keyConnectorService.GetUsesKeyConnector())
            {
                var pinSet = await IsPinLockSetAsync();

                var pinLock = (pinSet.Item1 && PinProtectedKey != null) || pinSet.Item2;

                if (!pinLock && !await IsBiometricLockSetAsync())
                {
                    await LogOutAsync();

                    return;
                }
            }

            if (allowSoftLock)
            {
                BiometricLocked = await IsBiometricLockSetAsync();

                if (BiometricLocked)
                {
                    _messagingService.Send("locked", userInitiated);
                    _lockedCallback?.Invoke(userInitiated);
                    return;
                }
            }
            await Task.WhenAll(
                _cryptoService.ClearKeyAsync(),
                _cryptoService.ClearOrgKeysAsync(true),
                _cryptoService.ClearKeyPairAsync(true),
                _cryptoService.ClearEncKeyAsync(true));

            _folderService.ClearCache();
            await _cipherService.ClearCacheAsync();

            _collectionService.ClearCache();
            _searchService.ClearIndex();
            _messagingService.Send("locked", userInitiated);
            _lockedCallback?.Invoke(userInitiated);
        }
Beispiel #3
0
        public async Task LockAsync(bool allowSoftLock = false)
        {
            var authed = await _userService.IsAuthenticatedAsync();

            if (!authed)
            {
                return;
            }
            if (allowSoftLock)
            {
                var pinSet = await IsPinLockSetAsync();

                if (pinSet.Item1)
                {
                    PinLocked = true;
                }
                if (await IsFingerprintLockSetAsync())
                {
                    FingerprintLocked = true;
                }
                if (FingerprintLocked || PinLocked)
                {
                    _messagingService.Send("locked");
                    // TODO: locked callback?
                    return;
                }
            }
            await Task.WhenAll(
                _cryptoService.ClearKeyAsync(),
                _cryptoService.ClearOrgKeysAsync(true),
                _cryptoService.ClearKeyPairAsync(true),
                _cryptoService.ClearEncKeyAsync(true));

            _folderService.ClearCache();
            _cipherService.ClearCache();
            _collectionService.ClearCache();
            _searchService.ClearIndex();
            _messagingService.Send("locked");
            // TODO: locked callback?
        }