-
Notifications
You must be signed in to change notification settings - Fork 10
Add-userid-to-encryption-methods #278
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 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a2af030
Include userId as a part of unlocked client contexts
MGibson1 7a13e96
Include the UserId a cipher is encrypted for
MGibson1 bcd886b
SDK auth is used in secrets manager
MGibson1 2f0a896
`cargo +"nightly-2025-05-08" fmt` :robot:
MGibson1 05c8080
`cargo clippy --all-features --tests --fix --lib -p bitwarden-core` :โฆ
MGibson1 2f18679
Fix example applications
MGibson1 9ebfeb3
Match encrypted for name across implementations
MGibson1 8d64d29
Include encryptedFor in uniffi bridge callbacks
MGibson1 edf8961
Remove userid from auth success response
MGibson1 fbda0e7
Merge branch 'main' into add-userid-to-encryption-methods
MGibson1 468bcda
Only allow setting userID once
MGibson1 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
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
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
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
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
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 |
---|---|---|
|
@@ -39,6 +39,7 @@ pub enum MobileCryptoError { | |
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] | ||
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))] | ||
pub struct InitUserCryptoRequest { | ||
pub user_id: Option<uuid::Uuid>, | ||
/// The user's KDF parameters, as received from the prelogin request | ||
pub kdf_params: Kdf, | ||
/// The user's email address | ||
|
@@ -131,6 +132,10 @@ pub async fn initialize_user_crypto( | |
|
||
let private_key: EncString = req.private_key.parse()?; | ||
|
||
if let Some(user_id) = req.user_id { | ||
client.internal.set_user_id(user_id); | ||
} | ||
|
||
match req.method { | ||
InitUserCryptoMethod::Password { password, user_key } => { | ||
let user_key: EncString = user_key.parse()?; | ||
|
@@ -564,6 +569,7 @@ mod tests { | |
initialize_user_crypto( | ||
& client, | ||
InitUserCryptoRequest { | ||
user_id: Some(uuid::Uuid::new_v4()), | ||
kdf_params: kdf.clone(), | ||
email: "[email protected]".into(), | ||
private_key: priv_key.to_owned(), | ||
|
@@ -583,6 +589,7 @@ mod tests { | |
initialize_user_crypto( | ||
&client2, | ||
InitUserCryptoRequest { | ||
user_id: Some(uuid::Uuid::new_v4()), | ||
kdf_params: kdf.clone(), | ||
email: "[email protected]".into(), | ||
private_key: priv_key.to_owned(), | ||
|
@@ -638,6 +645,7 @@ mod tests { | |
initialize_user_crypto( | ||
& client, | ||
InitUserCryptoRequest { | ||
user_id: Some(uuid::Uuid::new_v4()), | ||
kdf_params: Kdf::PBKDF2 { | ||
iterations: 100_000.try_into().unwrap(), | ||
}, | ||
|
@@ -659,6 +667,7 @@ mod tests { | |
initialize_user_crypto( | ||
&client2, | ||
InitUserCryptoRequest { | ||
user_id: Some(uuid::Uuid::new_v4()), | ||
kdf_params: Kdf::PBKDF2 { | ||
iterations: 100_000.try_into().unwrap(), | ||
}, | ||
|
@@ -701,6 +710,7 @@ mod tests { | |
initialize_user_crypto( | ||
&client3, | ||
InitUserCryptoRequest { | ||
user_id: Some(uuid::Uuid::new_v4()), | ||
kdf_params: Kdf::PBKDF2 { | ||
iterations: 100_000.try_into().unwrap(), | ||
}, | ||
|
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
issue?: it seems odd to have a public function that changes the
user_id
without any additional context required. I feel like theuser_id
should only ever change when the client is initialized and possibly never again after that. Maybe there's some edge case where we'd want a client without Crypto but tied to a user? If that is the case then I think this function should instead be called something likeinit_user_id()
and only allow itself to be called once. However, it's probably more likely that we'll split up the client into user and non-user scoped clients and then just require theuser_id
on creation.Either way, I think we should remove the ability to change the
user_id
. My opinion is that it should be bundled into theinitialize_user_crypto
functions below, but I'm not married to that solutionUh 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.
Yeah I agree, separate user-bound and non-user bounds clients would allow us to require user id during construction and enforce no changes to it, until we have those we can use a
OnceLock
to ensure the ID is only initialized once: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.
There definitely are user-bound, but not crypto-inited clients -- that's a locked SDK.
The thought was, that I only need the
UserId
during encryption (for now) and I'm not 100% familiar with our current usages and I wanted to minimize the impact of the breaking change.I can certainly revise. I agree it makes sense to init userId only once -- that's an easy change -- Actually making the pure, environment-bound, and user-bound client contexts feel out of scope here, though. Do you agree?
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.
Oh yes splitting them up is way out of scope, we're gonna be working on that with Auth if I remember correctly. I was just thinking ahead a little, I could've been a little clearer there :) I think
OnceLock
that Dani suggested is a perfectly sound solution until we eventually start splitting stuffThere 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.
This is done (468bcda), but there is an unfortunate side effect that crypto initialization can now error with a userId already set.
This will have to be updated once the clients are split, but for now is in line with the expectation that UserId is sent into crypto initialization. Once I implemented it, I got to thinking that for the same reasons it makes sense to error should multiple
init_user_crypto
requests be sent into a single client, so hopefully this can just morph into aCryptoAlreadyInitialized
error or some such.