Esempio n. 1
0
        public async Task InitAsync()
        {
            _supportsBiometric = await _platformUtilsService.SupportsBiometricAsync();

            var lastSync = await _syncService.GetLastSyncAsync();

            if (lastSync != null)
            {
                lastSync      = lastSync.Value.ToLocalTime();
                _lastSyncDate = string.Format("{0} {1}", lastSync.Value.ToShortDateString(),
                                              lastSync.Value.ToShortTimeString());
            }
            var timeout = await _storageService.GetAsync <int?>(Constants.VaultTimeoutKey);

            _vaultTimeoutDisplayValue = _vaultTimeouts.FirstOrDefault(o => o.Value == timeout).Key;
            var action = await _storageService.GetAsync <string>(Constants.VaultTimeoutActionKey) ?? "lock";

            _vaultTimeoutActionDisplayValue = _vaultTimeoutActions.FirstOrDefault(o => o.Value == action).Key;
            var pinSet = await _vaultTimeoutService.IsPinLockSetAsync();

            _pin       = pinSet.Item1 || pinSet.Item2;
            _biometric = await _vaultTimeoutService.IsBiometricLockSetAsync();

            BuildList();
        }
Esempio n. 2
0
        public override void ViewDidLoad()
        {
            _vaultTimeoutService  = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            _cryptoService        = ServiceContainer.Resolve <ICryptoService>("cryptoService");
            _deviceActionService  = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _userService          = ServiceContainer.Resolve <IUserService>("userService");
            _storageService       = ServiceContainer.Resolve <IStorageService>("storageService");
            _secureStorageService = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _biometricService     = ServiceContainer.Resolve <IBiometricService>("biometricService");

            _pinSet        = _vaultTimeoutService.IsPinLockSetAsync().GetAwaiter().GetResult();
            _pinLock       = (_pinSet.Item1 && _vaultTimeoutService.PinProtectedKey != null) || _pinSet.Item2;
            _biometricLock = _vaultTimeoutService.IsBiometricLockSetAsync().GetAwaiter().GetResult() &&
                             _cryptoService.HasKeyAsync().GetAwaiter().GetResult();
            _biometricIntegrityValid = _biometricService.ValidateIntegrityAsync(BiometricIntegrityKey).GetAwaiter()
                                       .GetResult();

            BaseNavItem.Title      = _pinLock ? AppResources.VerifyPIN : AppResources.VerifyMasterPassword;
            BaseCancelButton.Title = AppResources.Cancel;
            BaseSubmitButton.Title = AppResources.Submit;

            var descriptor = UIFontDescriptor.PreferredBody;

            MasterPasswordCell.Label.Text = _pinLock ? AppResources.PIN : AppResources.MasterPassword;
            MasterPasswordCell.TextField.SecureTextEntry = true;
            MasterPasswordCell.TextField.ReturnKeyType   = UIReturnKeyType.Go;
            MasterPasswordCell.TextField.ShouldReturn   += (UITextField tf) =>
            {
                CheckPasswordAsync().GetAwaiter().GetResult();
                return(true);
            };
            if (_pinLock)
            {
                MasterPasswordCell.TextField.KeyboardType = UIKeyboardType.NumberPad;
            }

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 70;
            TableView.Source             = new TableSource(this);
            TableView.AllowsSelection    = true;

            base.ViewDidLoad();

            if (_biometricLock)
            {
                if (!_biometricIntegrityValid)
                {
                    return;
                }
                var tasks = Task.Run(async() =>
                {
                    await Task.Delay(500);
                    NSRunLoop.Main.BeginInvokeOnMainThread(async() => await PromptBiometricAsync());
                });
            }
        }
