feat(master-password): Master Password Service - Made changed to the request models and the master password service.

This commit is contained in:
Patrick Pimentel
2026-04-09 11:35:00 -04:00
parent 8385caee60
commit cb98256f16
6 changed files with 24 additions and 16 deletions

View File

@@ -669,6 +669,17 @@ public class AccountsController : Controller
throw new UnauthorizedAccessException();
}
var result;
if (model.RequestHasNewDataTypes())
{
result = await _tdeOffboardingPasswordCommand.UpdateTdeOffboardingPasswordAsync(user, model.UnlockData!.ToData(), model.AuthenticationData!.ToData(), model.MasterPasswordHint);
}
else
{
result = await _tdeOffboardingPasswordCommand.UpdateTdeOffboardingPasswordAsync(user, model.NewMasterPasswordHash, model.Key, model.MasterPasswordHint);
}
var result = await _tdeOffboardingPasswordCommand.UpdateTdeOffboardingPasswordAsync(user, model.NewMasterPasswordHash, model.Key, model.MasterPasswordHint);
if (result.Succeeded)
{

View File

@@ -5,11 +5,13 @@ namespace Bit.Api.Auth.Models.Request.Accounts;
public class PasswordRequestModel : SecretVerificationRequestModel
{
[Obsolete("To be removed in PM-33141")]
[StringLength(300)]
public string? NewMasterPasswordHash { get; set; }
[Obsolete("To be removed in PM-33141")]
public string? Key { get; set; }
[StringLength(50)]
public string? MasterPasswordHint { get; set; }
public string? Key { get; set; }
public MasterPasswordAuthenticationDataRequestModel? AuthenticationData { get; set; }
public MasterPasswordUnlockDataRequestModel? UnlockData { get; set; }

View File

@@ -1,7 +1,4 @@
// FIXME: Update this file to be null safe and then delete the line below
#nullable disable
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Bit.Api.Models.Request.Organizations;
namespace Bit.Api.Auth.Models.Request.Accounts;
@@ -9,5 +6,5 @@ namespace Bit.Api.Auth.Models.Request.Accounts;
public class UpdateTempPasswordRequestModel : OrganizationUserResetPasswordRequestModel
{
[StringLength(50)]
public string MasterPasswordHint { get; set; }
public string? MasterPasswordHint { get; set; }
}

View File

@@ -11,8 +11,8 @@ namespace Bit.Core.Auth.UserFeatures.TdeOffboardingPassword.Interfaces;
public interface ITdeOffboardingPasswordCommand
{
public Task<IdentityResult> UpdateTdeOffboardingPasswordAsync(User user, string masterPassword, string key,
string orgSsoIdentifier);
string masterPasswordHint);
public Task<IdentityResult> UpdateTdeOffboardingPasswordAsync(User user, MasterPasswordUnlockData unlockData,
MasterPasswordAuthenticationData authenticationData, string orgSsoIdentifier);
MasterPasswordAuthenticationData authenticationData, string masterPasswordHint);
}

View File

@@ -107,8 +107,8 @@ public interface IMasterPasswordService
/// Use when the caller controls persistence.
/// </summary>
/// <param name="user">
/// The user object to mutate. Must already have a master password; must not be a Key Connector
/// user. KDF parameters and salt must be unchanged relative to the values in
/// The user object to mutate. Will not update a master password salt. Must already have a master password;
/// must not be a Key Connector user. KDF parameters and salt must be unchanged relative to the values in
/// <paramref name="updateExistingData"/>. Validated via
/// <see cref="UpdateExistingPasswordData.ValidateDataForUser"/>.
/// </param>

View File

@@ -70,11 +70,8 @@ public class MasterPasswordService(
// Set salt on the user
user.MasterPasswordSalt = setInitialData.MasterPasswordUnlock.Salt;
// If we've passed in a hint then set it
if (setInitialData.MasterPasswordHint != null)
{
user.MasterPasswordHint = setInitialData.MasterPasswordHint;
}
// Always override the master password hint, even if it's null.
user.MasterPasswordHint = setInitialData.MasterPasswordHint;
// Update time markers on the user
var now = _timeProvider.GetUtcNow().UtcDateTime;
@@ -139,7 +136,8 @@ public class MasterPasswordService(
user.Key = updateExistingData.MasterPasswordUnlock.MasterKeyWrappedUserKey;
user.MasterPasswordSalt = updateExistingData.MasterPasswordUnlock.Salt;
// Always override the master password hint, even if it's null.
user.MasterPasswordHint = updateExistingData.MasterPasswordHint;
user.LastPasswordChangeDate = now;
user.RevisionDate = user.AccountRevisionDate = now;