1
0
mirror of https://github.com/bitwarden/server synced 2026-01-01 08:03:23 +00:00
This commit is contained in:
Bernd Schoolmann
2025-12-02 16:50:59 +01:00
parent b151506ed2
commit 9015bc8169
4 changed files with 22 additions and 21 deletions

View File

@@ -1,13 +1,9 @@
using Bit.Core.KeyManagement.Models.Api.Request;
using Bit.Core.KeyManagement.Repositories;
using Bit.Core.Repositories;
namespace Bit.Core.KeyManagement.Commands.Interfaces;
public interface ISetAccountKeysForUserCommand
{
Task SetAccountKeysForUserAsync(Guid userId,
AccountKeysRequestModel accountKeys,
IUserRepository userRepository,
IUserSignatureKeyPairRepository userSignatureKeyPairRepository);
AccountKeysRequestModel accountKeys);
}

View File

@@ -9,9 +9,19 @@ namespace Bit.Core.KeyManagement.Commands;
public class SetAccountKeysForUserCommand : ISetAccountKeysForUserCommand
{
public async Task SetAccountKeysForUserAsync(Guid userId, AccountKeysRequestModel accountKeys, IUserRepository userRepository, IUserSignatureKeyPairRepository userSignatureKeyPairRepository)
private readonly IUserRepository _userRepository;
private readonly IUserSignatureKeyPairRepository _userSignatureKeyPairRepository;
public SetAccountKeysForUserCommand(
IUserRepository userRepository,
IUserSignatureKeyPairRepository userSignatureKeyPairRepository)
{
var user = await userRepository.GetByIdAsync(userId);
_userRepository = userRepository;
_userSignatureKeyPairRepository = userSignatureKeyPairRepository;
}
public async Task SetAccountKeysForUserAsync(Guid userId, AccountKeysRequestModel accountKeys)
{
var user = await _userRepository.GetByIdAsync(userId);
if (user == null)
{
throw new ArgumentException("User not found", nameof(userId));
@@ -29,7 +39,7 @@ public class SetAccountKeysForUserCommand : ISetAccountKeysForUserCommand
user.SignedPublicKey = accountKeysData.PublicKeyEncryptionKeyPairData.SignedPublicKey;
user.SecurityState = accountKeysData.SecurityStateData.SecurityState;
user.SecurityVersion = accountKeysData.SecurityStateData.SecurityVersion;
await userSignatureKeyPairRepository.UpsertAsync(new UserSignatureKeyPair
await _userSignatureKeyPairRepository.UpsertAsync(new UserSignatureKeyPair
{
Id = CoreHelpers.GenerateComb(),
UserId = userId,
@@ -40,6 +50,6 @@ public class SetAccountKeysForUserCommand : ISetAccountKeysForUserCommand
RevisionDate = DateTime.UtcNow,
});
}
await userRepository.ReplaceAsync(user);
await _userRepository.ReplaceAsync(user);
}
}

View File

@@ -21,6 +21,7 @@ public static class KeyManagementServiceCollectionExtensions
{
services.AddScoped<IRegenerateUserAsymmetricKeysCommand, RegenerateUserAsymmetricKeysCommand>();
services.AddScoped<IChangeKdfCommand, ChangeKdfCommand>();
services.AddScoped<ISetAccountKeysForUserCommand, SetAccountKeysForUserCommand>();
}
private static void AddKeyManagementQueries(this IServiceCollection services)