-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathTdeOnboardPasswordRequestModel.cs
More file actions
55 lines (46 loc) · 1.99 KB
/
Copy pathTdeOnboardPasswordRequestModel.cs
File metadata and controls
55 lines (46 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.ComponentModel.DataAnnotations;
using Bit.Api.KeyManagement.Models.Requests;
using Bit.Core.Auth.Models.Data;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;
namespace Bit.Api.Auth.Models.Request.Accounts;
public class TdeOnboardPasswordRequestModel : IValidatableObject
{
public required MasterPasswordAuthenticationDataRequestModel MasterPasswordAuthentication { get; set; }
public required MasterPasswordUnlockDataRequestModel MasterPasswordUnlock { get; set; }
[StringLength(50)]
public string? MasterPasswordHint { get; set; }
[Required]
public required string OrgIdentifier { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
// Validate Kdf
var authenticationKdf = MasterPasswordAuthentication.Kdf.ToData();
var unlockKdf = MasterPasswordUnlock.Kdf.ToData();
// Currently, KDF settings are not saved separately for authentication and unlock and must therefore be equal
if (!authenticationKdf.Equals(unlockKdf))
{
throw new BadRequestException("KDF settings must be equal for authentication and unlock.");
}
var authenticationValidationErrors = KdfSettingsValidator.Validate(authenticationKdf).ToList();
if (authenticationValidationErrors.Count != 0)
{
yield return authenticationValidationErrors.First();
}
var unlockValidationErrors = KdfSettingsValidator.Validate(unlockKdf).ToList();
if (unlockValidationErrors.Count != 0)
{
yield return unlockValidationErrors.First();
}
}
public TdeOnboardMasterPasswordDataModel ToData()
{
return new TdeOnboardMasterPasswordDataModel
{
MasterPasswordAuthentication = MasterPasswordAuthentication.ToData(),
MasterPasswordUnlock = MasterPasswordUnlock.ToData(),
OrgSsoIdentifier = OrgIdentifier,
MasterPasswordHint = MasterPasswordHint
};
}
}