diff --git a/crates/bitwarden-core/src/auth/auth_client.rs b/crates/bitwarden-core/src/auth/auth_client.rs index 6164a87a3..c302c52a1 100644 --- a/crates/bitwarden-core/src/auth/auth_client.rs +++ b/crates/bitwarden-core/src/auth/auth_client.rs @@ -2,6 +2,8 @@ use bitwarden_crypto::{ CryptoError, DeviceKey, EncString, Kdf, TrustDeviceResponse, UnsignedSharedKey, }; +#[cfg(feature = "internal")] +use uuid::Uuid; #[cfg(feature = "secrets")] use crate::auth::login::{login_access_token, AccessTokenLoginRequest, AccessTokenLoginResponse}; @@ -91,8 +93,15 @@ impl AuthClient { email: String, org_public_key: String, remember_device: bool, + user_id: Uuid, ) -> Result { - make_register_tde_keys(&self.client, email, org_public_key, remember_device) + make_register_tde_keys( + &self.client, + email, + org_public_key, + remember_device, + user_id, + ) } #[allow(missing_docs)] diff --git a/crates/bitwarden-core/src/auth/auth_request.rs b/crates/bitwarden-core/src/auth/auth_request.rs index 5655f2110..325ffe832 100644 --- a/crates/bitwarden-core/src/auth/auth_request.rs +++ b/crates/bitwarden-core/src/auth/auth_request.rs @@ -241,7 +241,7 @@ mod tests { new_device .crypto() .initialize_user_crypto(InitUserCryptoRequest { - user_id: Some(uuid::Uuid::new_v4()), + user_id: uuid::Uuid::new_v4(), kdf_params: kdf, email: email.to_owned(), private_key, diff --git a/crates/bitwarden-core/src/auth/login/api_key.rs b/crates/bitwarden-core/src/auth/login/api_key.rs index 782a6df34..06357fb99 100644 --- a/crates/bitwarden-core/src/auth/login/api_key.rs +++ b/crates/bitwarden-core/src/auth/login/api_key.rs @@ -39,14 +39,15 @@ pub(crate) async fn login_api_key( let master_key = MasterKey::derive(&input.password, &email, &kdf)?; - client - .internal - .set_login_method(LoginMethod::User(UserLoginMethod::ApiKey { + client.internal.set_login_method(LoginMethod::User { + method: UserLoginMethod::ApiKey { client_id: input.client_id.to_owned(), client_secret: input.client_secret.to_owned(), email, kdf, - })); + }, + user_id: access_token_obj.sub.parse()?, + }); let user_key: EncString = require!(r.key.as_deref()).parse()?; let private_key: EncString = require!(r.private_key.as_deref()).parse()?; diff --git a/crates/bitwarden-core/src/auth/login/auth_request.rs b/crates/bitwarden-core/src/auth/login/auth_request.rs index 363086fb1..b5efc6d72 100644 --- a/crates/bitwarden-core/src/auth/login/auth_request.rs +++ b/crates/bitwarden-core/src/auth/login/auth_request.rs @@ -10,6 +10,7 @@ use crate::{ auth::{ api::{request::AuthRequestTokenRequest, response::IdentityTokenResponse}, auth_request::new_auth_request, + JwtToken, }, client::{LoginMethod, UserLoginMethod}, key_management::crypto::{AuthRequestMethod, InitUserCryptoMethod, InitUserCryptoRequest}, @@ -88,6 +89,8 @@ pub(crate) async fn complete_auth_request( .await?; if let IdentityTokenResponse::Authenticated(r) = response { + let access_token_obj: JwtToken = r.access_token.parse()?; + let kdf = Kdf::default(); client.internal.set_tokens( @@ -95,13 +98,14 @@ pub(crate) async fn complete_auth_request( r.refresh_token.clone(), r.expires_in, ); - client - .internal - .set_login_method(LoginMethod::User(UserLoginMethod::Username { + client.internal.set_login_method(LoginMethod::User { + method: UserLoginMethod::Username { client_id: "web".to_owned(), email: auth_req.email.to_owned(), kdf: kdf.clone(), - })); + }, + user_id: access_token_obj.sub.parse()?, + }); let method = match res.master_password_hash { Some(_) => AuthRequestMethod::MasterKey { @@ -116,7 +120,7 @@ pub(crate) async fn complete_auth_request( client .crypto() .initialize_user_crypto(InitUserCryptoRequest { - user_id: None, + user_id: access_token_obj.sub.parse()?, kdf_params: kdf, email: auth_req.email, private_key: require!(r.private_key).parse()?, diff --git a/crates/bitwarden-core/src/auth/login/mod.rs b/crates/bitwarden-core/src/auth/login/mod.rs index e186ac043..bdfd51a4e 100644 --- a/crates/bitwarden-core/src/auth/login/mod.rs +++ b/crates/bitwarden-core/src/auth/login/mod.rs @@ -42,6 +42,8 @@ pub enum LoginError { Serde(#[from] serde_json::Error), #[error(transparent)] InvalidBase64(#[from] base64::DecodeError), + #[error(transparent)] + Uuid(#[from] uuid::Error), #[error(transparent)] MissingField(#[from] crate::MissingFieldError), diff --git a/crates/bitwarden-core/src/auth/login/password.rs b/crates/bitwarden-core/src/auth/login/password.rs index 76656d91b..c82a95740 100644 --- a/crates/bitwarden-core/src/auth/login/password.rs +++ b/crates/bitwarden-core/src/auth/login/password.rs @@ -34,18 +34,23 @@ pub(crate) async fn login_password( let response = request_identity_tokens(client, input, &password_hash).await?; if let IdentityTokenResponse::Authenticated(r) = &response { + use crate::auth::JwtToken; + + let access_token_obj: JwtToken = r.access_token.parse()?; + client.internal.set_tokens( r.access_token.clone(), r.refresh_token.clone(), r.expires_in, ); - client - .internal - .set_login_method(LoginMethod::User(UserLoginMethod::Username { + client.internal.set_login_method(LoginMethod::User { + method: UserLoginMethod::Username { client_id: "web".to_owned(), email: input.email.to_owned(), kdf: input.kdf.to_owned(), - })); + }, + user_id: access_token_obj.sub.parse()?, + }); let user_key: EncString = require!(r.key.as_deref()).parse()?; let private_key: EncString = require!(r.private_key.as_deref()).parse()?; diff --git a/crates/bitwarden-core/src/auth/password/validate.rs b/crates/bitwarden-core/src/auth/password/validate.rs index 229c7fde7..f36510225 100644 --- a/crates/bitwarden-core/src/auth/password/validate.rs +++ b/crates/bitwarden-core/src/auth/password/validate.rs @@ -18,7 +18,11 @@ pub(crate) fn validate_password( .ok_or(NotAuthenticatedError)?; #[allow(irrefutable_let_patterns)] - if let LoginMethod::User(login_method) = login_method.as_ref() { + if let LoginMethod::User { + method: login_method, + .. + } = login_method.as_ref() + { match login_method { UserLoginMethod::Username { email, kdf, .. } | UserLoginMethod::ApiKey { email, kdf, .. } => { @@ -50,7 +54,11 @@ pub(crate) fn validate_password_user_key( .ok_or(NotAuthenticatedError)?; #[allow(irrefutable_let_patterns)] - if let LoginMethod::User(login_method) = login_method.as_ref() { + if let LoginMethod::User { + method: login_method, + .. + } = login_method.as_ref() + { match login_method { UserLoginMethod::Username { email, kdf, .. } | UserLoginMethod::ApiKey { email, kdf, .. } => { @@ -91,15 +99,16 @@ mod tests { use crate::client::{Client, LoginMethod, UserLoginMethod}; let client = Client::new(None); - client - .internal - .set_login_method(LoginMethod::User(UserLoginMethod::Username { + client.internal.set_login_method(LoginMethod::User { + method: UserLoginMethod::Username { email: "test@bitwarden.com".to_string(), kdf: Kdf::PBKDF2 { iterations: NonZeroU32::new(100_000).unwrap(), }, client_id: "1".to_string(), - })); + }, + user_id: uuid::Uuid::new_v4(), + }); let password = "password123".to_string(); let password_hash = "7kTqkF1pY/3JeOu73N9kR99fDDe9O1JOZaVc7KH3lsU=".to_string(); @@ -125,13 +134,14 @@ mod tests { iterations: NonZeroU32::new(600_000).unwrap(), }; - client - .internal - .set_login_method(LoginMethod::User(UserLoginMethod::Username { + client.internal.set_login_method(LoginMethod::User { + method: UserLoginMethod::Username { email: email.to_string(), kdf: kdf.clone(), client_id: "1".to_string(), - })); + }, + user_id: uuid::Uuid::new_v4(), + }); let master_key = MasterKey::derive(password, email, &kdf).unwrap(); @@ -173,13 +183,14 @@ mod tests { iterations: NonZeroU32::new(600_000).unwrap(), }; - client - .internal - .set_login_method(LoginMethod::User(UserLoginMethod::Username { + client.internal.set_login_method(LoginMethod::User { + method: UserLoginMethod::Username { email: email.to_string(), kdf: kdf.clone(), client_id: "1".to_string(), - })); + }, + user_id: uuid::Uuid::new_v4(), + }); let master_key = MasterKey::derive(password, email, &kdf).unwrap(); diff --git a/crates/bitwarden-core/src/auth/pin.rs b/crates/bitwarden-core/src/auth/pin.rs index c337f9327..12ec447e2 100644 --- a/crates/bitwarden-core/src/auth/pin.rs +++ b/crates/bitwarden-core/src/auth/pin.rs @@ -18,7 +18,11 @@ pub(crate) fn validate_pin( .ok_or(NotAuthenticatedError)?; #[allow(irrefutable_let_patterns)] - let LoginMethod::User(login_method) = login_method.as_ref() else { + let LoginMethod::User { + method: login_method, + .. + } = login_method.as_ref() + else { return Err(NotAuthenticatedError)?; }; @@ -47,6 +51,7 @@ mod tests { use std::num::NonZeroU32; use bitwarden_crypto::{Kdf, MasterKey}; + use uuid::Uuid; use super::*; use crate::client::{Client, LoginMethod, UserLoginMethod}; @@ -60,13 +65,14 @@ mod tests { iterations: NonZeroU32::new(600_000).unwrap(), }; - client - .internal - .set_login_method(LoginMethod::User(UserLoginMethod::Username { + client.internal.set_login_method(LoginMethod::User { + method: UserLoginMethod::Username { email: email.to_string(), kdf: kdf.clone(), client_id: "1".to_string(), - })); + }, + user_id: Uuid::new_v4(), + }); let master_key = MasterKey::derive(password, email, &kdf).unwrap(); diff --git a/crates/bitwarden-core/src/auth/renew.rs b/crates/bitwarden-core/src/auth/renew.rs index 7b3e6f02c..c110e4a43 100644 --- a/crates/bitwarden-core/src/auth/renew.rs +++ b/crates/bitwarden-core/src/auth/renew.rs @@ -40,7 +40,7 @@ pub(crate) async fn renew_token(client: &InternalClient) -> Result<(), LoginErro .clone(); let res = match login_method.as_ref() { - LoginMethod::User(u) => match u { + LoginMethod::User { method: u, .. } => match u { UserLoginMethod::Username { client_id, .. } => { let refresh = tokens.refresh_token.ok_or(NotAuthenticatedError)?; diff --git a/crates/bitwarden-core/src/auth/tde.rs b/crates/bitwarden-core/src/auth/tde.rs index 570a28fd2..63fd600b8 100644 --- a/crates/bitwarden-core/src/auth/tde.rs +++ b/crates/bitwarden-core/src/auth/tde.rs @@ -3,6 +3,7 @@ use bitwarden_crypto::{ AsymmetricPublicCryptoKey, DeviceKey, EncString, Kdf, SymmetricCryptoKey, TrustDeviceResponse, UnsignedSharedKey, UserKey, }; +use uuid::Uuid; use crate::{client::encryption_settings::EncryptionSettingsError, Client}; @@ -14,6 +15,7 @@ pub(super) fn make_register_tde_keys( email: String, org_public_key: String, remember_device: bool, + user_id: Uuid, ) -> Result { let public_key = AsymmetricPublicCryptoKey::from_der(&STANDARD.decode(org_public_key)?)?; @@ -30,13 +32,14 @@ pub(super) fn make_register_tde_keys( client .internal - .set_login_method(crate::client::LoginMethod::User( - crate::client::UserLoginMethod::Username { + .set_login_method(crate::client::LoginMethod::User { + user_id, + method: crate::client::UserLoginMethod::Username { client_id: "".to_owned(), email, kdf: Kdf::default(), }, - )); + }); client.internal.initialize_user_crypto_decrypted_key( user_key.0, key_pair.private.clone(), diff --git a/crates/bitwarden-core/src/client/client.rs b/crates/bitwarden-core/src/client/client.rs index 7fcec2ace..e1fc740f1 100644 --- a/crates/bitwarden-core/src/client/client.rs +++ b/crates/bitwarden-core/src/client/client.rs @@ -1,4 +1,4 @@ -use std::sync::{Arc, OnceLock, RwLock}; +use std::sync::{Arc, RwLock}; use bitwarden_crypto::KeyStore; use reqwest::header::{self, HeaderValue}; @@ -76,7 +76,6 @@ impl Client { Self { internal: Arc::new(InternalClient { - user_id: OnceLock::new(), tokens: RwLock::new(Tokens::default()), login_method: RwLock::new(None), #[cfg(feature = "internal")] diff --git a/crates/bitwarden-core/src/client/encryption_settings.rs b/crates/bitwarden-core/src/client/encryption_settings.rs index ab8d84cd4..2e4b583bc 100644 --- a/crates/bitwarden-core/src/client/encryption_settings.rs +++ b/crates/bitwarden-core/src/client/encryption_settings.rs @@ -9,7 +9,7 @@ use uuid::Uuid; #[cfg(any(feature = "internal", feature = "secrets"))] use crate::key_management::{KeyIds, SymmetricKeyId}; -use crate::{error::UserIdAlreadySetError, MissingPrivateKeyError, VaultLockedError}; +use crate::{MissingPrivateKeyError, VaultLockedError}; #[allow(missing_docs)] #[bitwarden_error(flat)] @@ -29,9 +29,6 @@ pub enum EncryptionSettingsError { #[error(transparent)] MissingPrivateKey(#[from] MissingPrivateKeyError), - - #[error(transparent)] - UserIdAlreadySetError(#[from] UserIdAlreadySetError), } #[allow(missing_docs)] diff --git a/crates/bitwarden-core/src/client/internal.rs b/crates/bitwarden-core/src/client/internal.rs index 8749a4d32..47317bbcb 100644 --- a/crates/bitwarden-core/src/client/internal.rs +++ b/crates/bitwarden-core/src/client/internal.rs @@ -1,4 +1,4 @@ -use std::sync::{Arc, OnceLock, RwLock}; +use std::sync::{Arc, RwLock}; use bitwarden_crypto::KeyStore; #[cfg(any(feature = "internal", feature = "secrets"))] @@ -12,8 +12,7 @@ use super::encryption_settings::EncryptionSettings; #[cfg(feature = "secrets")] use super::login_method::ServiceAccountLoginMethod; use crate::{ - auth::renew::renew_token, client::login_method::LoginMethod, error::UserIdAlreadySetError, - key_management::KeyIds, DeviceType, + auth::renew::renew_token, client::login_method::LoginMethod, key_management::KeyIds, DeviceType, }; #[cfg(feature = "internal")] use crate::{ @@ -45,7 +44,6 @@ pub(crate) struct Tokens { #[allow(missing_docs)] #[derive(Debug)] pub struct InternalClient { - pub(crate) user_id: OnceLock, pub(crate) tokens: RwLock, pub(crate) login_method: RwLock>>, @@ -153,9 +151,10 @@ impl InternalClient { .expect("RwLock is not poisoned") .as_deref() { - Some(LoginMethod::User( - UserLoginMethod::Username { kdf, .. } | UserLoginMethod::ApiKey { kdf, .. }, - )) => Ok(kdf.clone()), + Some(LoginMethod::User { + method: UserLoginMethod::Username { kdf, .. } | UserLoginMethod::ApiKey { kdf, .. }, + .. + }) => Ok(kdf.clone()), _ => Err(NotAuthenticatedError), } } @@ -182,14 +181,17 @@ impl InternalClient { &self.key_store } - #[allow(missing_docs)] - pub fn init_user_id(&self, user_id: Uuid) -> Result<(), UserIdAlreadySetError> { - self.user_id.set(user_id).map_err(|_| UserIdAlreadySetError) - } - - #[allow(missing_docs)] + /// Returns the user's ID if logged in as a user. pub fn get_user_id(&self) -> Option { - self.user_id.get().copied() + match self + .login_method + .read() + .expect("RwLock is not poisoned") + .as_deref() + { + Some(LoginMethod::User { user_id, .. }) => Some(*user_id), + _ => None, + } } #[cfg(feature = "internal")] diff --git a/crates/bitwarden-core/src/client/login_method.rs b/crates/bitwarden-core/src/client/login_method.rs index 67db15a71..143655865 100644 --- a/crates/bitwarden-core/src/client/login_method.rs +++ b/crates/bitwarden-core/src/client/login_method.rs @@ -2,7 +2,6 @@ use std::path::PathBuf; use bitwarden_crypto::Kdf; -#[cfg(feature = "secrets")] use uuid::Uuid; #[cfg(feature = "secrets")] @@ -11,7 +10,10 @@ use crate::auth::AccessToken; #[derive(Debug)] pub(crate) enum LoginMethod { #[allow(dead_code)] - User(UserLoginMethod), + User { + user_id: Uuid, + method: UserLoginMethod, + }, // TODO: Organizations supports api key // Organization(OrganizationLoginMethod), #[cfg(feature = "secrets")] diff --git a/crates/bitwarden-core/src/client/test_accounts.rs b/crates/bitwarden-core/src/client/test_accounts.rs index 48a5cdba9..9577524ff 100644 --- a/crates/bitwarden-core/src/client/test_accounts.rs +++ b/crates/bitwarden-core/src/client/test_accounts.rs @@ -118,7 +118,7 @@ pub struct TestAccount { pub fn test_bitwarden_com_account() -> TestAccount { TestAccount { user: InitUserCryptoRequest { - user_id: Some(uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8")), + user_id: uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8"), kdf_params: Kdf::PBKDF2 { iterations: 600_000.try_into().unwrap(), }, @@ -178,7 +178,7 @@ pub fn test_bitwarden_com_account() -> TestAccount { pub fn test_legacy_user_key_account() -> TestAccount { TestAccount { user: InitUserCryptoRequest { - user_id: Some(uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8")), + user_id: uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8"), kdf_params: Kdf::PBKDF2 { iterations: 600_000.try_into().unwrap(), }, diff --git a/crates/bitwarden-core/src/error.rs b/crates/bitwarden-core/src/error.rs index cafd2d24a..19af6c621 100644 --- a/crates/bitwarden-core/src/error.rs +++ b/crates/bitwarden-core/src/error.rs @@ -48,11 +48,6 @@ impl_bitwarden_error!(IdentityError, ApiError); #[error("The client is not authenticated or the session has expired")] pub struct NotAuthenticatedError; -/// Client's user ID is already set. -#[derive(Debug, Error)] -#[error("The client user ID is already set")] -pub struct UserIdAlreadySetError; - /// Missing required field. #[derive(Debug, Error)] #[error("The response received was missing a required field: {0}")] diff --git a/crates/bitwarden-core/src/key_management/crypto.rs b/crates/bitwarden-core/src/key_management/crypto.rs index 1aaca34c2..9b752385a 100644 --- a/crates/bitwarden-core/src/key_management/crypto.rs +++ b/crates/bitwarden-core/src/key_management/crypto.rs @@ -44,7 +44,7 @@ pub enum CryptoClientError { #[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))] pub struct InitUserCryptoRequest { /// The user's ID. - pub user_id: Option, + pub user_id: uuid::Uuid, /// The user's KDF parameters, as received from the prelogin request pub kdf_params: Kdf, /// The user's email address @@ -137,10 +137,6 @@ pub(super) async fn initialize_user_crypto( use crate::auth::{auth_request_decrypt_master_key, auth_request_decrypt_user_key}; - if let Some(user_id) = req.user_id { - client.internal.init_user_id(user_id)?; - } - match req.method { InitUserCryptoMethod::Password { password, user_key } => { let master_key = MasterKey::derive(&password, &req.email, &req.kdf_params)?; @@ -229,13 +225,14 @@ pub(super) async fn initialize_user_crypto( client .internal - .set_login_method(crate::client::LoginMethod::User( - crate::client::UserLoginMethod::Username { + .set_login_method(crate::client::LoginMethod::User { + user_id: req.user_id, + method: crate::client::UserLoginMethod::Username { client_id: "".to_string(), email: req.email, kdf: req.kdf_params, }, - )); + }); Ok(()) } @@ -299,10 +296,12 @@ pub(super) fn update_password( // Derive a new master key from password let new_master_key = match login_method.as_ref() { - LoginMethod::User( - UserLoginMethod::Username { email, kdf, .. } - | UserLoginMethod::ApiKey { email, kdf, .. }, - ) => MasterKey::derive(&new_password, email, kdf)?, + LoginMethod::User { + method: + UserLoginMethod::Username { email, kdf, .. } + | UserLoginMethod::ApiKey { email, kdf, .. }, + .. + } => MasterKey::derive(&new_password, email, kdf)?, #[cfg(feature = "secrets")] LoginMethod::ServiceAccount(_) => return Err(NotAuthenticatedError)?, }; @@ -382,10 +381,12 @@ fn derive_pin_protected_user_key( use bitwarden_crypto::PinKey; let derived_key = match login_method { - LoginMethod::User( - UserLoginMethod::Username { email, kdf, .. } - | UserLoginMethod::ApiKey { email, kdf, .. }, - ) => PinKey::derive(pin.as_bytes(), email.as_bytes(), kdf)?, + LoginMethod::User { + method: + UserLoginMethod::Username { email, kdf, .. } + | UserLoginMethod::ApiKey { email, kdf, .. }, + .. + } => PinKey::derive(pin.as_bytes(), email.as_bytes(), kdf)?, #[cfg(feature = "secrets")] LoginMethod::ServiceAccount(_) => return Err(NotAuthenticatedError)?, }; @@ -633,7 +634,7 @@ mod tests { initialize_user_crypto( & client, InitUserCryptoRequest { - user_id: Some(uuid::Uuid::new_v4()), + user_id: uuid::Uuid::new_v4(), kdf_params: kdf.clone(), email: "test@bitwarden.com".into(), private_key: priv_key.to_owned(), @@ -654,7 +655,7 @@ mod tests { initialize_user_crypto( &client2, InitUserCryptoRequest { - user_id: Some(uuid::Uuid::new_v4()), + user_id: uuid::Uuid::new_v4(), kdf_params: kdf.clone(), email: "test@bitwarden.com".into(), private_key: priv_key.to_owned(), @@ -711,7 +712,7 @@ mod tests { initialize_user_crypto( & client, InitUserCryptoRequest { - user_id: Some(uuid::Uuid::new_v4()), + user_id: uuid::Uuid::new_v4(), kdf_params: Kdf::PBKDF2 { iterations: 100_000.try_into().unwrap(), }, @@ -734,7 +735,7 @@ mod tests { initialize_user_crypto( &client2, InitUserCryptoRequest { - user_id: Some(uuid::Uuid::new_v4()), + user_id: uuid::Uuid::new_v4(), kdf_params: Kdf::PBKDF2 { iterations: 100_000.try_into().unwrap(), }, @@ -778,7 +779,7 @@ mod tests { initialize_user_crypto( &client3, InitUserCryptoRequest { - user_id: Some(uuid::Uuid::new_v4()), + user_id: uuid::Uuid::new_v4(), kdf_params: Kdf::PBKDF2 { iterations: 100_000.try_into().unwrap(), }, diff --git a/crates/bitwarden-core/src/platform/get_user_api_key.rs b/crates/bitwarden-core/src/platform/get_user_api_key.rs index a127abab6..124acd251 100644 --- a/crates/bitwarden-core/src/platform/get_user_api_key.rs +++ b/crates/bitwarden-core/src/platform/get_user_api_key.rs @@ -78,7 +78,11 @@ fn build_secret_verification_request( login_method: &LoginMethod, input: &SecretVerificationRequest, ) -> Result { - if let LoginMethod::User(UserLoginMethod::Username { email, kdf, .. }) = login_method { + if let LoginMethod::User { + method: UserLoginMethod::Username { email, kdf, .. }, + .. + } = login_method + { let master_password_hash = input .master_password .as_ref() diff --git a/crates/bitwarden-core/tests/register.rs b/crates/bitwarden-core/tests/register.rs index 2b93f8227..063f632a6 100644 --- a/crates/bitwarden-core/tests/register.rs +++ b/crates/bitwarden-core/tests/register.rs @@ -29,7 +29,7 @@ async fn test_register_initialize_crypto() { client .crypto() .initialize_user_crypto(InitUserCryptoRequest { - user_id: Some(uuid::Uuid::new_v4()), + user_id: uuid::Uuid::new_v4(), kdf_params: kdf, email: email.to_owned(), private_key: register_response.keys.private, diff --git a/crates/bitwarden-uniffi/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt b/crates/bitwarden-uniffi/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt index dd759516b..5925dfa65 100644 --- a/crates/bitwarden-uniffi/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt +++ b/crates/bitwarden-uniffi/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt @@ -250,7 +250,7 @@ class MainActivity : FragmentActivity() { client.crypto().initializeUserCrypto( InitUserCryptoRequest( - userId = null, + userId = "fc0243b7-38f8-4f9c-af7e-e459298eefc3", kdfParams = kdf, email = EMAIL, privateKey = loginBody.PrivateKey, @@ -336,7 +336,7 @@ class MainActivity : FragmentActivity() { GlobalScope.launch { client.crypto().initializeUserCrypto( InitUserCryptoRequest( - userId = null, + userId = "fc0243b7-38f8-4f9c-af7e-e459298eefc3", kdfParams = kdf, email = EMAIL, privateKey = privateKey!!, @@ -375,7 +375,7 @@ class MainActivity : FragmentActivity() { GlobalScope.launch { client.crypto().initializeUserCrypto( InitUserCryptoRequest( - userId = null, + userId = "fc0243b7-38f8-4f9c-af7e-e459298eefc3", kdfParams = kdf, email = EMAIL, privateKey = privateKey!!, diff --git a/crates/bitwarden-uniffi/src/auth/mod.rs b/crates/bitwarden-uniffi/src/auth/mod.rs index 5f90b1673..1b34c7aed 100644 --- a/crates/bitwarden-uniffi/src/auth/mod.rs +++ b/crates/bitwarden-uniffi/src/auth/mod.rs @@ -3,6 +3,7 @@ use bitwarden_core::auth::{ RegisterKeyResponse, RegisterTdeKeyResponse, }; use bitwarden_crypto::{EncString, HashPurpose, Kdf, TrustDeviceResponse, UnsignedSharedKey}; +use uuid::Uuid; use crate::error::{Error, Result}; @@ -69,11 +70,12 @@ impl AuthClient { email: String, org_public_key: String, remember_device: bool, + user_id: Uuid, ) -> Result { Ok(self .0 .auth() - .make_register_tde_keys(email, org_public_key, remember_device) + .make_register_tde_keys(email, org_public_key, remember_device, user_id) .map_err(Error::EncryptionSettings)?) } diff --git a/crates/bitwarden-uniffi/swift/iOS/App/ContentView.swift b/crates/bitwarden-uniffi/swift/iOS/App/ContentView.swift index 6651785d7..dd40b8a42 100644 --- a/crates/bitwarden-uniffi/swift/iOS/App/ContentView.swift +++ b/crates/bitwarden-uniffi/swift/iOS/App/ContentView.swift @@ -189,7 +189,7 @@ struct ContentView: View { try await clientCrypto.initializeUserCrypto( req: InitUserCryptoRequest( - userId: nil, + userId: "fc0243b7-38f8-4f9c-af7e-e459298eefc3", kdfParams: kdf, email: EMAIL, privateKey: loginData.PrivateKey, @@ -248,7 +248,7 @@ struct ContentView: View { let key = biometricRetrieveValue()! try await clientCrypto.initializeUserCrypto(req: InitUserCryptoRequest( - userId: nil, + userId: "fc0243b7-38f8-4f9c-af7e-e459298eefc3", kdfParams: kdf, email: EMAIL, privateKey: privateKey, @@ -276,7 +276,7 @@ struct ContentView: View { let pinProtectedUserKey = defaults.string(forKey: "pinProtectedUserKey")! try await clientCrypto.initializeUserCrypto(req: InitUserCryptoRequest( - userId: nil, + userId: "fc0243b7-38f8-4f9c-af7e-e459298eefc3", kdfParams: kdf, email: EMAIL, privateKey: privateKey,