mirror of
https://github.com/bitwarden/server
synced 2025-12-22 03:03:33 +00:00
Add support for V2 keys
This commit is contained in:
@@ -17,6 +17,7 @@ using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces;
|
|||||||
using Bit.Core.Auth.UserFeatures.UserMasterPassword.Interfaces;
|
using Bit.Core.Auth.UserFeatures.UserMasterPassword.Interfaces;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
|
using Bit.Core.KeyManagement.Commands;
|
||||||
using Bit.Core.KeyManagement.Kdf;
|
using Bit.Core.KeyManagement.Kdf;
|
||||||
using Bit.Core.KeyManagement.Queries.Interfaces;
|
using Bit.Core.KeyManagement.Queries.Interfaces;
|
||||||
using Bit.Core.Models.Api.Response;
|
using Bit.Core.Models.Api.Response;
|
||||||
@@ -44,6 +45,7 @@ public class AccountsController : Controller
|
|||||||
private readonly IUserAccountKeysQuery _userAccountKeysQuery;
|
private readonly IUserAccountKeysQuery _userAccountKeysQuery;
|
||||||
private readonly ITwoFactorEmailService _twoFactorEmailService;
|
private readonly ITwoFactorEmailService _twoFactorEmailService;
|
||||||
private readonly IChangeKdfCommand _changeKdfCommand;
|
private readonly IChangeKdfCommand _changeKdfCommand;
|
||||||
|
private readonly SetAccountKeysForUserCommand _setAccountKeysForUserCommand;
|
||||||
|
|
||||||
public AccountsController(
|
public AccountsController(
|
||||||
IOrganizationService organizationService,
|
IOrganizationService organizationService,
|
||||||
@@ -57,7 +59,8 @@ public class AccountsController : Controller
|
|||||||
IFeatureService featureService,
|
IFeatureService featureService,
|
||||||
IUserAccountKeysQuery userAccountKeysQuery,
|
IUserAccountKeysQuery userAccountKeysQuery,
|
||||||
ITwoFactorEmailService twoFactorEmailService,
|
ITwoFactorEmailService twoFactorEmailService,
|
||||||
IChangeKdfCommand changeKdfCommand
|
IChangeKdfCommand changeKdfCommand,
|
||||||
|
SetAccountKeysForUserCommand setAccountKeysForUserCommand
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_organizationService = organizationService;
|
_organizationService = organizationService;
|
||||||
@@ -72,6 +75,7 @@ public class AccountsController : Controller
|
|||||||
_userAccountKeysQuery = userAccountKeysQuery;
|
_userAccountKeysQuery = userAccountKeysQuery;
|
||||||
_twoFactorEmailService = twoFactorEmailService;
|
_twoFactorEmailService = twoFactorEmailService;
|
||||||
_changeKdfCommand = changeKdfCommand;
|
_changeKdfCommand = changeKdfCommand;
|
||||||
|
_setAccountKeysForUserCommand = setAccountKeysForUserCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -440,7 +444,15 @@ public class AccountsController : Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (model.AccountKeys != null)
|
||||||
|
{
|
||||||
|
await _setAccountKeysForUserCommand.SetAccountKeysForUserAsync(user.Id, model.AccountKeys);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
await _userService.SaveUserAsync(model.ToUser(user));
|
await _userService.SaveUserAsync(model.ToUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
return new KeysResponseModel(user);
|
return new KeysResponseModel(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,22 @@
|
|||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Bit.Core.Entities;
|
using Bit.Core.Entities;
|
||||||
|
using Bit.Core.KeyManagement.Models.Api.Request;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Core.Auth.Models.Api.Request.Accounts;
|
namespace Bit.Core.Auth.Models.Api.Request.Accounts;
|
||||||
|
|
||||||
public class KeysRequestModel
|
public class KeysRequestModel
|
||||||
{
|
{
|
||||||
|
[Obsolete("Use AccountKeys.AccountPublicKey instead")]
|
||||||
[Required]
|
[Required]
|
||||||
public string PublicKey { get; set; }
|
public string PublicKey { get; set; }
|
||||||
|
[Obsolete("Use AccountKeys.UserKeyEncryptedAccountPrivateKey instead")]
|
||||||
[Required]
|
[Required]
|
||||||
public string EncryptedPrivateKey { get; set; }
|
public string EncryptedPrivateKey { get; set; }
|
||||||
|
public AccountKeysRequestModel AccountKeys { get; set; }
|
||||||
|
|
||||||
|
[Obsolete("Use SetAccountKeysForUserCommand instead")]
|
||||||
public User ToUser(User existingUser)
|
public User ToUser(User existingUser)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(PublicKey) || string.IsNullOrWhiteSpace(EncryptedPrivateKey))
|
if (string.IsNullOrWhiteSpace(PublicKey) || string.IsNullOrWhiteSpace(EncryptedPrivateKey))
|
||||||
|
|||||||
Reference in New Issue
Block a user