|
|
|
@ -26,6 +26,8 @@ use crate::{ |
|
|
|
util::{NumberOrString, convert_json_key_lcase_first}, |
|
|
|
}; |
|
|
|
|
|
|
|
use super::accounts::{AuthenticationData, UnlockData}; |
|
|
|
|
|
|
|
pub fn routes() -> Vec<Route> { |
|
|
|
routes![ |
|
|
|
get_organization, |
|
|
|
@ -2939,9 +2941,14 @@ struct OrganizationUserResetPasswordEnrollmentRequest { |
|
|
|
#[derive(Deserialize)] |
|
|
|
#[serde(rename_all = "camelCase")] |
|
|
|
struct OrganizationUserRecoverAccountRequest { |
|
|
|
// Legacy payload
|
|
|
|
new_master_password_hash: Option<String>, |
|
|
|
key: Option<String>, |
|
|
|
|
|
|
|
// Current payload
|
|
|
|
authentication_data: Option<AuthenticationData>, |
|
|
|
unlock_data: Option<UnlockData>, |
|
|
|
|
|
|
|
#[serde(default)] |
|
|
|
reset_master_password: bool, |
|
|
|
#[serde(default)] |
|
|
|
@ -3054,13 +3061,23 @@ async fn recover_account( |
|
|
|
} |
|
|
|
|
|
|
|
if req.reset_master_password { |
|
|
|
if let Some(key) = req.key |
|
|
|
&& let Some(hash) = req.new_master_password_hash |
|
|
|
let (new_master_password_hash, new_key) = if let (Some(authentication_data), Some(unlock_data)) = |
|
|
|
(req.authentication_data, req.unlock_data) |
|
|
|
{ |
|
|
|
user.set_password(hash.as_str(), Some(key), true, None, &conn).await?; |
|
|
|
authentication_data.check(&user, &unlock_data)?; |
|
|
|
|
|
|
|
if !authentication_data.kdf.matches_user(&user) { |
|
|
|
err!("KDF settings do not match the user account") |
|
|
|
} |
|
|
|
|
|
|
|
(authentication_data.master_password_authentication_hash, unlock_data.master_key_wrapped_user_key) |
|
|
|
} else if let (Some(new_master_password_hash), Some(new_key)) = (req.new_master_password_hash, req.key) { |
|
|
|
(new_master_password_hash, new_key) |
|
|
|
} else { |
|
|
|
err_code!("Unprocessable request", "Missing fields to reset password", Status::UnprocessableEntity.code); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
user.set_password(&new_master_password_hash, Some(new_key), true, None, &conn).await?; |
|
|
|
} |
|
|
|
|
|
|
|
if req.reset_two_factor { |
|
|
|
@ -3118,6 +3135,7 @@ async fn get_reset_password_details( |
|
|
|
"kdfIterations": user.client_kdf_iter, |
|
|
|
"kdfMemory": user.client_kdf_memory, |
|
|
|
"kdfParallelism": user.client_kdf_parallelism, |
|
|
|
"masterPasswordSalt": user.master_password_salt(), |
|
|
|
"resetPasswordKey": member.reset_password_key, |
|
|
|
"encryptedPrivateKey": org.private_key, |
|
|
|
}))) |
|
|
|
|