diff --git a/src/App/Enums/UriMatchType.cs b/src/App/Enums/UriMatchType.cs new file mode 100644 index 000000000..760db3be9 --- /dev/null +++ b/src/App/Enums/UriMatchType.cs @@ -0,0 +1,12 @@ +namespace Bit.App.Enums +{ + public enum UriMatchType : byte + { + Domain = 0, + Host = 1, + StartsWith = 2, + Exact = 3, + RegularExpression = 4, + Never = 5 + } +} diff --git a/src/App/Models/Api/CardDataModel.cs b/src/App/Models/Api/CardDataModel.cs deleted file mode 100644 index b19d73eb2..000000000 --- a/src/App/Models/Api/CardDataModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Bit.App.Models.Api -{ - public class CardDataModel : CipherDataModel - { - public string CardholderName { get; set; } - public string Brand { get; set; } - public string Number { get; set; } - public string ExpMonth { get; set; } - public string ExpYear { get; set; } - public string Code { get; set; } - } -} diff --git a/src/App/Models/Api/CardType.cs b/src/App/Models/Api/CardType.cs new file mode 100644 index 000000000..d32cfeeb5 --- /dev/null +++ b/src/App/Models/Api/CardType.cs @@ -0,0 +1,24 @@ +namespace Bit.App.Models.Api +{ + public class CardType + { + public CardType() { } + + public CardType(Cipher cipher) + { + CardholderName = cipher.Card.CardholderName?.EncryptedString; + Brand = cipher.Card.Brand?.EncryptedString; + Number = cipher.Card.Number?.EncryptedString; + ExpMonth = cipher.Card.ExpMonth?.EncryptedString; + ExpYear = cipher.Card.ExpYear?.EncryptedString; + Code = cipher.Card.Code?.EncryptedString; + } + + public string CardholderName { get; set; } + public string Brand { get; set; } + public string Number { get; set; } + public string ExpMonth { get; set; } + public string ExpYear { get; set; } + public string Code { get; set; } + } +} diff --git a/src/App/Models/Api/CipherDataModel.cs b/src/App/Models/Api/CipherDataModel.cs deleted file mode 100644 index 81dbf8d6c..000000000 --- a/src/App/Models/Api/CipherDataModel.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; - -namespace Bit.App.Models.Api -{ - public abstract class CipherDataModel - { - public string Name { get; set; } - public string Notes { get; set; } - public IEnumerable Fields { get; set; } - } -} diff --git a/src/App/Models/Api/FieldDataModel.cs b/src/App/Models/Api/FieldDataModel.cs deleted file mode 100644 index 1ee190a6c..000000000 --- a/src/App/Models/Api/FieldDataModel.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Bit.App.Enums; - -namespace Bit.App.Models.Api -{ - public class FieldDataModel - { - public FieldType Type { get; set; } - public string Name { get; set; } - public string Value { get; set; } - } -} diff --git a/src/App/Models/Api/FieldType.cs b/src/App/Models/Api/FieldType.cs new file mode 100644 index 000000000..d00f40b62 --- /dev/null +++ b/src/App/Models/Api/FieldType.cs @@ -0,0 +1,18 @@ +namespace Bit.App.Models.Api +{ + public class FieldType + { + public FieldType() { } + + public FieldType(Field field) + { + Type = field.Type; + Name = field.Name?.EncryptedString; + Value = field.Value?.EncryptedString; + } + + public Enums.FieldType Type { get; set; } + public string Name { get; set; } + public string Value { get; set; } + } +} diff --git a/src/App/Models/Api/IdentityDataModel.cs b/src/App/Models/Api/IdentityDataModel.cs deleted file mode 100644 index c49cda2de..000000000 --- a/src/App/Models/Api/IdentityDataModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Bit.App.Models.Api -{ - public class IdentityDataModel : CipherDataModel - { - 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; } - } -} diff --git a/src/App/Models/Api/IdentityType.cs b/src/App/Models/Api/IdentityType.cs new file mode 100644 index 000000000..f4819309c --- /dev/null +++ b/src/App/Models/Api/IdentityType.cs @@ -0,0 +1,48 @@ +namespace Bit.App.Models.Api +{ + public class IdentityType + { + public IdentityType() { } + + public IdentityType(Cipher cipher) + { + Title = cipher.Identity.Title?.EncryptedString; + FirstName = cipher.Identity.FirstName?.EncryptedString; + MiddleName = cipher.Identity.MiddleName?.EncryptedString; + LastName = cipher.Identity.LastName?.EncryptedString; + Address1 = cipher.Identity.Address1?.EncryptedString; + Address2 = cipher.Identity.Address2?.EncryptedString; + Address3 = cipher.Identity.Address3?.EncryptedString; + City = cipher.Identity.City?.EncryptedString; + State = cipher.Identity.State?.EncryptedString; + PostalCode = cipher.Identity.PostalCode?.EncryptedString; + Country = cipher.Identity.Country?.EncryptedString; + Company = cipher.Identity.Company?.EncryptedString; + Email = cipher.Identity.Email?.EncryptedString; + Phone = cipher.Identity.Phone?.EncryptedString; + SSN = cipher.Identity.SSN?.EncryptedString; + Username = cipher.Identity.Username?.EncryptedString; + PassportNumber = cipher.Identity.PassportNumber?.EncryptedString; + LicenseNumber = cipher.Identity.LicenseNumber?.EncryptedString; + } + + 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; } + } +} diff --git a/src/App/Models/Api/LoginDataModel.cs b/src/App/Models/Api/LoginDataModel.cs deleted file mode 100644 index 637822256..000000000 --- a/src/App/Models/Api/LoginDataModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bit.App.Models.Api -{ - public class LoginDataModel : CipherDataModel - { - public string Uri { get; set; } - public string Username { get; set; } - public string Password { get; set; } - public string Totp { get; set; } - } -} diff --git a/src/App/Models/Api/LoginType.cs b/src/App/Models/Api/LoginType.cs new file mode 100644 index 000000000..683cb79b8 --- /dev/null +++ b/src/App/Models/Api/LoginType.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Bit.App.Models.Api +{ + public class LoginType + { + public LoginType() { } + + public LoginType(Cipher cipher) + { + Uris = cipher.Login.Uris.Select(u => new LoginUriType(u)); + Username = cipher.Login.Username?.EncryptedString; + Password = cipher.Login.Password?.EncryptedString; + Totp = cipher.Login.Totp?.EncryptedString; + } + + public IEnumerable Uris { get; set; } + public string Username { get; set; } + public string Password { get; set; } + public string Totp { get; set; } + } +} diff --git a/src/App/Models/Api/LoginUriType.cs b/src/App/Models/Api/LoginUriType.cs new file mode 100644 index 000000000..fe6d7b52e --- /dev/null +++ b/src/App/Models/Api/LoginUriType.cs @@ -0,0 +1,18 @@ +using Bit.App.Enums; + +namespace Bit.App.Models.Api +{ + public class LoginUriType + { + public LoginUriType() { } + + public LoginUriType(LoginUri u) + { + Uri = u.Uri?.EncryptedString; + Match = u.Match; + } + + public string Uri { get; set; } + public UriMatchType? Match { get; set; } + } +} diff --git a/src/App/Models/Api/Request/CipherRequest.cs b/src/App/Models/Api/Request/CipherRequest.cs index 55aed604c..3e3353157 100644 --- a/src/App/Models/Api/Request/CipherRequest.cs +++ b/src/App/Models/Api/Request/CipherRequest.cs @@ -17,12 +17,7 @@ namespace Bit.App.Models.Api if(cipher.Fields != null) { - Fields = cipher.Fields.Select(f => new FieldDataModel - { - Name = f.Name?.EncryptedString, - Value = f.Value?.EncryptedString, - Type = f.Type - }); + Fields = cipher.Fields.Select(f => new FieldType(f)); } switch(Type) @@ -50,101 +45,11 @@ namespace Bit.App.Models.Api public bool Favorite { get; set; } public string Name { get; set; } public string Notes { get; set; } - public IEnumerable Fields { get; set; } + public IEnumerable Fields { get; set; } public LoginType Login { get; set; } public CardType Card { get; set; } public IdentityType Identity { get; set; } public SecureNoteType SecureNote { get; set; } - - public class LoginType - { - public LoginType(Cipher cipher) - { - Uri = cipher.Login.Uri?.EncryptedString; - Username = cipher.Login.Username?.EncryptedString; - Password = cipher.Login.Password?.EncryptedString; - Totp = cipher.Login.Totp?.EncryptedString; - } - - public string Uri { get; set; } - public string Username { get; set; } - public string Password { get; set; } - public string Totp { get; set; } - } - - public class CardType - { - public CardType(Cipher cipher) - { - CardholderName = cipher.Card.CardholderName?.EncryptedString; - Brand = cipher.Card.Brand?.EncryptedString; - Number = cipher.Card.Number?.EncryptedString; - ExpMonth = cipher.Card.ExpMonth?.EncryptedString; - ExpYear = cipher.Card.ExpYear?.EncryptedString; - Code = cipher.Card.Code?.EncryptedString; - } - - public string CardholderName { get; set; } - public string Brand { get; set; } - public string Number { get; set; } - public string ExpMonth { get; set; } - public string ExpYear { get; set; } - public string Code { get; set; } - } - - public class IdentityType - { - public IdentityType(Cipher cipher) - { - Title = cipher.Identity.Title?.EncryptedString; - FirstName = cipher.Identity.FirstName?.EncryptedString; - MiddleName = cipher.Identity.MiddleName?.EncryptedString; - LastName = cipher.Identity.LastName?.EncryptedString; - Address1 = cipher.Identity.Address1?.EncryptedString; - Address2 = cipher.Identity.Address2?.EncryptedString; - Address3 = cipher.Identity.Address3?.EncryptedString; - City = cipher.Identity.City?.EncryptedString; - State = cipher.Identity.State?.EncryptedString; - PostalCode = cipher.Identity.PostalCode?.EncryptedString; - Country = cipher.Identity.Country?.EncryptedString; - Company = cipher.Identity.Company?.EncryptedString; - Email = cipher.Identity.Email?.EncryptedString; - Phone = cipher.Identity.Phone?.EncryptedString; - SSN = cipher.Identity.SSN?.EncryptedString; - Username = cipher.Identity.Username?.EncryptedString; - PassportNumber = cipher.Identity.PassportNumber?.EncryptedString; - LicenseNumber = cipher.Identity.LicenseNumber?.EncryptedString; - } - - 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; } - } - - public class SecureNoteType - { - public SecureNoteType(Cipher cipher) - { - Type = cipher.SecureNote.Type; - } - - public Enums.SecureNoteType Type { get; set; } - } } } diff --git a/src/App/Models/Api/Response/CipherResponse.cs b/src/App/Models/Api/Response/CipherResponse.cs index 0dca96085..f9bf5a76c 100644 --- a/src/App/Models/Api/Response/CipherResponse.cs +++ b/src/App/Models/Api/Response/CipherResponse.cs @@ -1,6 +1,5 @@ using Bit.App.Enums; using System; -using Newtonsoft.Json.Linq; using System.Collections.Generic; namespace Bit.App.Models.Api @@ -15,7 +14,13 @@ namespace Bit.App.Models.Api public bool Favorite { get; set; } public bool Edit { get; set; } public bool OrganizationUseTotp { get; set; } - public JObject Data { get; set; } + public string Name { get; set; } + public string Notes { get; set; } + public LoginType Login { get; set; } + public CardType Card { get; set; } + public IdentityType Identity { get; set; } + public SecureNoteType SecureNote { get; set; } + public IEnumerable Fields { get; set; } public IEnumerable Attachments { get; set; } public IEnumerable CollectionIds { get; set; } public DateTime RevisionDate { get; set; } diff --git a/src/App/Models/Api/SecureNoteDataModel.cs b/src/App/Models/Api/SecureNoteDataModel.cs deleted file mode 100644 index 5e2e5ee12..000000000 --- a/src/App/Models/Api/SecureNoteDataModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Bit.App.Enums; - -namespace Bit.App.Models.Api -{ - public class SecureNoteDataModel : CipherDataModel - { - public SecureNoteType Type { get; set; } - } -} diff --git a/src/App/Models/Api/SecureNoteType.cs b/src/App/Models/Api/SecureNoteType.cs new file mode 100644 index 000000000..d904d6f98 --- /dev/null +++ b/src/App/Models/Api/SecureNoteType.cs @@ -0,0 +1,14 @@ +namespace Bit.App.Models.Api +{ + public class SecureNoteType + { + public SecureNoteType() { } + + public SecureNoteType(Cipher cipher) + { + Type = cipher.SecureNote.Type; + } + + public Enums.SecureNoteType Type { get; set; } + } +} diff --git a/src/App/Models/Card.cs b/src/App/Models/Card.cs index b6767d485..c46aa2275 100644 --- a/src/App/Models/Card.cs +++ b/src/App/Models/Card.cs @@ -1,6 +1,6 @@ -using Bit.App.Models.Api; -using Bit.App.Models.Data; +using Bit.App.Models.Data; using Newtonsoft.Json; +using System; namespace Bit.App.Models { @@ -10,7 +10,19 @@ namespace Bit.App.Models public Card(CipherData data) { - var deserializedData = JsonConvert.DeserializeObject(data.Data); + CardDataModel deserializedData; + if(data.Card != null) + { + deserializedData = JsonConvert.DeserializeObject(data.Card); + } + else if(data.Data != null) + { + deserializedData = JsonConvert.DeserializeObject(data.Data); + } + else + { + throw new ArgumentNullException(nameof(data.Card)); + } CardholderName = deserializedData.CardholderName != null ? new CipherString(deserializedData.CardholderName) : null; diff --git a/src/App/Models/Cipher.cs b/src/App/Models/Cipher.cs index be070303e..d36f92276 100644 --- a/src/App/Models/Cipher.cs +++ b/src/App/Models/Cipher.cs @@ -1,5 +1,4 @@ using Bit.App.Enums; -using Bit.App.Models.Api; using Bit.App.Models.Data; using Newtonsoft.Json; using System.Collections.Generic; diff --git a/src/App/Models/Data/CipherData.cs b/src/App/Models/Data/CipherData.cs index 717133472..46bd7f9ff 100644 --- a/src/App/Models/Data/CipherData.cs +++ b/src/App/Models/Data/CipherData.cs @@ -1,10 +1,10 @@ using System; using SQLite; using Bit.App.Abstractions; -using Bit.App.Models.Api; using Newtonsoft.Json; using System.Linq; using Bit.App.Enums; +using Bit.App.Models.Api; namespace Bit.App.Models.Data { @@ -26,46 +26,38 @@ namespace Bit.App.Models.Data OrganizationUseTotp = cipher.OrganizationUseTotp; RevisionDateTime = cipher.RevisionDate; Type = cipher.Type; - Data = JsonConvert.SerializeObject(cipher.Data); + Data = null; - CipherDataModel cipherData = null; switch(cipher.Type) { case CipherType.Login: - var loginData = cipher.Data.ToObject(); - cipherData = loginData; - - Uri = loginData.Uri; - Username = loginData.Username; - Password = loginData.Password; - Totp = loginData.Totp; + var loginData = new LoginDataModel(cipher); + Login = JsonConvert.SerializeObject(loginData); break; case CipherType.SecureNote: - var noteData = cipher.Data.ToObject(); - cipherData = noteData; - - SecureNoteType = noteData.Type; + var noteData = new SecureNoteDataModel(cipher); + SecureNote = JsonConvert.SerializeObject(noteData); break; case CipherType.Card: - var cardData = cipher.Data.ToObject(); - cipherData = cardData; + var cardData = new CardDataModel(cipher); + Card = JsonConvert.SerializeObject(cardData); break; case CipherType.Identity: - var idData = cipher.Data.ToObject(); - cipherData = idData; + var idData = new IdentityDataModel(cipher); + Identity = JsonConvert.SerializeObject(idData); break; default: throw new ArgumentException(nameof(cipher.Type)); } - Name = cipherData.Name; - Notes = cipherData.Notes; + Name = cipher.Name; + Notes = cipher.Notes; - if(cipherData.Fields != null && cipherData.Fields.Any()) + if(cipher.Fields != null && cipher.Fields.Any()) { try { - Fields = JsonConvert.SerializeObject(cipherData.Fields); + Fields = JsonConvert.SerializeObject(cipher.Fields.Select(f => new FieldDataModel(f))); } catch(JsonSerializationException) { } } @@ -80,21 +72,17 @@ namespace Bit.App.Models.Data public string Name { get; set; } public string Notes { get; set; } public string Fields { get; set; } + public string Login { get; set; } + public string Card { get; set; } + public string Identity { get; set; } + public string SecureNote { get; set; } public bool Favorite { get; set; } public bool Edit { get; set; } public bool OrganizationUseTotp { get; set; } public DateTime RevisionDateTime { get; set; } = DateTime.UtcNow; [Indexed] public CipherType Type { get; set; } = CipherType.Login; + [Obsolete] public string Data { get; set; } - - // Login metadata - public string Uri { get; set; } - public string Username { get; set; } - public string Password { get; set; } - public string Totp { get; set; } - - // Secure Note metadata - public SecureNoteType? SecureNoteType { get; set; } } } diff --git a/src/App/Models/Data/CipherData/CardDataModel.cs b/src/App/Models/Data/CipherData/CardDataModel.cs new file mode 100644 index 000000000..5a53bbf99 --- /dev/null +++ b/src/App/Models/Data/CipherData/CardDataModel.cs @@ -0,0 +1,33 @@ +using Bit.App.Models.Api; +using System; + +namespace Bit.App.Models.Data +{ + public class CardDataModel : CipherDataModel + { + public CardDataModel() { } + + public CardDataModel(CipherResponse response) + : base(response) + { + if(response?.Card == null) + { + throw new ArgumentNullException(nameof(response.Card)); + } + + CardholderName = response.Card.CardholderName; + Brand = response.Card.Brand; + Number = response.Card.Number; + ExpMonth = response.Card.ExpMonth; + ExpYear = response.Card.ExpYear; + Code = response.Card.Code; + } + + public string CardholderName { get; set; } + public string Brand { get; set; } + public string Number { get; set; } + public string ExpMonth { get; set; } + public string ExpYear { get; set; } + public string Code { get; set; } + } +} diff --git a/src/App/Models/Data/CipherData/CipherDataModel.cs b/src/App/Models/Data/CipherData/CipherDataModel.cs new file mode 100644 index 000000000..27a958d7b --- /dev/null +++ b/src/App/Models/Data/CipherData/CipherDataModel.cs @@ -0,0 +1,22 @@ +using Bit.App.Models.Api; +using System.Collections.Generic; +using System.Linq; + +namespace Bit.App.Models.Data +{ + public abstract class CipherDataModel + { + public CipherDataModel() { } + + public CipherDataModel(CipherResponse cipher) + { + Name = cipher.Name; + Notes = cipher.Notes; + Fields = cipher.Fields.Select(f => new FieldDataModel(f)); + } + + public string Name { get; set; } + public string Notes { get; set; } + public IEnumerable Fields { get; set; } + } +} diff --git a/src/App/Models/Data/CipherData/FieldDataModel.cs b/src/App/Models/Data/CipherData/FieldDataModel.cs new file mode 100644 index 000000000..831d2798c --- /dev/null +++ b/src/App/Models/Data/CipherData/FieldDataModel.cs @@ -0,0 +1,20 @@ +using Bit.App.Models.Api; + +namespace Bit.App.Models.Data +{ + public class FieldDataModel + { + public FieldDataModel() { } + + public FieldDataModel(FieldType f) + { + Type = f.Type; + Name = f.Name; + Value = f.Value; + } + + public Enums.FieldType Type { get; set; } + public string Name { get; set; } + public string Value { get; set; } + } +} diff --git a/src/App/Models/Data/CipherData/IdentityDataModel.cs b/src/App/Models/Data/CipherData/IdentityDataModel.cs new file mode 100644 index 000000000..825184a91 --- /dev/null +++ b/src/App/Models/Data/CipherData/IdentityDataModel.cs @@ -0,0 +1,57 @@ +using Bit.App.Models.Api; +using System; + +namespace Bit.App.Models.Data +{ + public class IdentityDataModel : CipherDataModel + { + public IdentityDataModel() { } + + public IdentityDataModel(CipherResponse response) + : base(response) + { + if(response?.Identity == null) + { + throw new ArgumentNullException(nameof(response.Card)); + } + + Title = response.Identity.Title; + FirstName = response.Identity.FirstName; + MiddleName = response.Identity.MiddleName; + LastName = response.Identity.LastName; + Address1 = response.Identity.Address1; + Address2 = response.Identity.Address2; + Address3 = response.Identity.Address3; + City = response.Identity.City; + State = response.Identity.State; + PostalCode = response.Identity.PostalCode; + Country = response.Identity.Country; + Company = response.Identity.Company; + Email = response.Identity.Email; + Phone = response.Identity.Phone; + SSN = response.Identity.SSN; + Username = response.Identity.Username; + PassportNumber = response.Identity.PassportNumber; + LicenseNumber = response.Identity.LicenseNumber; + } + + 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; } + } +} diff --git a/src/App/Models/Data/CipherData/LoginDataModel.cs b/src/App/Models/Data/CipherData/LoginDataModel.cs new file mode 100644 index 000000000..6316306d8 --- /dev/null +++ b/src/App/Models/Data/CipherData/LoginDataModel.cs @@ -0,0 +1,38 @@ +using Bit.App.Models.Api; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Bit.App.Models.Data +{ + public class LoginDataModel : CipherDataModel + { + private string _uri; + + public LoginDataModel() { } + + public LoginDataModel(CipherResponse response) + : base(response) + { + if(response?.Login == null) + { + throw new ArgumentNullException(nameof(response.Card)); + } + + Uris = response.Login.Uris?.Where(u => u != null).Select(u => new LoginUriDataModel(u)); + Username = response.Login.Username; + Password = response.Login.Password; + Totp = response.Login.Totp; + } + + public string Uri + { + get => Uris?.FirstOrDefault()?.Uri ?? _uri; + set { _uri = value; } + } + public IEnumerable Uris { get; set; } + public string Username { get; set; } + public string Password { get; set; } + public string Totp { get; set; } + } +} diff --git a/src/App/Models/Data/CipherData/LoginUriDataModel.cs b/src/App/Models/Data/CipherData/LoginUriDataModel.cs new file mode 100644 index 000000000..abac5cdc2 --- /dev/null +++ b/src/App/Models/Data/CipherData/LoginUriDataModel.cs @@ -0,0 +1,19 @@ +using Bit.App.Enums; +using Bit.App.Models.Api; + +namespace Bit.App.Models.Data +{ + public class LoginUriDataModel + { + public LoginUriDataModel() { } + + public LoginUriDataModel(LoginUriType u) + { + Uri = u.Uri; + Match = u.Match; + } + + public string Uri { get; set; } + public UriMatchType? Match { get; set; } + } +} diff --git a/src/App/Models/Data/CipherData/SecureNoteDataModel.cs b/src/App/Models/Data/CipherData/SecureNoteDataModel.cs new file mode 100644 index 000000000..abb04a08b --- /dev/null +++ b/src/App/Models/Data/CipherData/SecureNoteDataModel.cs @@ -0,0 +1,23 @@ +using Bit.App.Models.Api; +using System; + +namespace Bit.App.Models.Data +{ + public class SecureNoteDataModel : CipherDataModel + { + public SecureNoteDataModel() { } + + public SecureNoteDataModel(CipherResponse response) + : base(response) + { + if(response?.SecureNote == null) + { + throw new ArgumentNullException(nameof(response.SecureNote)); + } + + Type = response.SecureNote.Type; + } + + public Enums.SecureNoteType Type { get; set; } + } +} diff --git a/src/App/Models/Field.cs b/src/App/Models/Field.cs index 83e99a952..17b1ebbc0 100644 --- a/src/App/Models/Field.cs +++ b/src/App/Models/Field.cs @@ -1,5 +1,5 @@ using Bit.App.Enums; -using Bit.App.Models.Api; +using Bit.App.Models.Data; namespace Bit.App.Models { diff --git a/src/App/Models/Identity.cs b/src/App/Models/Identity.cs index 7be189538..0383b0dae 100644 --- a/src/App/Models/Identity.cs +++ b/src/App/Models/Identity.cs @@ -1,6 +1,6 @@ -using Bit.App.Models.Api; -using Bit.App.Models.Data; +using Bit.App.Models.Data; using Newtonsoft.Json; +using System; namespace Bit.App.Models { @@ -10,7 +10,19 @@ namespace Bit.App.Models public Identity(CipherData data) { - var deserializedData = JsonConvert.DeserializeObject(data.Data); + IdentityDataModel deserializedData; + if(data.Card != null) + { + deserializedData = JsonConvert.DeserializeObject(data.Card); + } + else if(data.Data != null) + { + deserializedData = JsonConvert.DeserializeObject(data.Data); + } + else + { + throw new ArgumentNullException(nameof(data.Identity)); + } Title = deserializedData.Title != null ? new CipherString(deserializedData.Title) : null; FirstName = deserializedData.FirstName != null ? new CipherString(deserializedData.FirstName) : null; diff --git a/src/App/Models/Login.cs b/src/App/Models/Login.cs index c5691f175..4f84d344c 100644 --- a/src/App/Models/Login.cs +++ b/src/App/Models/Login.cs @@ -1,4 +1,8 @@ using Bit.App.Models.Data; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; namespace Bit.App.Models { @@ -8,13 +12,27 @@ namespace Bit.App.Models public Login(CipherData data) { - Uri = data.Uri != null ? new CipherString(data.Uri) : null; - Username = data.Username != null ? new CipherString(data.Username) : null; - Password = data.Password != null ? new CipherString(data.Password) : null; - Totp = data.Totp != null ? new CipherString(data.Totp) : null; + LoginDataModel deserializedData; + if(data.Login != null) + { + deserializedData = JsonConvert.DeserializeObject(data.Login); + } + else if(data.Data != null) + { + deserializedData = JsonConvert.DeserializeObject(data.Data); + } + else + { + throw new ArgumentNullException(nameof(data.Identity)); + } + + Username = deserializedData.Username != null ? new CipherString(deserializedData.Username) : null; + Password = deserializedData.Password != null ? new CipherString(deserializedData.Password) : null; + Totp = deserializedData.Totp != null ? new CipherString(deserializedData.Totp) : null; + Uris = deserializedData.Uris?.Select(u => new LoginUri(u)); } - public CipherString Uri { get; set; } + public IEnumerable Uris { get; set; } public CipherString Username { get; set; } public CipherString Password { get; set; } public CipherString Totp { get; set; } diff --git a/src/App/Models/LoginUri.cs b/src/App/Models/LoginUri.cs new file mode 100644 index 000000000..976da114c --- /dev/null +++ b/src/App/Models/LoginUri.cs @@ -0,0 +1,19 @@ +using Bit.App.Enums; +using Bit.App.Models.Data; + +namespace Bit.App.Models +{ + public class LoginUri + { + public LoginUri() { } + + public LoginUri(LoginUriDataModel data) + { + Uri = data.Uri != null ? new CipherString(data.Uri) : null; + Match = data.Match; + } + + public CipherString Uri { get; set; } + public UriMatchType? Match { get; set; } + } +} diff --git a/src/App/Models/Page/VaultListPageModel.cs b/src/App/Models/Page/VaultListPageModel.cs index ef89920ac..daba956f2 100644 --- a/src/App/Models/Page/VaultListPageModel.cs +++ b/src/App/Models/Page/VaultListPageModel.cs @@ -42,7 +42,7 @@ namespace Bit.App.Models.Page { case CipherType.Login: LoginUsername = cipher.Login?.Username?.Decrypt(cipher.OrganizationId) ?? " "; - LoginUri = cipher.Login?.Uri?.Decrypt(cipher.OrganizationId) ?? " "; + LoginUri = cipher.Login.Uris?.FirstOrDefault()?.Uri?.Decrypt(cipher.OrganizationId) ?? " "; LoginPassword = new Lazy(() => cipher.Login?.Password?.Decrypt(cipher.OrganizationId)); LoginTotp = new Lazy(() => cipher.Login?.Totp?.Decrypt(cipher.OrganizationId)); diff --git a/src/App/Models/Page/VaultViewCipherPageModel.cs b/src/App/Models/Page/VaultViewCipherPageModel.cs index 4b5c878a8..bd96b3afe 100644 --- a/src/App/Models/Page/VaultViewCipherPageModel.cs +++ b/src/App/Models/Page/VaultViewCipherPageModel.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using Xamarin.Forms; using System.Collections.Generic; using Bit.App.Enums; +using System.Linq; namespace Bit.App.Models.Page { @@ -600,7 +601,7 @@ namespace Bit.App.Models.Page case CipherType.Login: LoginUsername = cipher.Login.Username?.Decrypt(cipher.OrganizationId); LoginPassword = cipher.Login.Password?.Decrypt(cipher.OrganizationId); - LoginUri = cipher.Login.Uri?.Decrypt(cipher.OrganizationId); + LoginUri = cipher.Login.Uris?.FirstOrDefault()?.Uri?.Decrypt(cipher.OrganizationId); break; case CipherType.Card: CardName = cipher.Card.CardholderName?.Decrypt(cipher.OrganizationId); diff --git a/src/App/Models/SecureNote.cs b/src/App/Models/SecureNote.cs index 5c207f593..0715660f0 100644 --- a/src/App/Models/SecureNote.cs +++ b/src/App/Models/SecureNote.cs @@ -1,5 +1,7 @@ using Bit.App.Enums; using Bit.App.Models.Data; +using Newtonsoft.Json; +using System; namespace Bit.App.Models { @@ -9,7 +11,21 @@ namespace Bit.App.Models public SecureNote(CipherData data) { - Type = data.SecureNoteType.Value; + SecureNoteDataModel deserializedData; + if(data.SecureNote != null) + { + deserializedData = JsonConvert.DeserializeObject(data.SecureNote); + } + else if(data.Data != null) + { + deserializedData = JsonConvert.DeserializeObject(data.Data); + } + else + { + throw new ArgumentNullException(nameof(data.Identity)); + } + + Type = deserializedData.Type; } public SecureNoteType Type { get; set; }