Esempio n. 3
0
        public async Task InitAsync()
        {
            _supportsBiometric = await _platformUtilsService.SupportsBiometricAsync();

            var lastSync = await _syncService.GetLastSyncAsync();

            if (lastSync != null)
            {
                lastSync      = lastSync.Value.ToLocalTime();
                _lastSyncDate = string.Format("{0} {1}",
                                              _localizeService.GetLocaleShortDate(lastSync.Value),
                                              _localizeService.GetLocaleShortTime(lastSync.Value));
            }

            if (await _policyService.PolicyAppliesToUser(PolicyType.MaximumVaultTimeout))
            {
                _vaultTimeoutPolicy = (await _policyService.GetAll(PolicyType.MaximumVaultTimeout)).First();
                var minutes = _policyService.GetPolicyInt(_vaultTimeoutPolicy, "minutes").GetValueOrDefault();
                _vaultTimeouts = _vaultTimeouts.Where(t =>
                                                      t.Value <= minutes &&
                                                      (t.Value > 0 || t.Value == CustomVaultTimeoutValue) &&
                                                      t.Value != null).ToList();
            }

            _vaultTimeout = await _vaultTimeoutService.GetVaultTimeout();

            _vaultTimeoutDisplayValue = _vaultTimeouts.FirstOrDefault(o => o.Value == _vaultTimeout).Key;
            var action = await _stateService.GetVaultTimeoutActionAsync() ?? VaultTimeoutAction.Lock;

            _vaultTimeoutActionDisplayValue = _vaultTimeoutActions.FirstOrDefault(o => o.Value == action).Key;
            var pinSet = await _vaultTimeoutService.IsPinLockSetAsync();

            _pin       = pinSet.Item1 || pinSet.Item2;
            _biometric = await _vaultTimeoutService.IsBiometricLockSetAsync();

            _screenCaptureAllowed = await _stateService.GetScreenCaptureAllowedAsync();

            if (_vaultTimeoutDisplayValue == null)
            {
                _vaultTimeoutDisplayValue = AppResources.Custom;
            }

            _showChangeMasterPassword = IncludeLinksWithSubscriptionInfo() &&
                                        !await _keyConnectorService.GetUsesKeyConnector();

            _reportLoggingEnabled = await _loggerService.IsEnabled();

            BuildList();
        }
