mirror of
https://github.com/bitwarden/mobile
synced 2025-12-27 05:33:23 +00:00
initial commit
This commit is contained in:
10
src/App/Models/Api/ApiError.cs
Normal file
10
src/App/Models/Api/ApiError.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class ApiError
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public HttpStatusCode StatusCode { get; set; }
|
||||
}
|
||||
}
|
||||
33
src/App/Models/Api/ApiResult.cs
Normal file
33
src/App/Models/Api/ApiResult.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class ApiResult<T>
|
||||
{
|
||||
private List<ApiError> m_errors = new List<ApiError>();
|
||||
|
||||
public bool Succeeded { get; private set; }
|
||||
public T Result { get; set; }
|
||||
public IEnumerable<ApiError> Errors => m_errors;
|
||||
|
||||
public static ApiResult<T> Success(T result)
|
||||
{
|
||||
return new ApiResult<T>
|
||||
{
|
||||
Succeeded = true,
|
||||
Result = result
|
||||
};
|
||||
}
|
||||
|
||||
public static ApiResult<T> Failed(params ApiError[] errors)
|
||||
{
|
||||
var result = new ApiResult<T> { Succeeded = false };
|
||||
if(errors != null)
|
||||
{
|
||||
result.m_errors.AddRange(errors);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/App/Models/Api/Request/FolderRequest.cs
Normal file
7
src/App/Models/Api/Request/FolderRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class FolderRequest
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
12
src/App/Models/Api/Request/SiteRequest.cs
Normal file
12
src/App/Models/Api/Request/SiteRequest.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class SiteRequest
|
||||
{
|
||||
public string FolderId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
}
|
||||
8
src/App/Models/Api/Request/TokenRequest.cs
Normal file
8
src/App/Models/Api/Request/TokenRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class TokenRequest
|
||||
{
|
||||
public string Email { get; set; }
|
||||
public string MasterPasswordHash { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/App/Models/Api/Response/ErrorResponse.cs
Normal file
14
src/App/Models/Api/Response/ErrorResponse.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class ErrorResponse
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public Dictionary<string, IEnumerable<string>> ValidationErrors { get; set; }
|
||||
// For use in development environments.
|
||||
public string ExceptionMessage { get; set; }
|
||||
public string ExceptionStackTrace { get; set; }
|
||||
public string InnerExceptionMessage { get; set; }
|
||||
}
|
||||
}
|
||||
8
src/App/Models/Api/Response/FolderResponse.cs
Normal file
8
src/App/Models/Api/Response/FolderResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class FolderResponse
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
12
src/App/Models/Api/Response/ProfileResponse.cs
Normal file
12
src/App/Models/Api/Response/ProfileResponse.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class ProfileResponse
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string MasterPasswordHint { get; set; }
|
||||
public string Culture { get; set; }
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
16
src/App/Models/Api/Response/SiteResponse.cs
Normal file
16
src/App/Models/Api/Response/SiteResponse.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class SiteResponse
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
|
||||
// Expandables
|
||||
public FolderResponse Folder { get; set; }
|
||||
}
|
||||
}
|
||||
8
src/App/Models/Api/Response/TokenResponse.cs
Normal file
8
src/App/Models/Api/Response/TokenResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class TokenResponse
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public ProfileResponse Profile { get; set; }
|
||||
}
|
||||
}
|
||||
11
src/App/Models/Cipher.cs
Normal file
11
src/App/Models/Cipher.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public abstract class Cipher
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ServerId { get; set; }
|
||||
public CipherString Name { get; set; }
|
||||
}
|
||||
}
|
||||
50
src/App/Models/CipherString.cs
Normal file
50
src/App/Models/CipherString.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Abstractions;
|
||||
using XLabs.Ioc;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public class CipherString
|
||||
{
|
||||
public CipherString(string encryptedString)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(encryptedString) || !encryptedString.Contains("|"))
|
||||
{
|
||||
throw new ArgumentException(nameof(encryptedString));
|
||||
}
|
||||
|
||||
EncryptedString = encryptedString;
|
||||
}
|
||||
|
||||
public CipherString(string initializationVector, string cipherText)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(initializationVector))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(initializationVector));
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(cipherText))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cipherText));
|
||||
}
|
||||
|
||||
EncryptedString = string.Format("{0}|{1}", initializationVector, cipherText);
|
||||
}
|
||||
|
||||
public string EncryptedString { get; private set; }
|
||||
public string InitializationVector { get { return EncryptedString?.Split('|')[0]; } }
|
||||
public string CipherText { get { return EncryptedString?.Split('|')[1]; } }
|
||||
public byte[] InitializationVectorBytes { get { return Convert.FromBase64String(InitializationVector); } }
|
||||
public byte[] CipherTextBytes { get { return Convert.FromBase64String(CipherText); } }
|
||||
|
||||
public string Decrypt()
|
||||
{
|
||||
var cryptoService = Resolver.Resolve<ICryptoService>();
|
||||
return cryptoService.Decrypt(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/App/Models/Data/FolderData.cs
Normal file
32
src/App/Models/Data/FolderData.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using SQLite;
|
||||
using Bit.App.Abstractions;
|
||||
|
||||
namespace Bit.App.Models.Data
|
||||
{
|
||||
[Table("Folder")]
|
||||
public class FolderData : IDataObject<int>
|
||||
{
|
||||
public FolderData()
|
||||
{ }
|
||||
|
||||
public FolderData(Folder folder)
|
||||
{
|
||||
Id = folder.Id;
|
||||
ServerId = folder.ServerId;
|
||||
Name = folder.Name?.EncryptedString;
|
||||
}
|
||||
|
||||
[PrimaryKey]
|
||||
[AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
public string ServerId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime RevisionDateTime { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public Folder ToFolder()
|
||||
{
|
||||
return new Folder(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/App/Models/Data/SiteData.cs
Normal file
44
src/App/Models/Data/SiteData.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using SQLite;
|
||||
using Bit.App.Abstractions;
|
||||
|
||||
namespace Bit.App.Models.Data
|
||||
{
|
||||
[Table("Site")]
|
||||
public class SiteData : IDataObject<int>
|
||||
{
|
||||
public SiteData()
|
||||
{ }
|
||||
|
||||
public SiteData(Site site)
|
||||
{
|
||||
Id = site.Id;
|
||||
ServerId = site.ServerId;
|
||||
FolderId = site.FolderId;
|
||||
ServerFolderId = site.ServerFolderId;
|
||||
Name = site.Name?.EncryptedString;
|
||||
Uri = site.Uri?.EncryptedString;
|
||||
Username = site.Username?.EncryptedString;
|
||||
Password = site.Password?.EncryptedString;
|
||||
Notes = site.Notes?.EncryptedString;
|
||||
}
|
||||
|
||||
[PrimaryKey]
|
||||
[AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
public string ServerId { get; set; }
|
||||
public int? FolderId { get; set; }
|
||||
public string ServerFolderId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime RevisionDateTime { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public Site ToSite()
|
||||
{
|
||||
return new Site(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/App/Models/Folder.cs
Normal file
29
src/App/Models/Folder.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Bit.App.Models.Data;
|
||||
using Bit.App.Models.Api;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public class Folder : Cipher
|
||||
{
|
||||
public Folder()
|
||||
{ }
|
||||
|
||||
public Folder(FolderData data)
|
||||
{
|
||||
Id = data.Id;
|
||||
ServerId = data.ServerId;
|
||||
Name = data.Name != null ? new CipherString(data.Name) : null;
|
||||
}
|
||||
|
||||
public Folder(FolderResponse response)
|
||||
{
|
||||
ServerId = response.Id;
|
||||
Name = response.Name != null ? new CipherString(response.Name) : null;
|
||||
}
|
||||
|
||||
public FolderData ToFolderData()
|
||||
{
|
||||
return new FolderData(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/App/Models/Site.cs
Normal file
47
src/App/Models/Site.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Bit.App.Models.Api;
|
||||
using Bit.App.Models.Data;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public class Site : Cipher
|
||||
{
|
||||
public Site()
|
||||
{ }
|
||||
|
||||
public Site(SiteData data)
|
||||
{
|
||||
Id = data.Id;
|
||||
ServerId = data.ServerId;
|
||||
FolderId = data.FolderId;
|
||||
ServerFolderId = data.ServerFolderId;
|
||||
Name = data.Name != null ? new CipherString(data.Name) : null;
|
||||
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;
|
||||
Notes = data.Notes != null ? new CipherString(data.Notes) : null;
|
||||
}
|
||||
|
||||
public Site(SiteResponse response)
|
||||
{
|
||||
ServerId = response.Id;
|
||||
ServerFolderId = response.FolderId;
|
||||
Name = response.Name != null ? new CipherString(response.Name) : null;
|
||||
Uri = response.Uri != null ? new CipherString(response.Uri) : null;
|
||||
Username = response.Username != null ? new CipherString(response.Username) : null;
|
||||
Password = response.Password != null ? new CipherString(response.Password) : null;
|
||||
Notes = response.Notes != null ? new CipherString(response.Notes) : null;
|
||||
}
|
||||
|
||||
public int? FolderId { get; set; }
|
||||
public string ServerFolderId { get; set; }
|
||||
public CipherString Uri { get; set; }
|
||||
public CipherString Username { get; set; }
|
||||
public CipherString Password { get; set; }
|
||||
public CipherString Notes { get; set; }
|
||||
|
||||
public SiteData ToSiteData()
|
||||
{
|
||||
return new SiteData(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/App/Models/View/VaultView.cs
Normal file
48
src/App/Models/View/VaultView.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Bit.App.Models.View
|
||||
{
|
||||
public class VaultView
|
||||
{
|
||||
public class Site
|
||||
{
|
||||
public Site(Models.Site site)
|
||||
{
|
||||
Id = site.Id;
|
||||
Name = site.Name?.Decrypt();
|
||||
Username = site.Username?.Decrypt();
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Username { get; set; }
|
||||
}
|
||||
|
||||
public class Folder : ObservableCollection<Site>
|
||||
{
|
||||
public Folder(string name) { Name = name; }
|
||||
|
||||
public Folder(IEnumerable<Models.Site> sites)
|
||||
{
|
||||
Name = "(none)";
|
||||
foreach(var site in sites)
|
||||
{
|
||||
Items.Add(new Site(site));
|
||||
}
|
||||
}
|
||||
|
||||
public Folder(Models.Folder folder, IEnumerable<Models.Site> sites)
|
||||
: this(sites)
|
||||
{
|
||||
Id = folder.Id;
|
||||
Name = folder.Name?.Decrypt();
|
||||
}
|
||||
|
||||
public int? Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string FirstLetter { get { return Name.Substring(0, 1); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user