mirror of
https://github.com/bitwarden/mobile
synced 2025-12-21 18:53:29 +00:00
[PS-2358] Add kdf configuration options (#2328)
* Implement kdf configuration * Remove unused import * Move kdf parameters to kdfConfiguration struct * Remove unused state migration service keys * Revert newline changes in PCLCryptoFunctionService * Update KdfConfiguration.cs * Add checks for argon2, clean statemigration service * Update constants * Clean up code * Further cleanup * Change KdfType to non-nullable in SetKeyConnectorKeyRequest --------- Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
This commit is contained in:
@@ -46,6 +46,8 @@ namespace Bit.Core.Models.Domain
|
||||
OrgIdentifier = copy.OrgIdentifier;
|
||||
KdfType = copy.KdfType;
|
||||
KdfIterations = copy.KdfIterations;
|
||||
KdfMemory = copy.KdfMemory;
|
||||
KdfParallelism = copy.KdfParallelism;
|
||||
EmailVerified = copy.EmailVerified;
|
||||
HasPremiumPersonally = copy.HasPremiumPersonally;
|
||||
AvatarColor = copy.AvatarColor;
|
||||
@@ -59,6 +61,8 @@ namespace Bit.Core.Models.Domain
|
||||
public string AvatarColor;
|
||||
public KdfType? KdfType;
|
||||
public int? KdfIterations;
|
||||
public int? KdfMemory;
|
||||
public int? KdfParallelism;
|
||||
public bool? EmailVerified;
|
||||
public bool? HasPremiumPersonally;
|
||||
}
|
||||
|
||||
27
src/Core/Models/Domain/KdfConfiguration.cs
Executable file
27
src/Core/Models/Domain/KdfConfiguration.cs
Executable file
@@ -0,0 +1,27 @@
|
||||
using Bit.Core;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Domain;
|
||||
public struct KdfConfig
|
||||
{
|
||||
public static KdfConfig Default = new KdfConfig(KdfType.PBKDF2_SHA256, 5000, null, null);
|
||||
public KdfConfig(KdfType? type, int? iterations, int? memory, int? parallelism)
|
||||
{
|
||||
Type = type;
|
||||
Iterations = iterations;
|
||||
Memory = memory;
|
||||
Parallelism = parallelism;
|
||||
}
|
||||
|
||||
public KdfConfig(Account.AccountProfile profile)
|
||||
{
|
||||
Type = profile.KdfType;
|
||||
Iterations = profile.KdfIterations;
|
||||
Memory = profile.KdfMemory;
|
||||
Parallelism = profile.KdfParallelism;
|
||||
}
|
||||
|
||||
public KdfType? Type { get; set; }
|
||||
public int? Iterations { get; set; }
|
||||
public int? Memory { get; set; }
|
||||
public int? Parallelism { get; set; }
|
||||
}
|
||||
@@ -15,6 +15,8 @@ namespace Bit.Core.Models.Request
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public KdfType? Kdf { get; set; }
|
||||
public int? KdfIterations { get; set; }
|
||||
public int? KdfMemory { get; set; }
|
||||
public int? KdfParallelism { get; set; }
|
||||
public string CaptchaResponse { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,18 @@ namespace Bit.Core.Models.Request
|
||||
public KeysRequest Keys { get; set; }
|
||||
public KdfType Kdf { get; set; }
|
||||
public int? KdfIterations { get; set; }
|
||||
public int? KdfMemory { get; set; }
|
||||
public int? KdfParallelism { get; set; }
|
||||
public string OrgIdentifier { get; set; }
|
||||
|
||||
public SetKeyConnectorKeyRequest(string key, KeysRequest keys,
|
||||
KdfType kdf, int? kdfIterations, string orgIdentifier)
|
||||
public SetKeyConnectorKeyRequest(string key, KeysRequest keys, KdfConfig kdfConfig, string orgIdentifier)
|
||||
{
|
||||
this.Key = key;
|
||||
this.Keys = keys;
|
||||
this.Kdf = kdf;
|
||||
this.KdfIterations = kdfIterations;
|
||||
this.Kdf = kdfConfig.Type.GetValueOrDefault(KdfType.PBKDF2_SHA256);
|
||||
this.KdfIterations = kdfConfig.Iterations;
|
||||
this.KdfMemory = kdfConfig.Memory;
|
||||
this.KdfParallelism = kdfConfig.Parallelism;
|
||||
this.OrgIdentifier = orgIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Bit.Core.Models.Request
|
||||
public KeysRequest Keys { get; set; }
|
||||
public KdfType Kdf { get; set; }
|
||||
public int KdfIterations { get; set; }
|
||||
public int? KdfMemory { get; set; }
|
||||
public int? KdfParallelism { get; set; }
|
||||
public string OrgIdentifier { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ namespace Bit.Core.Models.Response
|
||||
public string TwoFactorToken { get; set; }
|
||||
public KdfType Kdf { get; set; }
|
||||
public int? KdfIterations { get; set; }
|
||||
public int? KdfMemory { get; set; }
|
||||
public int? KdfParallelism { get; set; }
|
||||
public bool ForcePasswordReset { get; set; }
|
||||
public string KeyConnectorUrl { get; set; }
|
||||
[JsonIgnore]
|
||||
public KdfConfig KdfConfig => new KdfConfig(Kdf, KdfIterations, KdfMemory, KdfParallelism);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Bit.Core.Enums;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Response
|
||||
{
|
||||
@@ -6,5 +7,9 @@ namespace Bit.Core.Models.Response
|
||||
{
|
||||
public KdfType Kdf { get; set; }
|
||||
public int KdfIterations { get; set; }
|
||||
public int? KdfMemory { get; set; }
|
||||
public int? KdfParallelism { get; set; }
|
||||
[JsonIgnore]
|
||||
public KdfConfig KdfConfig => new KdfConfig(Kdf, KdfIterations, KdfMemory, KdfParallelism);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user