From 8ade49c958c5a20ad12903b1d399843f9fb79925 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 12 Apr 2019 16:39:20 -0400 Subject: [PATCH] domains and view stubs --- src/Core/Models/Domain/Attachment.cs | 27 ++++------ src/Core/Models/Domain/Card.cs | 46 +++++++++++++++++ src/Core/Models/Domain/Identity.cs | 70 ++++++++++++++++++++++++++ src/Core/Models/Domain/Login.cs | 57 ++++++++++++++++++++- src/Core/Models/Domain/LoginUri.cs | 20 +++----- src/Core/Models/Domain/SecureNote.cs | 32 ++++++++++++ src/Core/Models/View/CardView.cs | 20 ++++++++ src/Core/Models/View/IdentityView.cs | 32 ++++++++++++ src/Core/Models/View/SecureNoteView.cs | 18 +++++++ 9 files changed, 292 insertions(+), 30 deletions(-) create mode 100644 src/Core/Models/Domain/Card.cs create mode 100644 src/Core/Models/Domain/Identity.cs create mode 100644 src/Core/Models/Domain/SecureNote.cs create mode 100644 src/Core/Models/View/CardView.cs create mode 100644 src/Core/Models/View/IdentityView.cs create mode 100644 src/Core/Models/View/SecureNoteView.cs diff --git a/src/Core/Models/Domain/Attachment.cs b/src/Core/Models/Domain/Attachment.cs index 69367ff58..1a262eb69 100644 --- a/src/Core/Models/Domain/Attachment.cs +++ b/src/Core/Models/Domain/Attachment.cs @@ -7,19 +7,21 @@ namespace Bit.Core.Models.Domain { public class Attachment : Domain { + private HashSet _map = new HashSet + { + "Id", + "Url", + "SizeName", + "FileName", + "Key" + }; + public Attachment() { } public Attachment(AttachmentData obj, bool alreadyEncrypted = false) { Size = obj.Size; - BuildDomainModel(this, obj, new HashSet - { - "Id", - "Url", - "SizeName", - "FileName", - "Key" - }, alreadyEncrypted, new HashSet { "Id", "Url", "SizeName" }); + BuildDomainModel(this, obj, _map, alreadyEncrypted, new HashSet { "Id", "Url", "SizeName" }); } public string Id { get; set; } @@ -45,14 +47,7 @@ namespace Bit.Core.Models.Domain { var a = new AttachmentData(); a.Size = Size; - BuildDataModel(this, a, new HashSet - { - "Id", - "Url", - "SizeName", - "FileName", - "Key" - }, new HashSet { "Id", "Url", "SizeName" }); + BuildDataModel(this, a, _map, new HashSet { "Id", "Url", "SizeName" }); return a; } } diff --git a/src/Core/Models/Domain/Card.cs b/src/Core/Models/Domain/Card.cs new file mode 100644 index 000000000..c53f1ec04 --- /dev/null +++ b/src/Core/Models/Domain/Card.cs @@ -0,0 +1,46 @@ +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class Card : Domain + { + private HashSet _map = new HashSet + { + "CardholderName", + "Brand", + "Number", + "ExpMonth", + "ExpYear", + "Code" + }; + + public Card() { } + + public Card(CardData obj, bool alreadyEncrypted = false) + { + BuildDomainModel(this, obj, _map, alreadyEncrypted); + } + + public CipherString CardholderName { get; set; } + public CipherString Brand { get; set; } + public CipherString Number { get; set; } + public CipherString ExpMonth { get; set; } + public CipherString ExpYear { get; set; } + public CipherString Code { get; set; } + + public Task DecryptAsync(string orgId) + { + return DecryptObjAsync(new CardView(this), this, _map, orgId); + } + + public CardData ToLoginUriData() + { + var c = new CardData(); + BuildDataModel(this, c, _map); + return c; + } + } +} diff --git a/src/Core/Models/Domain/Identity.cs b/src/Core/Models/Domain/Identity.cs new file mode 100644 index 000000000..3698d680c --- /dev/null +++ b/src/Core/Models/Domain/Identity.cs @@ -0,0 +1,70 @@ +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class Identity : Domain + { + private HashSet _map = new HashSet + { + "Title", + "FirstName", + "MiddleName", + "LastName", + "Address1", + "Address2", + "Address3", + "City", + "State", + "PostalCode", + "Country", + "Company", + "Email", + "Phone", + "SSN", + "Username", + "PassportNumber", + "LicenseNumber" + }; + + public Identity() { } + + public Identity(IdentityData obj, bool alreadyEncrypted = false) + { + BuildDomainModel(this, obj, _map, alreadyEncrypted); + } + + public CipherString Title { get; set; } + public CipherString FirstName { get; set; } + public CipherString MiddleName { get; set; } + public CipherString LastName { get; set; } + public CipherString Address1 { get; set; } + public CipherString Address2 { get; set; } + public CipherString Address3 { get; set; } + public CipherString City { get; set; } + public CipherString State { get; set; } + public CipherString PostalCode { get; set; } + public CipherString Country { get; set; } + public CipherString Company { get; set; } + public CipherString Email { get; set; } + public CipherString Phone { get; set; } + public CipherString SSN { get; set; } + public CipherString Username { get; set; } + public CipherString PassportNumber { get; set; } + public CipherString LicenseNumber { get; set; } + + public Task DecryptAsync(string orgId) + { + return DecryptObjAsync(new IdentityView(this), this, _map, orgId); + } + + public IdentityData ToLoginUriData() + { + var i = new IdentityData(); + BuildDataModel(this, i, _map); + return i; + } + } +} diff --git a/src/Core/Models/Domain/Login.cs b/src/Core/Models/Domain/Login.cs index 5c5c5c2aa..266a58f5f 100644 --- a/src/Core/Models/Domain/Login.cs +++ b/src/Core/Models/Domain/Login.cs @@ -1,15 +1,68 @@ -using System; +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System; using System.Collections.Generic; -using System.Text; +using System.Linq; +using System.Threading.Tasks; namespace Bit.Core.Models.Domain { public class Login : Domain { + public Login() { } + + public Login(LoginData obj, bool alreadyEncrypted = false) + { + PasswordRevisionDate = obj.PasswordRevisionDate; + Uris = obj.Uris?.Select(u => new LoginUri(u, alreadyEncrypted)).ToList(); + BuildDomainModel(this, obj, new HashSet + { + "Username", + "Password", + "Totp" + }, alreadyEncrypted); + } + public List Uris { get; set; } public CipherString Username { get; set; } public CipherString Password { get; set; } public DateTime? PasswordRevisionDate { get; set; } public CipherString Totp { get; set; } + + public async Task DecryptAsync(string orgId) + { + var view = await DecryptObjAsync(new LoginView(this), this, new HashSet + { + "Username", + "Password", + "Totp" + }, orgId); + if(Uris != null) + { + view.Uris = new List(); + foreach(var uri in Uris) + { + view.Uris.Add(await uri.DecryptAsync(orgId)); + } + } + return view; + } + + public LoginData ToLoginUriData() + { + var l = new LoginData(); + l.PasswordRevisionDate = PasswordRevisionDate; + BuildDataModel(this, l, new HashSet + { + "Username", + "Password", + "Totp" + }); + if(Uris?.Any() ?? false) + { + l.Uris = Uris.Select(u => u.ToLoginUriData()).ToList(); + } + return l; + } } } diff --git a/src/Core/Models/Domain/LoginUri.cs b/src/Core/Models/Domain/LoginUri.cs index 32f6b73bb..d6467e4a7 100644 --- a/src/Core/Models/Domain/LoginUri.cs +++ b/src/Core/Models/Domain/LoginUri.cs @@ -8,15 +8,17 @@ namespace Bit.Core.Models.Domain { public class LoginUri : Domain { + private HashSet _map = new HashSet + { + "Uri" + }; + public LoginUri() { } public LoginUri(LoginUriData obj, bool alreadyEncrypted = false) { Match = obj.Match; - BuildDomainModel(this, obj, new HashSet - { - "Uri" - }, alreadyEncrypted); + BuildDomainModel(this, obj, _map, alreadyEncrypted); } public CipherString Uri { get; set; } @@ -24,19 +26,13 @@ namespace Bit.Core.Models.Domain public Task DecryptAsync(string orgId) { - return DecryptObjAsync(new LoginUriView(this), this, new HashSet - { - "Uri" - }, orgId); + return DecryptObjAsync(new LoginUriView(this), this, _map, orgId); } public LoginUriData ToLoginUriData() { var u = new LoginUriData(); - BuildDataModel(this, u, new HashSet - { - "Uri" - }, new HashSet { "Match" }); + BuildDataModel(this, u, _map, new HashSet { "Match" }); return u; } } diff --git a/src/Core/Models/Domain/SecureNote.cs b/src/Core/Models/Domain/SecureNote.cs new file mode 100644 index 000000000..e45239db1 --- /dev/null +++ b/src/Core/Models/Domain/SecureNote.cs @@ -0,0 +1,32 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class SecureNote : Domain + { + public SecureNote() { } + + public SecureNote(SecureNoteData obj, bool alreadyEncrypted = false) + { + Type = obj.Type; + } + + public SecureNoteType Type { get; set; } + + public Task DecryptAsync(string orgId) + { + return Task.FromResult(new SecureNoteView(this)); + } + + public SecureNoteData ToLoginUriData() + { + return new SecureNoteData + { + Type = Type + }; + } + } +} diff --git a/src/Core/Models/View/CardView.cs b/src/Core/Models/View/CardView.cs new file mode 100644 index 000000000..02ccb5aaa --- /dev/null +++ b/src/Core/Models/View/CardView.cs @@ -0,0 +1,20 @@ +using Bit.Core.Models.Domain; + +namespace Bit.Core.Models.View +{ + public class CardView : View + { + public CardView() { } + + public CardView(Card c) { } + + public string Id { get; set; } + public string Url { get; set; } + public string Size { get; set; } + public string SizeName { get; set; } + public string FileName { get; set; } + public SymmetricCryptoKey Key { get; set; } + + // TODO + } +} diff --git a/src/Core/Models/View/IdentityView.cs b/src/Core/Models/View/IdentityView.cs new file mode 100644 index 000000000..e1c5dfff2 --- /dev/null +++ b/src/Core/Models/View/IdentityView.cs @@ -0,0 +1,32 @@ +using Bit.Core.Models.Domain; + +namespace Bit.Core.Models.View +{ + public class IdentityView : View + { + public IdentityView() { } + + public IdentityView(Identity i) { } + + public string Title { get; set; } + public string FirstName { get; set; } + public string MiddleName { get; set; } + public string LastName { get; set; } + public string Address1 { get; set; } + public string Address2 { get; set; } + public string Address3 { get; set; } + public string City { get; set; } + public string State { get; set; } + public string PostalCode { get; set; } + public string Country { get; set; } + public string Company { get; set; } + public string Email { get; set; } + public string Phone { get; set; } + public string SSN { get; set; } + public string Username { get; set; } + public string PassportNumber { get; set; } + public string LicenseNumber { get; set; } + + // TODO + } +} diff --git a/src/Core/Models/View/SecureNoteView.cs b/src/Core/Models/View/SecureNoteView.cs new file mode 100644 index 000000000..694f8ba6e --- /dev/null +++ b/src/Core/Models/View/SecureNoteView.cs @@ -0,0 +1,18 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Domain; + +namespace Bit.Core.Models.View +{ + public class SecureNoteView : View + { + public SecureNoteView() { } + + public SecureNoteView(SecureNote n) + { + Type = n.Type; + } + + public SecureNoteType Type { get; set; } + public string SubTitle => null; + } +}