1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-27 03:52:57 +02:00

[PM-6798] Fix account switch on autofill (#3106)

* PM-6798 Force state update when opening the Autofill extension

* PM-6798 Fix InitAppIfNeededAsync to be awaited and also ignored Fido2AuthenticatorException from logging them to AppCenter since they don't add much information and we're logging in other places what we need
This commit is contained in:
Federico Maccaroni 2024-03-25 12:17:40 -03:00 committed by GitHub
parent 27380abd89
commit 45641aadfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 11 deletions

View File

@ -186,6 +186,7 @@ namespace Bit.Core.Abstractions
Task<BwRegion?> GetActiveUserRegionAsync();
Task<BwRegion?> GetPreAuthRegionAsync();
Task SetPreAuthRegionAsync(BwRegion value);
Task ReloadStateAsync();
[Obsolete("Use GetPinKeyEncryptedUserKeyAsync instead, left for migration purposes")]
Task<string> GetPinProtectedAsync(string userId = null);
[Obsolete("Use SetPinKeyEncryptedUserKeyAsync instead, left for migration purposes")]

View File

@ -1688,6 +1688,11 @@ namespace Bit.Core.Services
await _storageService.SaveAsync(Constants.iOSExtensionActiveUserIdKey, userId);
}
public async Task ReloadStateAsync()
{
_state = await GetStateFromStorageAsync() ?? new State();
}
private async Task CheckStateAsync()
{
if (!_migrationChecked)
@ -1699,7 +1704,7 @@ namespace Bit.Core.Services
if (_state == null)
{
_state = await GetStateFromStorageAsync() ?? new State();
await ReloadStateAsync();
}
}

View File

@ -66,6 +66,10 @@ namespace Bit.iOS.Autofill
}
}
catch (Fido2AuthenticatorException)
{
CancelRequest(ASExtensionErrorCode.Failed);
}
catch (Exception ex)
{
OnProvidingCredentialException(ex);
@ -79,7 +83,7 @@ namespace Bit.iOS.Autofill
return;
}
InitAppIfNeeded();
await InitAppIfNeededAsync();
if (!await IsAuthed())
{
@ -174,7 +178,7 @@ namespace Bit.iOS.Autofill
private async Task ProvideCredentialWithoutUserInteractionAsync(ASPasskeyCredentialRequest passkeyCredentialRequest)
{
InitAppIfNeeded();
await InitAppIfNeededAsync();
await _stateService.Value.SetPasswordRepromptAutofillAsync(false);
await _stateService.Value.SetPasswordVerifiedAutofillAsync(false);
if (!await IsAuthed() || await IsLocked())

View File

@ -10,6 +10,7 @@ using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Bit.Core.Utilities.Fido2;
using Bit.iOS.Autofill.Models;
using Bit.iOS.Core.Utilities;
using Bit.iOS.Core.Views;
@ -46,7 +47,7 @@ namespace Bit.iOS.Autofill
{
try
{
InitAppIfNeeded();
InitAppIfNeededAsync().FireAndForget(ex => OnProvidingCredentialException(ex));
base.ViewDidLoad();
@ -77,7 +78,7 @@ namespace Bit.iOS.Autofill
{
try
{
InitAppIfNeeded();
await InitAppIfNeededAsync();
_context.ServiceIdentifiers = serviceIdentifiers;
if (serviceIdentifiers.Length > 0)
{
@ -209,7 +210,7 @@ namespace Bit.iOS.Autofill
{
try
{
InitAppIfNeeded();
await InitAppIfNeededAsync();
_context.Configuring = true;
_context.VaultUnlockedDuringThisSession = false;
@ -228,7 +229,7 @@ namespace Bit.iOS.Autofill
private async Task ProvideCredentialWithoutUserInteractionAsync(ASPasswordCredentialIdentity credentialIdentity)
{
InitAppIfNeeded();
await InitAppIfNeededAsync();
await _stateService.Value.SetPasswordRepromptAutofillAsync(false);
await _stateService.Value.SetPasswordVerifiedAutofillAsync(false);
if (!await IsAuthed() || await IsLocked())
@ -244,7 +245,7 @@ namespace Bit.iOS.Autofill
private async Task PrepareInterfaceToProvideCredentialAsync(Action<Context> updateContext)
{
InitAppIfNeeded();
await InitAppIfNeededAsync();
if (!await IsAuthed())
{
await _accountsManager.NavigateOnAccountChangeAsync(false);
@ -476,7 +477,7 @@ namespace Bit.iOS.Autofill
{
if (!string.IsNullOrWhiteSpace(decCipher.Login.Totp)
&&
(cipher.OrganizationUseTotp || await _stateService.Value.CanAccessPremiumAsync()))
(cipher.OrganizationUseTotp || await _stateService.Value.CanAccessPremiumAsync()))
{
totpCode = await ServiceContainer.Resolve<ITotpService>().GetCodeAsync(decCipher.Login.Totp);
}
@ -484,6 +485,10 @@ namespace Bit.iOS.Autofill
CompleteRequest(decCipher.Id, decCipher.Login.Username, decCipher.Login.Password, totpCode);
}
catch (Fido2AuthenticatorException)
{
CancelRequest(ASExtensionErrorCode.Failed);
}
catch (Exception ex)
{
OnProvidingCredentialException(ex);
@ -541,12 +546,14 @@ namespace Bit.iOS.Autofill
_nfcSession, out _nfcDelegate, out _accountsManager);
}
private void InitAppIfNeeded()
private async Task InitAppIfNeededAsync()
{
if (ServiceContainer.RegisteredServices == null || ServiceContainer.RegisteredServices.Count == 0)
{
InitApp();
await MainThread.InvokeOnMainThreadAsync(InitApp);
}
await _stateService.Value.ReloadStateAsync();
}
private void LaunchHomePage()