-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Expand Hkdf crypto functions * Add tests for hkdf crypto functions Took the testing infrastructure from bitwarden/server * Move Hkdf to cryptoFunctionService * Port changes from bitwarden/jslib#192 * Port changes from bitwarden/jslib#205 * Make Send Expiration Optional implement changes from bitwarden/jslib#242 * Bug fixes found by testing * Test helpers * Test conversion between model types * Test SendService These are mostly happy-path tests to ensure a reasonably correct implementation * Add run tests step to GitHub Actions * Test send decryption * Test Request generation from Send * Constructor dependencies on separate lines * Remove unused testing infrastructure * Rename to match class name * Move fat arrows to previous lines * Handle exceptions in App layer * PR review cleanups * Throw when attempting to save an unkown Send Type I think it's best to only throw on unknown send types here. I don't think we want to throw whenever we encounter one since that would do bad things like lock up Sync if clients get out of date relative to servers. Instead, keep the client from ruining saved data by complaining last minute that it doesn't know what it's doing.
- Loading branch information
Showing
52 changed files
with
2,046 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Bit.Core.Models.Data; | ||
using Bit.Core.Models.Domain; | ||
using Bit.Core.Models.View; | ||
|
||
namespace Bit.Core.Abstractions | ||
{ | ||
public interface ISendService | ||
{ | ||
void ClearCache(); | ||
Task<(Send send, CipherString encryptedFileData)> EncryptAsync(SendView model, byte[] fileData, string password, | ||
SymmetricCryptoKey key = null); | ||
Task<Send> GetAsync(string id); | ||
Task<List<Send>> GetAllAsync(); | ||
Task<List<SendView>> GetAllDecryptedAsync(); | ||
Task SaveWithServerAsync(Send sendData, byte[] encryptedFileData); | ||
Task UpsertAsync(params SendData[] send); | ||
Task ReplaceAsync(Dictionary<string, SendData> sends); | ||
Task ClearAsync(string userId); | ||
Task DeleteAsync(params string[] ids); | ||
Task DeleteWithServerAsync(string id); | ||
Task RemovePasswordWithServerAsync(string id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Bit.Core.Enums | ||
{ | ||
public enum HkdfAlgorithm : byte | ||
{ | ||
Sha256 = 1, | ||
Sha512 = 2, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Bit.Core.Enums | ||
{ | ||
public enum SendType | ||
{ | ||
Text = 0, | ||
File = 1, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Bit.Core.Models.Api | ||
{ | ||
public class SendFileApi | ||
{ | ||
public string Id { get; set; } | ||
public string Url { get; set; } | ||
public string FileName { get; set; } | ||
public string Key { get; set; } | ||
public string Size { get; set; } | ||
public string SizeName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Bit.Core.Models.Api | ||
{ | ||
public class SendTextApi | ||
{ | ||
public string Text { get; set; } | ||
public bool Hidden { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using Bit.Core.Enums; | ||
using Bit.Core.Models.Response; | ||
|
||
namespace Bit.Core.Models.Data | ||
{ | ||
public class SendData : Data | ||
{ | ||
public SendData() { } | ||
|
||
public SendData(SendResponse response, string userId) | ||
{ | ||
Id = response.Id; | ||
AccessId = response.AccessId; | ||
UserId = userId; | ||
Type = response.Type; | ||
Name = response.Name; | ||
Notes = response.Notes; | ||
Key = response.Key; | ||
MaxAccessCount = response.MaxAccessCount; | ||
AccessCount = response.AccessCount; | ||
RevisionDate = response.RevisionDate; | ||
ExpirationDate = response.ExpirationDate; | ||
DeletionDate = response.DeletionDate; | ||
Password = response.Password; | ||
Disabled = response.Disabled; | ||
|
||
switch (Type) | ||
{ | ||
case SendType.File: | ||
File = new SendFileData(response.File); | ||
break; | ||
case SendType.Text: | ||
Text = new SendTextData(response.Text); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
public string Id { get; set; } | ||
public string AccessId { get; set; } | ||
public string UserId { get; set; } | ||
public SendType Type { get; set; } | ||
public string Name { get; set; } | ||
public string Notes { get; set; } | ||
public SendFileData File { get; set; } | ||
public SendTextData Text { get; set; } | ||
public string Key { get; set; } | ||
public int? MaxAccessCount { get; set; } | ||
public int AccessCount { get; set; } | ||
public DateTime RevisionDate { get; set; } | ||
public DateTime? ExpirationDate { get; set; } | ||
public DateTime DeletionDate { get; set; } | ||
public string Password { get; set; } | ||
public bool Disabled { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Drawing; | ||
using Bit.Core.Models.Api; | ||
|
||
namespace Bit.Core.Models.Data | ||
{ | ||
public class SendFileData : Data | ||
{ | ||
public SendFileData() { } | ||
|
||
public SendFileData(SendFileApi data) | ||
{ | ||
Id = data.Id; | ||
Url = data.Url; | ||
FileName = data.FileName; | ||
Key = data.Key; | ||
Size = data.Size; | ||
SizeName = data.SizeName; | ||
} | ||
|
||
public string Id { get; set; } | ||
public string Url { get; set; } | ||
public string FileName { get; set; } | ||
public string Key { get; set; } | ||
public string Size { get; set; } | ||
public string SizeName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Drawing; | ||
using Bit.Core.Models.Api; | ||
|
||
namespace Bit.Core.Models.Data | ||
{ | ||
public class SendTextData : Data | ||
{ | ||
public SendTextData() { } | ||
|
||
public SendTextData(SendTextApi data) | ||
{ | ||
Text = data.Text; | ||
Hidden = data.Hidden; | ||
} | ||
|
||
public string Text { get; set; } | ||
public bool Hidden { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.