mirror of
https://github.com/bitwarden/server
synced 2026-01-02 08:33:48 +00:00
* Added MasterPasswordUnlock to UserDecryptionOptions as part of identity response * Implement support for authentication data and unlock data in kdf change * Extract to kdf command and add tests * Fix namespace * Delete empty file * Fix build * Clean up tests * Fix tests * Add comments * Cleanup * Cleanup * Cleanup * Clean-up and fix build * Address feedback; force new parameters on KDF change request * Clean-up and add tests * Re-add logger * Update logger to interface * Clean up, remove Kdf Request Model * Remove kdf request model tests * Fix types in test * Address feedback to rename request model and re-add tests * Fix namespace * Move comments * Rename InnerKdfRequestModel to KdfRequestModel --------- Co-authored-by: Maciej Zieniuk <mzieniuk@bitwarden.com>
44 lines
1.9 KiB
C#
44 lines
1.9 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.KeyManagement.Models.Data;
|
|
|
|
namespace Bit.Core.Utilities;
|
|
|
|
public static class KdfSettingsValidator
|
|
{
|
|
public static IEnumerable<ValidationResult> Validate(KdfType kdfType, int kdfIterations, int? kdfMemory, int? kdfParallelism)
|
|
{
|
|
switch (kdfType)
|
|
{
|
|
case KdfType.PBKDF2_SHA256:
|
|
if (!AuthConstants.PBKDF2_ITERATIONS.InsideRange(kdfIterations))
|
|
{
|
|
yield return new ValidationResult($"KDF iterations must be between {AuthConstants.PBKDF2_ITERATIONS.Min} and {AuthConstants.PBKDF2_ITERATIONS.Max}.");
|
|
}
|
|
break;
|
|
case KdfType.Argon2id:
|
|
if (!AuthConstants.ARGON2_ITERATIONS.InsideRange(kdfIterations))
|
|
{
|
|
yield return new ValidationResult($"Argon2 iterations must be between {AuthConstants.ARGON2_ITERATIONS.Min} and {AuthConstants.ARGON2_ITERATIONS.Max}.");
|
|
}
|
|
else if (!kdfMemory.HasValue || !AuthConstants.ARGON2_MEMORY.InsideRange(kdfMemory.Value))
|
|
{
|
|
yield return new ValidationResult($"Argon2 memory must be between {AuthConstants.ARGON2_MEMORY.Min}mb and {AuthConstants.ARGON2_MEMORY.Max}mb.");
|
|
}
|
|
else if (!kdfParallelism.HasValue || !AuthConstants.ARGON2_PARALLELISM.InsideRange(kdfParallelism.Value))
|
|
{
|
|
yield return new ValidationResult($"Argon2 parallelism must be between {AuthConstants.ARGON2_PARALLELISM.Min} and {AuthConstants.ARGON2_PARALLELISM.Max}.");
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<ValidationResult> Validate(KdfSettings settings)
|
|
{
|
|
return Validate(settings.KdfType, settings.Iterations, settings.Memory, settings.Parallelism);
|
|
}
|
|
}
|