1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-25 12:05:59 +01:00

PM-5154 Added Fido2AuthenticationService to provide us a wrapper for the actual implementation

This commit is contained in:
Federico Maccaroni 2024-01-03 19:02:49 -03:00
parent 1eb9e5f8ea
commit dfb7a0621f
No known key found for this signature in database
GPG Key ID: 5D233F8F2B034536
8 changed files with 68 additions and 8 deletions

View File

@ -0,0 +1,9 @@
using Bit.Core.Utilities.Fido2;
namespace Bit.Core.Abstractions
{
public interface IFido2AuthenticationService
{
Task<Fido2AuthenticatorGetAssertionResult> GetAssertionAsync(Fido2AuthenticatorGetAssertionParams assertionParams);
}
}

View File

@ -73,6 +73,7 @@
<Folder Include="Utilities\Automation\" /> <Folder Include="Utilities\Automation\" />
<Folder Include="Utilities\Prompts\" /> <Folder Include="Utilities\Prompts\" />
<Folder Include="Resources\Localization\" /> <Folder Include="Resources\Localization\" />
<Folder Include="Utilities\Fido2\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MauiImage Include="Resources\Images\dotnet_bot.svg"> <MauiImage Include="Resources\Images\dotnet_bot.svg">
@ -100,4 +101,7 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Remove="Utilities\Fido2\" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,18 @@
using Bit.Core.Abstractions;
using Bit.Core.Utilities.Fido2;
namespace Bit.Core.Services
{
public class Fido2AuthenticationService : IFido2AuthenticationService
{
public Task<Fido2AuthenticatorGetAssertionResult> GetAssertionAsync(Fido2AuthenticatorGetAssertionParams assertionParams)
{
// TODO: IMPLEMENT this
return Task.FromResult(new Fido2AuthenticatorGetAssertionResult
{
AuthenticatorData = new byte[32],
Signature = new byte[8]
});
}
}
}

View File

@ -0,0 +1,12 @@
namespace Bit.Core.Utilities.Fido2
{
public class Fido2AuthenticatorGetAssertionParams
{
public string RpId { get; set; }
public string CredentialId { get; set; }
public string Counter { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace Bit.Core.Utilities.Fido2
{
public class Fido2AuthenticatorGetAssertionResult
{
public byte[] AuthenticatorData { get; set; }
public byte[] Signature { get; set; }
}
}

View File

@ -1,9 +1,6 @@
using System; using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Services; using Bit.Core.Services;
@ -118,6 +115,7 @@ namespace Bit.Core.Utilities
Register<IUsernameGenerationService>(usernameGenerationService); Register<IUsernameGenerationService>(usernameGenerationService);
Register<IDeviceTrustCryptoService>(deviceTrustCryptoService); Register<IDeviceTrustCryptoService>(deviceTrustCryptoService);
Register<IPasswordResetEnrollmentService>(passwordResetEnrollmentService); Register<IPasswordResetEnrollmentService>(passwordResetEnrollmentService);
Register<IFido2AuthenticationService>(new Fido2AuthenticationService());
} }
public static void Register<T>(string serviceName, T obj) public static void Register<T>(string serviceName, T obj)

View File

@ -25,7 +25,7 @@ namespace Bit.iOS.Autofill
await ProvideCredentialAsync(false); await ProvideCredentialAsync(false);
} }
public void CompleteAssertionRequest(CipherView cipherView) public async Task CompleteAssertionRequestAsync(CipherView cipherView)
{ {
if (!UIDevice.CurrentDevice.CheckSystemVersion(17, 0)) if (!UIDevice.CurrentDevice.CheckSystemVersion(17, 0))
{ {
@ -34,12 +34,19 @@ namespace Bit.iOS.Autofill
} }
// TODO: Generate the credential Signature and Auth data accordingly // TODO: Generate the credential Signature and Auth data accordingly
var fido2AssertionResult = await _fido2AuthService.Value.GetAssertionAsync(new Bit.Core.Utilities.Fido2.Fido2AuthenticatorGetAssertionParams
{
RpId = cipherView.Login.MainFido2Credential.RpId,
Counter = cipherView.Login.MainFido2Credential.Counter,
CredentialId = cipherView.Login.MainFido2Credential.CredentialId
});
CompleteAssertionRequest(new ASPasskeyAssertionCredential( CompleteAssertionRequest(new ASPasskeyAssertionCredential(
cipherView.Login.MainFido2Credential.UserHandle, cipherView.Login.MainFido2Credential.UserHandle,
cipherView.Login.MainFido2Credential.RpId, cipherView.Login.MainFido2Credential.RpId,
"TODO: Generate Signature", NSData.FromArray(fido2AssertionResult.Signature),
_context.PasskeyCredentialRequest?.ClientDataHash, _context.PasskeyCredentialRequest?.ClientDataHash,
"TODO: Generate Authenticator Data", NSData.FromArray(fido2AssertionResult.AuthenticatorData),
cipherView.Login.MainFido2Credential.CredentialId cipherView.Login.MainFido2Credential.CredentialId
)); ));
} }

View File

@ -29,6 +29,7 @@ namespace Bit.iOS.Autofill
private IAccountsManager _accountsManager; private IAccountsManager _accountsManager;
private readonly LazyResolve<IStateService> _stateService = new LazyResolve<IStateService>(); private readonly LazyResolve<IStateService> _stateService = new LazyResolve<IStateService>();
private readonly LazyResolve<IFido2AuthenticationService> _fido2AuthService = new LazyResolve<IFido2AuthenticationService>();
public CredentialProviderViewController(IntPtr handle) public CredentialProviderViewController(IntPtr handle)
: base(handle) : base(handle)
@ -411,7 +412,7 @@ namespace Bit.iOS.Autofill
if (_context.IsPasskey) if (_context.IsPasskey)
{ {
CompleteAssertionRequest(decCipher); await CompleteAssertionRequestAsync(decCipher);
return; return;
} }