Esempio n. 4
0
        public async Task InitAsync()
        {
            _supportsBiometric = await _platformUtilsService.SupportsBiometricAsync();

            var lastSync = await _syncService.GetLastSyncAsync();

            if (lastSync != null)
            {
                lastSync      = lastSync.Value.ToLocalTime();
                _lastSyncDate = string.Format("{0} {1}", lastSync.Value.ToShortDateString(),
                                              lastSync.Value.ToShortTimeString());
            }

            if (await _policyService.PolicyAppliesToUser(PolicyType.MaximumVaultTimeout))
            {
                _vaultTimeoutPolicy = (await _policyService.GetAll(PolicyType.MaximumVaultTimeout)).First();
                var minutes = _policyService.GetPolicyInt(_vaultTimeoutPolicy, "minutes").GetValueOrDefault();
                _vaultTimeouts = _vaultTimeouts.Where(t =>
                                                      t.Value <= minutes &&
                                                      (t.Value > 0 || t.Value == CustomVaultTimeoutValue) &&
                                                      t.Value != null).ToList();
            }

            _vaultTimeout = await _vaultTimeoutService.GetVaultTimeout();

            _vaultTimeoutDisplayValue = _vaultTimeouts.FirstOrDefault(o => o.Value == _vaultTimeout).Key;
            var action = await _storageService.GetAsync <string>(Constants.VaultTimeoutActionKey) ?? "lock";

            _vaultTimeoutActionDisplayValue = _vaultTimeoutActions.FirstOrDefault(o => o.Value == action).Key;
            var pinSet = await _vaultTimeoutService.IsPinLockSetAsync();

            _pin       = pinSet.Item1 || pinSet.Item2;
            _biometric = await _vaultTimeoutService.IsBiometricLockSetAsync();

            if (_vaultTimeoutDisplayValue == null)
            {
                _vaultTimeoutDisplayValue = AppResources.Custom;
            }

            BuildList();
        }
        public override async void ViewDidLoad()
        {
            _vaultTimeoutService  = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            _cryptoService        = ServiceContainer.Resolve <ICryptoService>("cryptoService");
            _deviceActionService  = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _stateService         = ServiceContainer.Resolve <IStateService>("stateService");
            _secureStorageService = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _biometricService     = ServiceContainer.Resolve <IBiometricService>("biometricService");
            _keyConnectorService  = ServiceContainer.Resolve <IKeyConnectorService>("keyConnectorService");
            _accountManager       = ServiceContainer.Resolve <IAccountsManager>("accountsManager");

            // We re-use the lock screen for autofill extension to verify master password
            // when trying to access protected items.
            if (autofillExtension && await _stateService.GetPasswordRepromptAutofillAsync())
            {
                _passwordReprompt      = true;
                _isPinProtected        = false;
                _isPinProtectedWithKey = false;
                _pinLock       = false;
                _biometricLock = false;
            }
            else
            {
                (_isPinProtected, _isPinProtectedWithKey) = await _vaultTimeoutService.IsPinLockSetAsync();

                _pinLock = (_isPinProtected && await _stateService.GetPinProtectedKeyAsync() != null) ||
                           _isPinProtectedWithKey;
                _biometricLock = await _vaultTimeoutService.IsBiometricLockSetAsync() &&
                                 await _cryptoService.HasKeyAsync();

                _biometricIntegrityValid = await _biometricService.ValidateIntegrityAsync(BiometricIntegrityKey);

                _usesKeyConnector = await _keyConnectorService.GetUsesKeyConnector();

                _biometricUnlockOnly = _usesKeyConnector && _biometricLock && !_pinLock;
            }

            if (_pinLock)
            {
                BaseNavItem.Title = AppResources.VerifyPIN;
            }
            else if (_usesKeyConnector)
            {
                BaseNavItem.Title = AppResources.UnlockVault;
            }
            else
            {
                BaseNavItem.Title = AppResources.VerifyMasterPassword;
            }

            BaseCancelButton.Title = AppResources.Cancel;

            if (_biometricUnlockOnly)
            {
                BaseSubmitButton.Title   = null;
                BaseSubmitButton.Enabled = false;
            }
            else
            {
                BaseSubmitButton.Title = AppResources.Submit;
            }

            var descriptor = UIFontDescriptor.PreferredBody;

            if (!_biometricUnlockOnly)
            {
                MasterPasswordCell.Label.Text = _pinLock ? AppResources.PIN : AppResources.MasterPassword;
                MasterPasswordCell.TextField.SecureTextEntry = true;
                MasterPasswordCell.TextField.ReturnKeyType   = UIReturnKeyType.Go;
                MasterPasswordCell.TextField.ShouldReturn   += (UITextField tf) =>
                {
                    CheckPasswordAsync().GetAwaiter().GetResult();
                    return(true);
                };
                if (_pinLock)
                {
                    MasterPasswordCell.TextField.KeyboardType = UIKeyboardType.NumberPad;
                }
                MasterPasswordCell.Button.TitleLabel.Font = UIFont.FromName("bwi-font", 28f);
                MasterPasswordCell.Button.SetTitle(BitwardenIcons.Eye, UIControlState.Normal);
                MasterPasswordCell.Button.TouchUpInside += (sender, e) =>
                {
                    MasterPasswordCell.TextField.SecureTextEntry = !MasterPasswordCell.TextField.SecureTextEntry;
                    MasterPasswordCell.Button.SetTitle(MasterPasswordCell.TextField.SecureTextEntry ? BitwardenIcons.Eye : BitwardenIcons.EyeSlash, UIControlState.Normal);
                };
            }

            if (TableView != null)
            {
                TableView.BackgroundColor    = ThemeHelpers.BackgroundColor;
                TableView.SeparatorColor     = ThemeHelpers.SeparatorColor;
                TableView.RowHeight          = UITableView.AutomaticDimension;
                TableView.EstimatedRowHeight = 70;
                TableView.Source             = new TableSource(this);
                TableView.AllowsSelection    = true;
            }

            base.ViewDidLoad();

            if (_biometricLock)
            {
                if (!_biometricIntegrityValid)
                {
                    return;
                }
                var tasks = Task.Run(async() =>
                {
                    await Task.Delay(500);
                    NSRunLoop.Main.BeginInvokeOnMainThread(async() => await PromptBiometricAsync());
                });
            }
        }
        public override async void ViewDidLoad()
        {
            _vaultTimeoutService  = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            _cryptoService        = ServiceContainer.Resolve <ICryptoService>("cryptoService");
            _deviceActionService  = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _userService          = ServiceContainer.Resolve <IUserService>("userService");
            _storageService       = ServiceContainer.Resolve <IStorageService>("storageService");
            _secureStorageService = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _biometricService     = ServiceContainer.Resolve <IBiometricService>("biometricService");
            _keyConnectorService  = ServiceContainer.Resolve <IKeyConnectorService>("keyConnectorService");

            // We re-use the lock screen for autofill extension to verify master password
            // when trying to access protected items.
            if (autofillExtension && await _storageService.GetAsync <bool>(Bit.Core.Constants.PasswordRepromptAutofillKey))
            {
                _passwordReprompt = true;
                _pinSet           = Tuple.Create(false, false);
                _pinLock          = false;
                _biometricLock    = false;
            }
            else
            {
                _pinSet        = _vaultTimeoutService.IsPinLockSetAsync().GetAwaiter().GetResult();
                _pinLock       = (_pinSet.Item1 && _vaultTimeoutService.PinProtectedKey != null) || _pinSet.Item2;
                _biometricLock = _vaultTimeoutService.IsBiometricLockSetAsync().GetAwaiter().GetResult() &&
                                 _cryptoService.HasKeyAsync().GetAwaiter().GetResult();
                _biometricIntegrityValid = _biometricService.ValidateIntegrityAsync(BiometricIntegrityKey).GetAwaiter()
                                           .GetResult();
                _usesKeyConnector = await _keyConnectorService.GetUsesKeyConnector();

                _biometricUnlockOnly = _usesKeyConnector && _biometricLock && !_pinLock;
            }

            if (_pinLock)
            {
                BaseNavItem.Title = AppResources.VerifyPIN;
            }
            else if (_usesKeyConnector)
            {
                BaseNavItem.Title = AppResources.UnlockVault;
            }
            else
            {
                BaseNavItem.Title = AppResources.VerifyMasterPassword;
            }

            BaseCancelButton.Title = AppResources.Cancel;

            if (_biometricUnlockOnly)
            {
                BaseSubmitButton.Title   = null;
                BaseSubmitButton.Enabled = false;
            }
            else
            {
                BaseSubmitButton.Title = AppResources.Submit;
            }

            var descriptor = UIFontDescriptor.PreferredBody;

            if (!_biometricUnlockOnly)
            {
                MasterPasswordCell.Label.Text = _pinLock ? AppResources.PIN : AppResources.MasterPassword;
                MasterPasswordCell.TextField.SecureTextEntry = true;
                MasterPasswordCell.TextField.ReturnKeyType   = UIReturnKeyType.Go;
                MasterPasswordCell.TextField.ShouldReturn   += (UITextField tf) =>
                {
                    CheckPasswordAsync().GetAwaiter().GetResult();
                    return(true);
                };
                if (_pinLock)
                {
                    MasterPasswordCell.TextField.KeyboardType = UIKeyboardType.NumberPad;
                }
                MasterPasswordCell.Button.TitleLabel.Font = UIFont.FromName("FontAwesome", 28f);
                MasterPasswordCell.Button.SetTitle("\uf06e", UIControlState.Normal);
                MasterPasswordCell.Button.TouchUpInside += (sender, e) => {
                    MasterPasswordCell.TextField.SecureTextEntry = !MasterPasswordCell.TextField.SecureTextEntry;
                    MasterPasswordCell.Button.SetTitle(MasterPasswordCell.TextField.SecureTextEntry ? "\uf06e" : "\uf070", UIControlState.Normal);
                };
            }

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 70;
            TableView.Source             = new TableSource(this);
            TableView.AllowsSelection    = true;

            base.ViewDidLoad();

            if (_biometricLock)
            {
                if (!_biometricIntegrityValid)
                {
                    return;
                }
                var tasks = Task.Run(async() =>
                {
                    await Task.Delay(500);
                    NSRunLoop.Main.BeginInvokeOnMainThread(async() => await PromptBiometricAsync());
                });
            }
        }