Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port send jslib to mobile #1219

Merged
merged 20 commits into from
Jan 25, 2021
Merged

Port send jslib to mobile #1219

merged 20 commits into from
Jan 25, 2021

Conversation

MGibson1
Copy link
Member

@MGibson1 MGibson1 commented Jan 13, 2021

Overview

Port of Send PRs to jslib (bitwarden/jslib#190, bitwarden/jslib#192, bitwarden/jslib#205, bitwarden/jslib#242). This PR does not implement any actual use of the SendService.

Testing

Projects

Common

This project is a copy from the bitwarden/server/Core.Test project, with some additions. Given the similarity here, we should think about creating a new repo for common testing items and accessing them through a submodule.

Core.Test

This is a test bed for the Send feature I'm implementing. Crypto tests are copied from jslib tests. Send model and service tests are happy path tests to ensure proper function since I'm not implementing anything that uses them.

Automated Testing

An Automated test runner is added to the android job. Unfortunately, dotnet is not capable of building the android and iOS projects, so it is run against only the Core.Test project. We'll have to add another line per test project we add.

Files Changes/Added

  • build.yml: Added running of tests in the Core.Test project to the android job pipeline.
  • bitwarden-mobile.sln: Added test projects test/Common.csproj and test/Core.Test
  • Android.csproj: This was automatically changed by VS Mac when adding the above projects. The new Guid is what was already in the solution file and seems like a good change to me, so I kept it. @mportune-bw, @kspearrin if you know why this Guid differed from the solution file, please let me know and I'll revert.
  • IApiService.cs/ApiService.cs: Add Send methods. No Access methods on Mobile.
  • ICryptoFunctionService.cs/PclCryptoFunctionService.cs: Add expanded hkdf implementation to function service. A basic implementation used to be private to CryptoFunctionService, but is not implemented in classes implementing this interface.
  • ICryptoService.cs/CryptoService.cs: Add send MakeKey method
  • ISendService.cs/SendService.cs: Service handling send functionality.
  • Enums/HkdfAlgorithm: Hkdf is currently only valid for Sha256 and Sha512, so this represents a subset of valid CryptoHashAlgorithms. Conversion between these enums happens in the CryptoFunctionService when Hkdf is calculated
  • Enums/SendType.cs: Types of valid sends
  • SendFileApi.cs: Api interface model for File type send data.
  • SendTestApi.cs: Api interface model for Text type send data.
  • SendData.cs/SendFileData.cs/SendTextData.cs: Client storage model for Send / File Send info / and Text Send info, respectively
  • Domain/Send/SendFile/SendText Encrypted data model for Send / File Send info / and Text Send info, respectively
  • SendView/SendFileView/SendTextView: Decrypted model for Send / File Send info / and Text Send info, respectively
  • CipherString: Allow optionally passing in decryption key
  • Domain: Optionally allow specifying decryption key
  • SendRequest: Api request model
  • SendResponse: Api response model
  • SyncResponse: Added sends to sync response
  • SyncService: Handle synced sends and replace current storage with received send data.
  • CoreHelpers: Added this method for testing, but it exists in CoreHelpers for Server. Open to moving to TestHelpers
  • ServiceContainer.cs: Make SendService available from ServiceContainer

Testing Files Changes

Common

  • AutoSubDataAttribute/CustomAutoDataAttribute/SutAutoDataAttribute/InlineAutoSubDataAttribute/InlineCustomAutoDataAttribute/FixtureExtension: Helper attributes to allow creation of autofixtures with customizations, substitutions, or sutProviders
  • ISutProvider/SutProvider/SutProviderCustomization: Autofixture customization to provide SUT objects with access to injected dependencies
  • common/TestHelper.cs: Commonly used helper methods are placed here.
  • Common.csproj: Project to house testing code common across testing projects. We should think about splitting this to a new Repo to share between csharp projects.

Core.Test

  • Core.Test/**/SymmetricCryptoKeyCustomization / SendCustomizations: AutFixture customizations to produce valid fixture data for SymmetricCryptoKey and Send data structures, respectively.
  • Core.Test.csproj: Project housing all Core tests and Core specific testing infrastructure (like above customizations)
  • SendDataTests.cs: Tests for SendData, SendTextData, and SendFileData data models. These are model conversion tests
  • SendTests.cs: Tests for Send, SendText, and SendFile domain models. These are model conversion tests
  • SendRequestTests.cs: Tests for SendRequest, SendTextApi, and SendFileApi models. These are model conversion tests
  • CryptoFunctionServiceTests.cs: Tests of Hkdf implementations. Tests are copied from bitwarden/jslib
  • SendServiceTests.cs: Happy path tests of send service functions

@MGibson1 MGibson1 requested a review from a team January 13, 2021 23:05
@MGibson1 MGibson1 force-pushed the port-send-jslib-to-mobile branch 3 times, most recently from a30ce2d to e77ca14 Compare January 14, 2021 03:04
Copy link
Member

@kspearrin kspearrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great. just a few comments

src/Core/Services/SendService.cs Outdated Show resolved Hide resolved
src/Core/Services/SendService.cs Outdated Show resolved Hide resolved
@MGibson1 MGibson1 force-pushed the port-send-jslib-to-mobile branch from e77ca14 to 07a2258 Compare January 15, 2021 00:23
@MGibson1 MGibson1 marked this pull request as ready for review January 15, 2021 16:21
@MGibson1 MGibson1 requested a review from a team January 15, 2021 16:21
@cscharf cscharf requested a review from kspearrin January 15, 2021 18:41
src/Core/Models/Domain/Send.cs Outdated Show resolved Hide resolved
src/Core/Models/Domain/Send.cs Outdated Show resolved Hide resolved
src/Core/Models/Domain/SendFile.cs Outdated Show resolved Hide resolved
src/Core/Models/Domain/SendFile.cs Outdated Show resolved Hide resolved
src/Core/Models/Domain/Send.cs Outdated Show resolved Hide resolved
test/Common/AutoFixture/SutProvider.cs Outdated Show resolved Hide resolved
test/Common/TestHelper.cs Outdated Show resolved Hide resolved
test/Core.Test/Services/SendServiceTests.cs Outdated Show resolved Hide resolved
test/Core.Test/Services/SendServiceTests.cs Outdated Show resolved Hide resolved
test/Core.Test/Services/SendServiceTests.cs Outdated Show resolved Hide resolved
response = await _apiService.PostSendFileAsync(fd);
break;
default:
response = new SendResponse();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default behavior idea might just be a bad one. It's identifying a possible future bug and recovering from it in a hard-to-track-down manner.

I think throwing would be better. Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please add throw here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up adding the throw only 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, we should just keep the client from ruining saved data by complaining last minute that it doesn't know what it's doing.

@MGibson1 MGibson1 requested review from cscharf and mpbw2 January 15, 2021 21:20
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.
Copy link

@cscharf cscharf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, please hold merge until after the release [code-freeze]

@cscharf cscharf added the hold do not merge yet label Jan 15, 2021
@MGibson1 MGibson1 removed the hold do not merge yet label Jan 25, 2021
@MGibson1 MGibson1 merged commit 8d5614c into master Jan 25, 2021
@MGibson1 MGibson1 deleted the port-send-jslib-to-mobile branch January 25, 2021 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants