diff --git a/src/iOS.Autofill/LoginListViewController.cs b/src/iOS.Autofill/LoginListViewController.cs index 7d042e5ad..e6d0d71fa 100644 --- a/src/iOS.Autofill/LoginListViewController.cs +++ b/src/iOS.Autofill/LoginListViewController.cs @@ -6,6 +6,9 @@ using Bit.iOS.Core.Controllers; using Bit.App.Resources; using Bit.iOS.Core.Views; using Bit.iOS.Autofill.Utilities; +using Bit.iOS.Core.Utilities; +using Bit.Core.Utilities; +using Bit.Core.Abstractions; namespace Bit.iOS.Autofill { @@ -28,6 +31,14 @@ namespace Bit.iOS.Autofill TableView.EstimatedRowHeight = 44; TableView.Source = new TableSource(this); await ((TableSource)TableView.Source).LoadItemsAsync(); + + var storageService = ServiceContainer.Resolve("storageService"); + var needsAutofillReplacement = await storageService.GetAsync( + Core.Constants.AutofillNeedsIdentityReplacementKey); + if(needsAutofillReplacement.GetValueOrDefault()) + { + await ASHelpers.ReplaceAllIdentities(); + } } partial void CancelBarButton_Activated(UIBarButtonItem sender) diff --git a/src/iOS.Core/Constants.cs b/src/iOS.Core/Constants.cs index 50941c0bb..34378a72a 100644 --- a/src/iOS.Core/Constants.cs +++ b/src/iOS.Core/Constants.cs @@ -28,5 +28,7 @@ public const string UTTypeAppExtensionFillWebViewAction = "org.appextension.fill-webview-action"; public const string UTTypeAppExtensionFillBrowserAction = "org.appextension.fill-browser-action"; public const string UTTypeAppExtensionSetup = "com.8bit.bitwarden.extension-setup"; + + public const string AutofillNeedsIdentityReplacementKey = "autofillNeedsIdentityReplacement"; } } diff --git a/src/iOS.Core/Utilities/ASHelpers.cs b/src/iOS.Core/Utilities/ASHelpers.cs index 9fceec5e7..4d51763a7 100644 --- a/src/iOS.Core/Utilities/ASHelpers.cs +++ b/src/iOS.Core/Utilities/ASHelpers.cs @@ -12,9 +12,16 @@ namespace Bit.iOS.Core.Utilities { public static async Task ReplaceAllIdentities() { - var cipherService = ServiceContainer.Resolve("cipherService"); if(await AutofillEnabled()) { + var storageService = ServiceContainer.Resolve("storageService"); + var lockService = ServiceContainer.Resolve("lockService"); + if(await lockService.IsLockedAsync()) + { + await storageService.SaveAsync(Constants.AutofillNeedsIdentityReplacementKey, true); + return; + } + var cipherService = ServiceContainer.Resolve("cipherService"); var identities = new List(); var ciphers = await cipherService.GetAllDecryptedAsync(); foreach(var cipher in ciphers) @@ -28,6 +35,7 @@ namespace Bit.iOS.Core.Utilities if(identities.Any()) { await ASCredentialIdentityStore.SharedStore?.ReplaceCredentialIdentitiesAsync(identities.ToArray()); + await storageService.SaveAsync(Constants.AutofillNeedsIdentityReplacementKey, false); } } } diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index d6689cb87..26d56aed6 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -96,6 +96,15 @@ namespace Bit.iOS { ListenYubiKey((bool)message.Data); } + else if(message.Command == "unlocked") + { + var needsAutofillReplacement = await _storageService.GetAsync( + Core.Constants.AutofillNeedsIdentityReplacementKey); + if(needsAutofillReplacement.GetValueOrDefault()) + { + await ASHelpers.ReplaceAllIdentities(); + } + } else if(message.Command == "showAppExtension") { Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data));