From ff35e3c02297bf061ed4887fb9c26d9bdeca3f6b Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 23 Nov 2021 09:50:34 +1000 Subject: [PATCH] [Key Connector] Hide MP input in iOS extensions (#1656) * Hide MP on iOS unlock screen * Update navbar if using biometric auth only * Tidy up logic --- .../Controllers/LockPasswordViewController.cs | 128 ++++++++++++------ 1 file changed, 88 insertions(+), 40 deletions(-) diff --git a/src/iOS.Core/Controllers/LockPasswordViewController.cs b/src/iOS.Core/Controllers/LockPasswordViewController.cs index 63fbb6eb2..3fc88472a 100644 --- a/src/iOS.Core/Controllers/LockPasswordViewController.cs +++ b/src/iOS.Core/Controllers/LockPasswordViewController.cs @@ -34,6 +34,7 @@ namespace Bit.iOS.Core.Controllers private bool _biometricIntegrityValid = true; private bool _passwordReprompt = false; private bool _usesKeyConnector; + private bool _biometricUnlockOnly = false; protected bool autofillExtension = false; @@ -49,9 +50,33 @@ namespace Bit.iOS.Core.Controllers public FormEntryTableViewCell MasterPasswordCell { get; set; } = new FormEntryTableViewCell( AppResources.MasterPassword, useButton: true); - + public string BiometricIntegrityKey { get; set; } + public UITableViewCell BiometricCell + { + get + { + var cell = new UITableViewCell(); + if (_biometricIntegrityValid) + { + var biometricButtonText = _deviceActionService.SupportsFaceBiometric() ? + AppResources.UseFaceIDToUnlock : AppResources.UseFingerprintToUnlock; + cell.TextLabel.TextColor = ThemeHelpers.PrimaryColor; + cell.TextLabel.Text = biometricButtonText; + } + else + { + cell.TextLabel.TextColor = ThemeHelpers.DangerColor; + cell.TextLabel.Font = ThemeHelpers.GetDangerFont(); + cell.TextLabel.Lines = 0; + cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap; + cell.TextLabel.Text = AppResources.BiometricInvalidatedExtension; + } + return cell; + } + } + public override async void ViewDidLoad() { _vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); @@ -82,32 +107,57 @@ namespace Bit.iOS.Core.Controllers _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; } - BaseNavItem.Title = _pinLock ? AppResources.VerifyPIN : AppResources.VerifyMasterPassword; BaseCancelButton.Title = AppResources.Cancel; - BaseSubmitButton.Title = AppResources.Submit; + + if (_biometricUnlockOnly) + { + BaseSubmitButton.Title = null; + BaseSubmitButton.Enabled = false; + } + else + { + 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) => + if (!_biometricUnlockOnly) { - CheckPasswordAsync().GetAwaiter().GetResult(); - return true; - }; - if (_pinLock) - { - MasterPasswordCell.TextField.KeyboardType = UIKeyboardType.NumberPad; + 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); + }; } - 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; @@ -143,9 +193,6 @@ namespace Bit.iOS.Core.Controllers { MasterPasswordCell.TextField.BecomeFirstResponder(); } - - - } protected async Task CheckPasswordAsync() @@ -355,38 +402,34 @@ namespace Bit.iOS.Core.Controllers { if (indexPath.Row == 0) { - return _controller.MasterPasswordCell; + if (_controller._biometricUnlockOnly) + { + return _controller.BiometricCell; + } + else + { + return _controller.MasterPasswordCell; + } } } else if (indexPath.Section == 1) { if (indexPath.Row == 0) { - var cell = new ExtendedUITableViewCell(); if (_controller._passwordReprompt) { + var cell = new ExtendedUITableViewCell(); cell.TextLabel.TextColor = ThemeHelpers.DangerColor; cell.TextLabel.Font = ThemeHelpers.GetDangerFont(); cell.TextLabel.Lines = 0; cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap; cell.TextLabel.Text = AppResources.PasswordConfirmationDesc; + return cell; } - else if (_controller._biometricIntegrityValid) + else if (!_controller._biometricUnlockOnly) { - var biometricButtonText = _controller._deviceActionService.SupportsFaceBiometric() ? - AppResources.UseFaceIDToUnlock : AppResources.UseFingerprintToUnlock; - cell.TextLabel.TextColor = ThemeHelpers.PrimaryColor; - cell.TextLabel.Text = biometricButtonText; + return _controller.BiometricCell; } - else - { - cell.TextLabel.TextColor = ThemeHelpers.DangerColor; - cell.TextLabel.Font = ThemeHelpers.GetDangerFont(); - cell.TextLabel.Lines = 0; - cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap; - cell.TextLabel.Text = AppResources.BiometricInvalidatedExtension; - } - return cell; } } return new ExtendedUITableViewCell(); @@ -399,7 +442,10 @@ namespace Bit.iOS.Core.Controllers public override nint NumberOfSections(UITableView tableView) { - return _controller._biometricLock || _controller._passwordReprompt ? 2 : 1; + return (!_controller._biometricUnlockOnly && _controller._biometricLock) || + _controller._passwordReprompt + ? 2 + : 1; } public override nint RowsInSection(UITableView tableview, nint section) @@ -425,7 +471,9 @@ namespace Bit.iOS.Core.Controllers { tableView.DeselectRow(indexPath, true); tableView.EndEditing(true); - if (indexPath.Section == 1 && indexPath.Row == 0) + if (indexPath.Row == 0 && + ((_controller._biometricUnlockOnly && indexPath.Section == 0) || + indexPath.Section == 1)) { var task = _controller.PromptBiometricAsync(); return;