From 9000474b5a2934aa4fb76d95de24c693a4686e2a Mon Sep 17 00:00:00 2001 From: Patrick Pimentel Date: Wed, 10 Dec 2025 17:47:12 -0500 Subject: [PATCH] fix(register): [PM-27084] Account Register Uses New Data Types - Added more comments and fixed up some long lines. --- .../Accounts/RegisterFinishRequestModel.cs | 24 ++++++++++++------- src/Core/Utilities/KdfSettingsValidator.cs | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Core/Auth/Models/Api/Request/Accounts/RegisterFinishRequestModel.cs b/src/Core/Auth/Models/Api/Request/Accounts/RegisterFinishRequestModel.cs index 3ef3e8fb68..7cc217cf84 100644 --- a/src/Core/Auth/Models/Api/Request/Accounts/RegisterFinishRequestModel.cs +++ b/src/Core/Auth/Models/Api/Request/Accounts/RegisterFinishRequestModel.cs @@ -25,23 +25,25 @@ public class RegisterFinishRequestModel : IValidatableObject public MasterPasswordAuthenticationData? MasterPasswordAuthenticationData { get; set; } public MasterPasswordUnlockData? MasterPasswordUnlockData { get; set; } - // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData + // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData) [StringLength(1000)] public string? MasterPasswordHash { get; set; } [StringLength(50)] public string? MasterPasswordHint { get; set; } - // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData + // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData) public string? UserSymmetricKey { get; set; } public required KeysRequestModel UserAsymmetricKeys { get; set; } - // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData + // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData) public KdfType? Kdf { get; set; } - // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData + // PM-28143 - Remove line below (made optional during migration to MasterPasswordUnlockData) public int? KdfIterations { get; set; } + // PM-28143 - Remove line below public int? KdfMemory { get; set; } + // PM-28143 - Remove line below public int? KdfParallelism { get; set; } public Guid? OrganizationUserId { get; set; } @@ -105,10 +107,16 @@ public class RegisterFinishRequestModel : IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { - var kdf = MasterPasswordUnlockData?.Kdf.KdfType ?? Kdf ?? throw new Exception($"{nameof(Kdf)} not found on RequestModel"); - var kdfIterations = MasterPasswordUnlockData?.Kdf.Iterations ?? KdfIterations ?? throw new Exception($"{nameof(KdfIterations)} not found on RequestModel"); - var kdfMemory = MasterPasswordUnlockData?.Kdf.Memory ?? KdfMemory; - var kdfParallelism = MasterPasswordUnlockData?.Kdf.Parallelism ?? KdfParallelism; + var kdf = MasterPasswordUnlockData?.Kdf.KdfType + ?? Kdf + ?? throw new Exception($"{nameof(Kdf)} not found on RequestModel"); + var kdfIterations = MasterPasswordUnlockData?.Kdf.Iterations + ?? KdfIterations + ?? throw new Exception($"{nameof(KdfIterations)} not found on RequestModel"); + var kdfMemory = MasterPasswordUnlockData?.Kdf.Memory + ?? KdfMemory; + var kdfParallelism = MasterPasswordUnlockData?.Kdf.Parallelism + ?? KdfParallelism; // PM-28143 - Remove line below in favor of using the unlock data. return KdfSettingsValidator.Validate(kdf, kdfIterations, kdfMemory, kdfParallelism); diff --git a/src/Core/Utilities/KdfSettingsValidator.cs b/src/Core/Utilities/KdfSettingsValidator.cs index 34241eda9f..be444d826d 100644 --- a/src/Core/Utilities/KdfSettingsValidator.cs +++ b/src/Core/Utilities/KdfSettingsValidator.cs @@ -6,6 +6,7 @@ namespace Bit.Core.Utilities; public static class KdfSettingsValidator { + // PM-28143 - Remove below when fixing ticket public static IEnumerable Validate(KdfType kdfType, int kdfIterations, int? kdfMemory, int? kdfParallelism) { switch (kdfType) @@ -36,6 +37,7 @@ public static class KdfSettingsValidator } } + // PM-28143 - Will be used in the referenced ticket. public static IEnumerable Validate(MasterPasswordUnlockData masterPasswordUnlockData) { switch (masterPasswordUnlockData.Kdf.KdfType)