From 3f31d78db1bac81dc134326d4f0481f975cdf462 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Thu, 18 Jan 2018 04:55:06 -0800 Subject: [PATCH] Add YubiKey keyboard support (#248) * App: Pages: Fix the YubiKey image source Signed-off-by: Alistair Francis * App: Allow YubiKey keyboard output on apps On Android and UWP it's possible to use the YubiKey to enter text instead of using the NFC. Allow people to do that. Signed-off-by: Alistair Francis * App: Pages: Enable YubiKey support on Windows platforms Windows platforms should always have YubiKey support. Signed-off-by: Alistair Francis --- src/App/Pages/LoginTwoFactorPage.cs | 29 +++++++++++++++------- src/App/Resources/AppResources.Designer.cs | 4 +-- src/App/Resources/AppResources.resx | 4 +-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/App/Pages/LoginTwoFactorPage.cs b/src/App/Pages/LoginTwoFactorPage.cs index b6d2f1835..3806cc77d 100644 --- a/src/App/Pages/LoginTwoFactorPage.cs +++ b/src/App/Pages/LoginTwoFactorPage.cs @@ -93,6 +93,12 @@ namespace Bit.App.Pages On = false }; + var continueToolbarItem = new ToolbarItem(AppResources.Continue, Helpers.ToolbarImage("ion_chevron_right.png"), async () => + { + var token = TokenCell?.Entry.Text.Trim().Replace(" ", ""); + await LogInAsync(token); + }, ToolbarItemOrder.Default, 0); + if(!_providerType.HasValue) { instruction.Text = AppResources.NoTwoStepAvailable; @@ -111,12 +117,6 @@ namespace Bit.App.Pages else if(_providerType.Value == TwoFactorProviderType.Authenticator || _providerType.Value == TwoFactorProviderType.Email) { - var continueToolbarItem = new ToolbarItem(AppResources.Continue, Helpers.ToolbarImage("login.png"), async () => - { - var token = TokenCell?.Entry.Text.Trim().Replace(" ", ""); - await LogInAsync(token); - }, ToolbarItemOrder.Default, 0); - var padding = Helpers.OnPlatform( iOS: new Thickness(15, 20), Android: new Thickness(15, 8), @@ -232,7 +232,7 @@ namespace Bit.App.Pages var image = new CachedImage { - Source = "yubikey", + Source = "yubikey.png", VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Center, WidthRequest = 266, @@ -240,9 +240,14 @@ namespace Bit.App.Pages Margin = new Thickness(0, 0, 0, 25) }; + TokenCell = new FormEntryCell("", imageSource: "lock"); + + TokenCell.Entry.ReturnType = ReturnType.Go; + var table = new TwoFactorTable( new TableSection(Helpers.GetEmptyTableSectionTitle()) { + TokenCell, RememberCell }); @@ -254,6 +259,7 @@ namespace Bit.App.Pages table.WrappingStackLayout = () => layout; scrollView.Content = layout; + ToolbarItems.Add(continueToolbarItem); Title = AppResources.YubiKeyTitle; Content = scrollView; @@ -270,6 +276,11 @@ namespace Bit.App.Pages { _deviceActionService.DismissKeyboard(); } + + if(TokenCell != null) + { + TokenCell.Entry.FocusWithDelay(); + } } private void InitEvents() @@ -312,7 +323,7 @@ namespace Bit.App.Pages { var nfcKey = _providers[TwoFactorProviderType.YubiKey].ContainsKey("Nfc") && (bool)_providers[TwoFactorProviderType.YubiKey]["Nfc"]; - if(_deviceInfoService.NfcEnabled && nfcKey) + if(_deviceInfoService.NfcEnabled && nfcKey || Device.RuntimePlatform == Device.UWP) { options.Add(AppResources.YubiKeyTitle); } @@ -453,7 +464,7 @@ namespace Bit.App.Pages break; case TwoFactorProviderType.YubiKey: var nfcKey = p.Value.ContainsKey("Nfc") && (bool)p.Value["Nfc"]; - if(!_deviceInfoService.NfcEnabled || !nfcKey) + if((!_deviceInfoService.NfcEnabled || !nfcKey) && Device.RuntimePlatform != Device.UWP) { continue; } diff --git a/src/App/Resources/AppResources.Designer.cs b/src/App/Resources/AppResources.Designer.cs index f175db098..d98da4586 100644 --- a/src/App/Resources/AppResources.Designer.cs +++ b/src/App/Resources/AppResources.Designer.cs @@ -3148,7 +3148,7 @@ namespace Bit.App.Resources { } /// - /// Looks up a localized string similar to Hold your YubiKey NEO against the back of the device to continue.. + /// Looks up a localized string similar to To continue, hold your YubiKey NEO against the back of the device or insert your YubiKey into your device's USB port, then touch its button.. /// public static string YubiKeyInstruction { get { @@ -3157,7 +3157,7 @@ namespace Bit.App.Resources { } /// - /// Looks up a localized string similar to YubiKey NEO Security Key. + /// Looks up a localized string similar to YubiKey Security Key. /// public static string YubiKeyTitle { get { diff --git a/src/App/Resources/AppResources.resx b/src/App/Resources/AppResources.resx index 52b665f9f..9d7f4c333 100644 --- a/src/App/Resources/AppResources.resx +++ b/src/App/Resources/AppResources.resx @@ -883,10 +883,10 @@ For 2FA - Hold your YubiKey NEO against the back of the device to continue. + To continue, hold your YubiKey NEO against the back of the device or insert your YubiKey into your device's USB port, then touch its button. - YubiKey NEO Security Key + YubiKey Security Key "YubiKey NEO" is the product name and should not be translated.