Skip to content

Commit

Permalink
[PM-4167] feat: add support for storing PRF keys
Browse files Browse the repository at this point in the history
  • Loading branch information
coroiu committed Oct 6, 2023
1 parent e6f5534 commit 4b9b047
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Api/Auth/Controllers/WebAuthnController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task Post([FromBody] WebAuthnCredentialRequestModel model)
throw new BadRequestException("The token associated with your request is expired. A valid token is required to continue.");
}

var success = await _userService.CompleteWebAuthLoginRegistrationAsync(user, model.Name, model.SupportsPrf, tokenable.Options, model.DeviceResponse);
var success = await _userService.CompleteWebAuthLoginRegistrationAsync(user, model.Name, model.SupportsPrf, model.EncryptedUserKey, model.EncryptedPublicKey, model.EncryptedPrivateKey, tokenable.Options, model.DeviceResponse);
if (!success)
{
throw new BadRequestException("Unable to complete WebAuthn registration.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
using Fido2NetLib;

namespace Bit.Api.Auth.Models.Request.Webauthn;
Expand All @@ -16,5 +17,20 @@ public class WebAuthnCredentialRequestModel

[Required]
public bool SupportsPrf { get; set; }

[Required]
[EncryptedString]
[EncryptedStringLength(2000)]
public string EncryptedUserKey { get; set; }

[Required]
[EncryptedString]
[EncryptedStringLength(2000)]
public string EncryptedPublicKey { get; set; }

[Required]
[EncryptedString]
[EncryptedStringLength(2000)]
public string EncryptedPrivateKey { get; set; }
}

3 changes: 3 additions & 0 deletions src/Core/Auth/Entities/WebAuthnCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public class WebAuthnCredential : ITableObject<Guid>
[MaxLength(20)]
public string Type { get; set; }
public Guid AaGuid { get; set; }
[MaxLength(2000)]
public string EncryptedUserKey { get; set; }
[MaxLength(2000)]
public string EncryptedPrivateKey { get; set; }
[MaxLength(2000)]
public string EncryptedPublicKey { get; set; }
public bool SupportsPrf { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Services/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IUserService
Task<bool> DeleteWebAuthnKeyAsync(User user, int id);
Task<bool> CompleteWebAuthRegistrationAsync(User user, int value, string name, AuthenticatorAttestationRawResponse attestationResponse);
Task<CredentialCreateOptions> StartWebAuthnLoginRegistrationAsync(User user);
Task<bool> CompleteWebAuthLoginRegistrationAsync(User user, string name, bool supportsPrf, CredentialCreateOptions options, AuthenticatorAttestationRawResponse attestationResponse);
Task<bool> CompleteWebAuthLoginRegistrationAsync(User user, string name, bool supportsPrf, string encryptedUserKey, string encryptedPublicKey, string encryptedPrivateKey, CredentialCreateOptions options, AuthenticatorAttestationRawResponse attestationResponse);
Task<AssertionOptions> StartWebAuthnLoginAssertionAsync(User user);
Task<string> CompleteWebAuthLoginAssertionAsync(AuthenticatorAssertionRawResponse assertionResponse, User user);
Task SendEmailVerificationAsync(User user);
Expand Down
6 changes: 5 additions & 1 deletion src/Core/Services/Implementations/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ public async Task<CredentialCreateOptions> StartWebAuthnLoginRegistrationAsync(U
}

public async Task<bool> CompleteWebAuthLoginRegistrationAsync(User user, string name, bool supportsPrf,
string encryptedUserKey, string encryptedPublicKey, string encryptedPrivateKey,
CredentialCreateOptions options,
AuthenticatorAttestationRawResponse attestationResponse)
{
Expand All @@ -566,7 +567,10 @@ public async Task<bool> CompleteWebAuthLoginRegistrationAsync(User user, string
AaGuid = success.Result.Aaguid,
Counter = (int)success.Result.Counter,
UserId = user.Id,
SupportsPrf = supportsPrf
SupportsPrf = supportsPrf,
EncryptedUserKey = encryptedUserKey,
EncryptedPublicKey = encryptedPublicKey,
EncryptedPrivateKey = encryptedPrivateKey
};

await _webAuthnCredentialRepository.CreateAsync(credential);
Expand Down

0 comments on commit 4b9b047

Please sign in to comment.