1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-23 12:31:06 -05:00

encrypted string length attr

This commit is contained in:
Kyle Spearrin 2018-08-02 08:57:32 -04:00
parent 8393af9afc
commit 14956f6383
11 changed files with 56 additions and 36 deletions

View File

@ -19,22 +19,22 @@ namespace Bit.Core.Models.Api
} }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string CardholderName { get; set; } public string CardholderName { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Brand { get; set; } public string Brand { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Number { get; set; } public string Number { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string ExpMonth { get; set; } public string ExpMonth { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [StringLength(1000)]
public string ExpYear { get; set; } public string ExpYear { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Code { get; set; } public string Code { get; set; }
} }
} }

View File

@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api namespace Bit.Core.Models.Api
{ {
@ -16,9 +17,9 @@ namespace Bit.Core.Models.Api
} }
public FieldType Type { get; set; } public FieldType Type { get; set; }
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Name { get; set; } public string Name { get; set; }
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Value { get; set; } public string Value { get; set; }
} }
} }

View File

@ -31,58 +31,58 @@ namespace Bit.Core.Models.Api
} }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Title { get; set; } public string Title { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string FirstName { get; set; } public string FirstName { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string MiddleName { get; set; } public string MiddleName { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string LastName { get; set; } public string LastName { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [StringLength(1000)]
public string Address1 { get; set; } public string Address1 { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Address2 { get; set; } public string Address2 { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Address3 { get; set; } public string Address3 { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string City { get; set; } public string City { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string State { get; set; } public string State { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string PostalCode { get; set; } public string PostalCode { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Country { get; set; } public string Country { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Company { get; set; } public string Company { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Email { get; set; } public string Email { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Phone { get; set; } public string Phone { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string SSN { get; set; } public string SSN { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Username { get; set; } public string Username { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string PassportNumber { get; set; } public string PassportNumber { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string LicenseNumber { get; set; } public string LicenseNumber { get; set; }
} }
} }

View File

@ -27,7 +27,7 @@ namespace Bit.Core.Models.Api
} }
[EncryptedString] [EncryptedString]
[StringLength(10000)] [EncryptedStringLength(10000)]
public string Uri public string Uri
{ {
get => Uris?.FirstOrDefault()?.Uri; get => Uris?.FirstOrDefault()?.Uri;
@ -48,14 +48,14 @@ namespace Bit.Core.Models.Api
} }
public List<CipherLoginUriModel> Uris { get; set; } public List<CipherLoginUriModel> Uris { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Username { get; set; } public string Username { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Password { get; set; } public string Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; } public DateTime? PasswordRevisionDate { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Totp { get; set; } public string Totp { get; set; }
public class CipherLoginUriModel public class CipherLoginUriModel
@ -74,7 +74,7 @@ namespace Bit.Core.Models.Api
} }
[EncryptedString] [EncryptedString]
[StringLength(10000)] [EncryptedStringLength(10000)]
public string Uri { get; set; } public string Uri { get; set; }
public UriMatchType? Match { get; set; } = null; public UriMatchType? Match { get; set; } = null;
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api namespace Bit.Core.Models.Api
{ {
@ -14,7 +15,8 @@ namespace Bit.Core.Models.Api
LastUsedDate = data.LastUsedDate; LastUsedDate = data.LastUsedDate;
} }
[StringLength(2000)] [EncryptedString]
[EncryptedStringLength(2000)]
[Required] [Required]
public string Password { get; set; } public string Password { get; set; }
[Required] [Required]

View File

@ -22,10 +22,10 @@ namespace Bit.Core.Models.Api
public bool Favorite { get; set; } public bool Favorite { get; set; }
[Required] [Required]
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Name { get; set; } public string Name { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(10000)] [EncryptedStringLength(10000)]
public string Notes { get; set; } public string Notes { get; set; }
public IEnumerable<CipherFieldModel> Fields { get; set; } public IEnumerable<CipherFieldModel> Fields { get; set; }
public IEnumerable<CipherPasswordHistoryModel> PasswordHistory { get; set; } public IEnumerable<CipherPasswordHistoryModel> PasswordHistory { get; set; }

View File

@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
{ {
[Required] [Required]
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Name { get; set; } public string Name { get; set; }
public IEnumerable<SelectionReadOnlyRequestModel> Groups { get; set; } public IEnumerable<SelectionReadOnlyRequestModel> Groups { get; set; }

View File

@ -10,7 +10,7 @@ namespace Bit.Core.Models.Api
{ {
[Required] [Required]
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string Name { get; set; } public string Name { get; set; }
public Folder ToFolder(Guid userId) public Folder ToFolder(Guid userId)

View File

@ -8,7 +8,7 @@ namespace Bit.Core.Models.Api
[Required] [Required]
public string Key { get; set; } public string Key { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string CollectionName { get; set; } public string CollectionName { get; set; }
} }
} }

View File

@ -27,7 +27,7 @@ namespace Bit.Core.Models.Api
[Range(0, 99)] [Range(0, 99)]
public short? AdditionalStorageGb { get; set; } public short? AdditionalStorageGb { get; set; }
[EncryptedString] [EncryptedString]
[StringLength(1000)] [EncryptedStringLength(1000)]
public string CollectionName { get; set; } public string CollectionName { get; set; }
public string Country { get; set; } public string Country { get; set; }

View File

@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Utilities
{
public class EncryptedStringLengthAttribute : StringLengthAttribute
{
public EncryptedStringLengthAttribute(int maximumLength)
: base(maximumLength)
{ }
public override string FormatErrorMessage(string name)
{
return string.Format("The field {0} exceeds the maximum encrypted value length of {1} characters.",
name, MaximumLength);
}
}
}