mirror of
https://github.com/bitwarden/mobile
synced 2026-01-13 05:53:18 +00:00
* PM-6441 Implement passkeys User Verification * PM-6441 Reorganized UserVerificationMediatorService so everything is not in the same file * PM-6441 Fix Unit tests * PM-6441 Refactor UserVerification on Fido2Authenticator and Client services to be of an enum type so we can see which specific preference the RP sent and to be passed into the user verification mediator service to perform the correct flow depending on that. Also updated Unit tests. * PM-6441 Changed user verification logic a bit so if preference is Preferred and the app has the ability to verify the user then enforce required UV and fix issue on on Discouraged to take into account MP reprompt
58 lines
2.5 KiB
C#
58 lines
2.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Bit.Core.Abstractions;
|
|
using Bit.Core.Utilities.Fido2;
|
|
using Bit.iOS.Autofill.Models;
|
|
|
|
namespace Bit.iOS.Autofill
|
|
{
|
|
public class Fido2MakeCredentialUserInterface : IFido2MakeCredentialUserInterface
|
|
{
|
|
private readonly Func<Task> _ensureUnlockedVaultCallback;
|
|
private readonly Func<bool> _hasVaultBeenUnlockedInThisTransaction;
|
|
private readonly Context _context;
|
|
private readonly Action _onConfirmingNewCredential;
|
|
private readonly Func<string, Fido2UserVerificationPreference, Task<bool>> _verifyUserCallback;
|
|
|
|
public Fido2MakeCredentialUserInterface(Func<Task> ensureUnlockedVaultCallback,
|
|
Func<bool> hasVaultBeenUnlockedInThisTransaction,
|
|
Context context,
|
|
Action onConfirmingNewCredential,
|
|
Func<string, Fido2UserVerificationPreference, Task<bool>> verifyUserCallback)
|
|
{
|
|
_ensureUnlockedVaultCallback = ensureUnlockedVaultCallback;
|
|
_hasVaultBeenUnlockedInThisTransaction = hasVaultBeenUnlockedInThisTransaction;
|
|
_context = context;
|
|
_onConfirmingNewCredential = onConfirmingNewCredential;
|
|
_verifyUserCallback = verifyUserCallback;
|
|
}
|
|
|
|
public bool HasVaultBeenUnlockedInThisTransaction { get; private set; }
|
|
|
|
public async Task<(string CipherId, bool UserVerified)> ConfirmNewCredentialAsync(Fido2ConfirmNewCredentialParams confirmNewCredentialParams)
|
|
{
|
|
_context.PickCredentialForFido2CreationTcs?.SetCanceled();
|
|
_context.PickCredentialForFido2CreationTcs = new TaskCompletionSource<(string, bool?)>();
|
|
_context.PasskeyCreationParams = confirmNewCredentialParams;
|
|
|
|
_onConfirmingNewCredential();
|
|
|
|
var (cipherId, isUserVerified) = await _context.PickCredentialForFido2CreationTcs.Task;
|
|
|
|
var verified = isUserVerified ?? await _verifyUserCallback(cipherId, confirmNewCredentialParams.UserVerificationPreference);
|
|
|
|
return (cipherId, verified);
|
|
}
|
|
|
|
// iOS doesn't seem to provide the ExcludeCredentialDescriptorList so nothing to do here currently.
|
|
public Task InformExcludedCredentialAsync(string[] existingCipherIds) => Task.CompletedTask;
|
|
|
|
public async Task EnsureUnlockedVaultAsync()
|
|
{
|
|
await _ensureUnlockedVaultCallback();
|
|
|
|
HasVaultBeenUnlockedInThisTransaction = _hasVaultBeenUnlockedInThisTransaction();
|
|
}
|
|
}
|
|
}
|