diff --git a/src/Core/Abstractions/IFido2AuthenticationService.cs b/src/Core/Abstractions/IFido2AuthenticationService.cs new file mode 100644 index 000000000..cf86ff79d --- /dev/null +++ b/src/Core/Abstractions/IFido2AuthenticationService.cs @@ -0,0 +1,9 @@ +using Bit.Core.Utilities.Fido2; + +namespace Bit.Core.Abstractions +{ + public interface IFido2AuthenticationService + { + Task GetAssertionAsync(Fido2AuthenticatorGetAssertionParams assertionParams); + } +} diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 7d3d10bf7..d82e3e339 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -73,6 +73,7 @@ + @@ -100,4 +101,7 @@ MSBuild:Compile + + + \ No newline at end of file diff --git a/src/Core/Services/Fido2AuthenticationService.cs b/src/Core/Services/Fido2AuthenticationService.cs new file mode 100644 index 000000000..2714320aa --- /dev/null +++ b/src/Core/Services/Fido2AuthenticationService.cs @@ -0,0 +1,18 @@ +using Bit.Core.Abstractions; +using Bit.Core.Utilities.Fido2; + +namespace Bit.Core.Services +{ + public class Fido2AuthenticationService : IFido2AuthenticationService + { + public Task GetAssertionAsync(Fido2AuthenticatorGetAssertionParams assertionParams) + { + // TODO: IMPLEMENT this + return Task.FromResult(new Fido2AuthenticatorGetAssertionResult + { + AuthenticatorData = new byte[32], + Signature = new byte[8] + }); + } + } +} diff --git a/src/Core/Utilities/Fido2/Fido2AuthenticatorGetAssertionParams.cs b/src/Core/Utilities/Fido2/Fido2AuthenticatorGetAssertionParams.cs new file mode 100644 index 000000000..ab6fe1e3a --- /dev/null +++ b/src/Core/Utilities/Fido2/Fido2AuthenticatorGetAssertionParams.cs @@ -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; } + } +} + diff --git a/src/Core/Utilities/Fido2/Fido2AuthenticatorGetAssertionResult.cs b/src/Core/Utilities/Fido2/Fido2AuthenticatorGetAssertionResult.cs new file mode 100644 index 000000000..845931143 --- /dev/null +++ b/src/Core/Utilities/Fido2/Fido2AuthenticatorGetAssertionResult.cs @@ -0,0 +1,11 @@ +using System; +namespace Bit.Core.Utilities.Fido2 +{ + public class Fido2AuthenticatorGetAssertionResult + { + public byte[] AuthenticatorData { get; set; } + + public byte[] Signature { get; set; } + } +} + diff --git a/src/Core/Utilities/ServiceContainer.cs b/src/Core/Utilities/ServiceContainer.cs index 7d3e32e3b..01b20cebc 100644 --- a/src/Core/Utilities/ServiceContainer.cs +++ b/src/Core/Utilities/ServiceContainer.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Globalization; using System.Text; -using System.Threading.Tasks; using Bit.Core.Abstractions; using Bit.Core.Services; @@ -118,6 +115,7 @@ namespace Bit.Core.Utilities Register(usernameGenerationService); Register(deviceTrustCryptoService); Register(passwordResetEnrollmentService); + Register(new Fido2AuthenticationService()); } public static void Register(string serviceName, T obj) diff --git a/src/iOS.Autofill/CredentialProviderViewController.Passkeys.cs b/src/iOS.Autofill/CredentialProviderViewController.Passkeys.cs index bcb40035a..3e06749ac 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.Passkeys.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.Passkeys.cs @@ -25,7 +25,7 @@ namespace Bit.iOS.Autofill await ProvideCredentialAsync(false); } - public void CompleteAssertionRequest(CipherView cipherView) + public async Task CompleteAssertionRequestAsync(CipherView cipherView) { if (!UIDevice.CurrentDevice.CheckSystemVersion(17, 0)) { @@ -34,12 +34,19 @@ namespace Bit.iOS.Autofill } // 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( cipherView.Login.MainFido2Credential.UserHandle, cipherView.Login.MainFido2Credential.RpId, - "TODO: Generate Signature", + NSData.FromArray(fido2AssertionResult.Signature), _context.PasskeyCredentialRequest?.ClientDataHash, - "TODO: Generate Authenticator Data", + NSData.FromArray(fido2AssertionResult.AuthenticatorData), cipherView.Login.MainFido2Credential.CredentialId )); } diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index a315feb78..432820510 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -29,6 +29,7 @@ namespace Bit.iOS.Autofill private IAccountsManager _accountsManager; private readonly LazyResolve _stateService = new LazyResolve(); + private readonly LazyResolve _fido2AuthService = new LazyResolve(); public CredentialProviderViewController(IntPtr handle) : base(handle) @@ -411,7 +412,7 @@ namespace Bit.iOS.Autofill if (_context.IsPasskey) { - CompleteAssertionRequest(decCipher); + await CompleteAssertionRequestAsync(decCipher); return; }