-
Notifications
You must be signed in to change notification settings - Fork 21
Add callout for crypto request/response models #740
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b6bec7
Added callout for request/response models.
trmartin4 a2fd457
Changed a to the.
trmartin4 e746732
Added callout to separation between salts.
trmartin4 02236b1
Merge branch 'main' into add-crypto-response-models
trmartin4 82e679f
Fixed naming of type to match the linked file.
trmartin4 07997cd
Merge branch 'add-crypto-response-models' of https://github.com/bitwaโฆ
trmartin4 9bae651
Additional change from response to request.
trmartin4 bd66e2e
Changed RAM to memory
trmartin4 b09c9e0
capitalized KM team
trmartin4 ba91ee7
Strengthened messaging on crypto code in SDK.
trmartin4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,9 +13,9 @@ build features that need end-to-end encryption. This guide provides an overview | |||||
| for composing features that need cryptographic protection. | ||||||
|
|
||||||
| Currently, there is a set of low-level APIs | ||||||
| ([EncString](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/enc_string/symmetric.rs#L59), | ||||||
| [UnsignedSharedKey](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/enc_string/asymmetric.rs#L58), | ||||||
| [MasterKey](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/keys/master_key.rs#L32)) | ||||||
| ([`EncString`](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/enc_string/symmetric.rs#L59), | ||||||
| [`UnsignedSharedKey`](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/enc_string/asymmetric.rs#L58), | ||||||
| [`MasterKey`](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/keys/master_key.rs#L32)) | ||||||
| that have been used to build most features, with each team owning the cryptographic constructions | ||||||
| created. Recently, high-level safe primitives were introduced that will move the complexity out of | ||||||
| each team's ownership. These are not yet complete, and if a particular use-case is not covered by | ||||||
|
|
@@ -36,10 +36,11 @@ Only where not otherwise possible should low level primitives be used, and this | |||||
| extreme caution and oversight. | ||||||
|
|
||||||
| Encryption in the TypeScript clients for new cases is deprecated. Any new cryptographic code should | ||||||
| be written in the SDK, if possible. Existing use-cases can be continued in the TypeScript clients | ||||||
| for now, but eventually will be migrated too. First, the SDK has better memory safety guarantees and | ||||||
| prevents key material from being left behind in memory. Second, newer, safer APIs are not exposed | ||||||
| outside of the SDK. | ||||||
| be written in the | ||||||
| [SDK](https://github.com/bitwarden/sdk-internal/tree/main/crates/bitwarden-crypto), if possible. | ||||||
| Existing use-cases can be continued in the TypeScript clients for now, but eventually will be | ||||||
| migrated too. First, the SDK has better memory safety guarantees and prevents key material from | ||||||
| being left behind in memory. Second, newer, safer APIs are not exposed outside of the SDK. | ||||||
|
|
||||||
| ## Terminology | ||||||
|
|
||||||
|
|
@@ -66,7 +67,7 @@ content-encryption-key needs to be re-uploaded. | |||||
| Content-encryption-keys are currently used for file attachments, and for vault items ("cipher | ||||||
| keys"). | ||||||
|
|
||||||
| ### Key wrap | ||||||
| ### Key wrapping | ||||||
|
|
||||||
| Key wrapping describes encrypting a symmetric key, a signature key or private key with a | ||||||
| **symmetric** key. There are various reasons for doing this. One of them is decoupling of keys, as | ||||||
|
|
@@ -86,7 +87,7 @@ a combination of these, teams should reach out! | |||||
| ### Protecting a document / struct | ||||||
|
|
||||||
| Use | ||||||
| [DataEnvelope](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/safe/data_envelope.rs). | ||||||
| [`DataEnvelope`](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/src/safe/data_envelope.rs). | ||||||
| This handles encryption versioning, and hides exact sizes of the encrypted contents. The existing | ||||||
| [example](https://github.com/bitwarden/sdk-internal/blob/c60a5d794732d2c0fc203feb21ce5851d5325fe1/crates/bitwarden-crypto/examples/seal_struct.rs) | ||||||
| can be used as a reference. Using the data envelope API, an encrypted blob is obtained and, | ||||||
|
|
@@ -96,26 +97,27 @@ content-encryption-key and the encrypted blob are required. | |||||
|
|
||||||
| :::note | ||||||
|
|
||||||
| EncStrings have been used for this process. Instead of protecting the document as a whole, they | ||||||
| `EncStrings` have been used for this process. Instead of protecting the document as a whole, they | ||||||
| protected individual fields on the document. These are no longer recommended for new use-cases. | ||||||
| There are a few reasons, such as performance impact of many small decrypt operations, overhead of | ||||||
| MAC / IV of many small encrypted items, certain kinds of tampering attacks on the document as a | ||||||
| whole. Further, maintainability is harder, requiring a lot more work both on the client side as well | ||||||
| as the server side, if the structs are passed along in this representation. | ||||||
|
|
||||||
| If there is still a need to maintain EncStrings and help is needed figuring out a path to migrate, | ||||||
| If there is still a need to maintain `EncString`s and help is needed figuring out a path to migrate, | ||||||
| teams should reach out. | ||||||
|
|
||||||
| The vast majority of existing encrypted data still uses EncStrings. | ||||||
| The vast majority of existing encrypted data still uses `EncString`s. | ||||||
|
|
||||||
| ::: | ||||||
|
|
||||||
| ### Protecting a file | ||||||
|
|
||||||
| Existing attachments are protected using an EncArrayBuffer. This is just an EncString, but encoded | ||||||
| slightly differently. Again, a content-encryption-key is usually used, but not enforced. When | ||||||
| encrypting files for new purposes, a content-encryption-key **MUST** be used. Consider that with the | ||||||
| current encryption scheme, the entire file must be downloaded and loaded into ram for decryption. | ||||||
| Existing attachments are protected using an `EncArrayBuffer`. This is just an `EncString`, but | ||||||
| encoded slightly differently. Again, a content-encryption-key is usually used, but not enforced. | ||||||
| When encrypting files for new purposes, a content-encryption-key **MUST** be used. Consider that | ||||||
| with the current encryption scheme, the entire file must be downloaded and loaded into ram for | ||||||
|
||||||
| with the current encryption scheme, the entire file must be downloaded and loaded into ram for | |
| with the current encryption scheme, the entire file must be downloaded and loaded into memory for |
Member
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with bd66e2e (#740)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
โน๏ธ Unrelated but I don't like this language at this point because it's still suggesting not using the SDK.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly is the suggestion here? / What phrasing would be better?
The phrasing clearly states that you SHOULD write SDK code, and never recommends using TS code, merely allows it for existing use-cases. All new crypto APIs are only available in the SDK, and existing crypto APIs in TypeScript are for a large part deprecated. The clarification here is that you can modify existing use-cases without having to instantly migrate them to the SDK (because doing so is not always immediately possible before a few blockers are resolved. We've seen this with the vault team).
New use-cases SHOULD be written in the SDK.
As a side note, @withinfocus / @MGibson1 if KM gets a review where people are using TS crypto APIs for a new use-case - such as DIRT adding a new type of report, or similar - is the expectation that we block the PR and request the team to re-write their changeset to work through the SDK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment is merely because it leaves the existing use case's path open-ended, and my preference is to use stronger language about how any use case, if needing modification, really should be a shift to the SDK at that point.
I do also feel that new use cases should be SDK-only, and it's essential that's known up front before any TypeScript work is even considered. Blocking a PR is too late in the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. Looking at recent PR's, I'm not sure if all teams are aware of that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this sound?
I'd like to also confirm (@quexten?) that all the TS APIs are actually deprecated in
clients. That should at least give pause to any team trying to use them. I know it did for Auth. In refinement we recognized "hey, these APIs are deprecated, we better reach out to KM to understand how to do it right" when we were designing a new feature.