Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Extract legacy domain from contacts

Manav Rathi9f29a279c764
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 5cd5953e4b..59432ef68d 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2443,6 +2443,7 @@ version = "0.0.0"
dependencies = [
"ente-accounts",
"ente-core",
+ "ente-legacy",
"ente-test-support",
"hmac 0.13.0",
"md-5 0.11.0",
@@ -2451,7 +2452,6 @@ dependencies = [
"serde",
"serde_json",
"sha1 0.11.0",
- "sha2 0.11.0",
"thiserror 2.0.18",
"tokio",
"uuid",
@@ -2495,6 +2495,7 @@ dependencies = [
"ente-accounts",
"ente-contacts",
"ente-core",
+ "ente-legacy",
"ente-wasm-log",
"js-sys",
"md-5 0.11.0",
@@ -2586,12 +2587,25 @@ dependencies = [
"tiff 0.10.3",
]
+[[package]]
+name = "ente-legacy"
+version = "0.0.0"
+dependencies = [
+ "ente-accounts",
+ "ente-core",
+ "serde",
+ "serde_json",
+ "sha2 0.11.0",
+ "thiserror 2.0.18",
+ "uuid",
+]
+
[[package]]
name = "ente-legacy-wasm"
version = "0.0.0"
dependencies = [
- "ente-contacts",
"ente-core",
+ "ente-legacy",
"ente-wasm-log",
"js-sys",
"serde",
@@ -2609,6 +2623,7 @@ dependencies = [
"ente-contacts",
"ente-core",
"ente-frb-log",
+ "ente-legacy",
"ente-ml",
"flutter_rust_bridge",
]
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index f4dcbf5265..ef399090ec 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -26,6 +26,7 @@ members = [
"crates/ensu",
"crates/ensu-crypto",
"crates/image",
+ "crates/legacy",
"crates/ml",
"crates/paste",
"crates/photos",
@@ -43,6 +44,7 @@ ente-ensu = { path = "crates/ensu" }
ente-ensu-crypto = { path = "crates/ensu-crypto" }
ente-frb-log = { path = "bindings/frb/log" }
ente-image = { path = "crates/image" }
+ente-legacy = { path = "crates/legacy" }
ente-ml = { path = "crates/ml" }
ente-paste = { path = "crates/paste" }
ente-photos = { path = "crates/photos" }
diff --git a/rust/bindings/frb/locker/Cargo.toml b/rust/bindings/frb/locker/Cargo.toml
index a5155678f2..59e37cc067 100644
--- a/rust/bindings/frb/locker/Cargo.toml
+++ b/rust/bindings/frb/locker/Cargo.toml
@@ -11,6 +11,7 @@ ente-assets.workspace = true
ente-contacts.workspace = true
ente-core.workspace = true
ente-frb-log.workspace = true
+ente-legacy.workspace = true
ente-ml.workspace = true
flutter_rust_bridge.workspace = true
diff --git a/rust/bindings/frb/locker/src/api/contacts.rs b/rust/bindings/frb/locker/src/api/contacts.rs
index f675e3e206..0959abc9fc 100644
--- a/rust/bindings/frb/locker/src/api/contacts.rs
+++ b/rust/bindings/frb/locker/src/api/contacts.rs
@@ -1,6 +1,10 @@
use std::sync::Arc;
-use ente_contacts::{LegacyKitOwnerRecoverySession, LegacyKitRecoveryInitiator};
+use ente_core::{
+ crypto::SecretVec,
+ http::{Api, ApiConfig, Auth, Http},
+};
+use ente_legacy::{LegacyClient, LegacyKitOwnerRecoverySession, LegacyKitRecoveryInitiator};
use flutter_rust_bridge::frb;
#[frb]
@@ -26,11 +30,25 @@ impl From<ente_contacts::Error> for ContactsError {
K::Http => Self::Http { message },
K::Parse => Self::Parse { message },
K::Crypto => Self::Crypto { message },
- K::Auth => Self::Auth { message },
K::InvalidInput => Self::InvalidInput { message },
K::MissingEncryptedData => Self::MissingEncryptedData { message },
K::MissingEncryptedKey => Self::MissingEncryptedKey { message },
K::ProfilePictureNotFound => Self::ProfilePictureNotFound { message },
+ }
+ }
+}
+
+impl From<ente_legacy::Error> for ContactsError {
+ fn from(e: ente_legacy::Error) -> Self {
+ use ente_legacy::ErrorKind as K;
+ let message = ente_core::error::chain(&e);
+ match e.kind() {
+ K::Network => Self::Network { message },
+ K::Http => Self::Http { message },
+ K::Parse => Self::Parse { message },
+ K::Crypto => Self::Crypto { message },
+ K::Auth => Self::Auth { message },
+ K::InvalidInput => Self::InvalidInput { message },
K::ActiveRecoverySession => Self::ActiveRecoverySession { message },
}
}
@@ -148,10 +166,10 @@ pub enum LegacyKitVariant {
TwoOfThree,
}
-impl From<ente_contacts::LegacyKitVariant> for LegacyKitVariant {
- fn from(value: ente_contacts::LegacyKitVariant) -> Self {
+impl From<ente_legacy::LegacyKitVariant> for LegacyKitVariant {
+ fn from(value: ente_legacy::LegacyKitVariant) -> Self {
match value {
- ente_contacts::LegacyKitVariant::TwoOfThree => Self::TwoOfThree,
+ ente_legacy::LegacyKitVariant::TwoOfThree => Self::TwoOfThree,
}
}
}
@@ -166,14 +184,14 @@ pub enum LegacyKitRecoveryStatus {
Recovered,
}
-impl From<ente_contacts::LegacyKitRecoveryStatus> for LegacyKitRecoveryStatus {
- fn from(value: ente_contacts::LegacyKitRecoveryStatus) -> Self {
+impl From<ente_legacy::LegacyKitRecoveryStatus> for LegacyKitRecoveryStatus {
+ fn from(value: ente_legacy::LegacyKitRecoveryStatus) -> Self {
match value {
- ente_contacts::LegacyKitRecoveryStatus::Waiting => Self::Waiting,
- ente_contacts::LegacyKitRecoveryStatus::Ready => Self::Ready,
- ente_contacts::LegacyKitRecoveryStatus::Blocked => Self::Blocked,
- ente_contacts::LegacyKitRecoveryStatus::Cancelled => Self::Cancelled,
- ente_contacts::LegacyKitRecoveryStatus::Recovered => Self::Recovered,
+ ente_legacy::LegacyKitRecoveryStatus::Waiting => Self::Waiting,
+ ente_legacy::LegacyKitRecoveryStatus::Ready => Self::Ready,
+ ente_legacy::LegacyKitRecoveryStatus::Blocked => Self::Blocked,
+ ente_legacy::LegacyKitRecoveryStatus::Cancelled => Self::Cancelled,
+ ente_legacy::LegacyKitRecoveryStatus::Recovered => Self::Recovered,
}
}
}
@@ -188,8 +206,8 @@ pub struct LegacyKitRecoverySession {
pub created_at: i64,
}
-impl From<ente_contacts::LegacyKitRecoverySession> for LegacyKitRecoverySession {
- fn from(value: ente_contacts::LegacyKitRecoverySession) -> Self {
+impl From<ente_legacy::LegacyKitRecoverySession> for LegacyKitRecoverySession {
+ fn from(value: ente_legacy::LegacyKitRecoverySession) -> Self {
Self {
id: value.id,
kit_id: value.kit_id,
@@ -241,8 +259,8 @@ pub struct LegacyKitPart {
pub name: String,
}
-impl From<ente_contacts::LegacyKitPart> for LegacyKitPart {
- fn from(value: ente_contacts::LegacyKitPart) -> Self {
+impl From<ente_legacy::LegacyKitPart> for LegacyKitPart {
+ fn from(value: ente_legacy::LegacyKitPart) -> Self {
Self {
index: value.index,
name: value.name,
@@ -256,8 +274,8 @@ pub struct LegacyKitMetadata {
pub parts: Vec<LegacyKitPart>,
}
-impl From<ente_contacts::LegacyKitMetadata> for LegacyKitMetadata {
- fn from(value: ente_contacts::LegacyKitMetadata) -> Self {
+impl From<ente_legacy::LegacyKitMetadata> for LegacyKitMetadata {
+ fn from(value: ente_legacy::LegacyKitMetadata) -> Self {
Self {
parts: value.parts.into_iter().map(Into::into).collect(),
}
@@ -277,8 +295,8 @@ pub struct LegacyKit {
pub active_recovery_session: Option<LegacyKitRecoverySession>,
}
-impl From<ente_contacts::LegacyKit> for LegacyKit {
- fn from(value: ente_contacts::LegacyKit) -> Self {
+impl From<ente_legacy::LegacyKit> for LegacyKit {
+ fn from(value: ente_legacy::LegacyKit) -> Self {
Self {
id: value.id,
variant: value.variant.into(),
@@ -304,8 +322,8 @@ pub struct LegacyKitShare {
pub part_name: String,
}
-impl From<ente_contacts::LegacyKitShare> for LegacyKitShare {
- fn from(value: ente_contacts::LegacyKitShare) -> Self {
+impl From<ente_legacy::LegacyKitShare> for LegacyKitShare {
+ fn from(value: ente_legacy::LegacyKitShare) -> Self {
Self {
payload_version: value.payload_version,
variant: value.variant.into(),
@@ -325,8 +343,8 @@ pub struct LegacyKitCreateResult {
pub shares: Vec<LegacyKitShare>,
}
-impl From<ente_contacts::LegacyKitCreateResult> for LegacyKitCreateResult {
- fn from(value: ente_contacts::LegacyKitCreateResult) -> Self {
+impl From<ente_legacy::LegacyKitCreateResult> for LegacyKitCreateResult {
+ fn from(value: ente_legacy::LegacyKitCreateResult) -> Self {
Self {
kit: value.kit.into(),
shares: value.shares.into_iter().map(Into::into).collect(),
@@ -386,29 +404,41 @@ pub struct OpenContactsCtxResult {
#[frb(opaque)]
#[derive(Clone)]
pub struct ContactsCtx {
- inner: Arc<ente_contacts::ContactsCtx>,
+ api: Arc<Api>,
+ contacts: Arc<ente_contacts::ContactsClient>,
+ legacy: Arc<LegacyClient>,
}
#[frb]
pub async fn open_contacts_ctx(
input: OpenContactsCtxInput,
) -> Result<OpenContactsCtxResult, ContactsError> {
- let opened = ente_contacts::ContactsCtx::open(ente_contacts::OpenContactsCtxInput {
- base_url: input.base_url,
- auth_token: input.auth_token,
- user_id: input.user_id,
- master_key: input.master_key,
- cached_wrapped_root_contact_key: input.cached_wrapped_root_contact_key.map(Into::into),
- user_agent: input.user_agent,
- client_package: input.client_package,
- client_version: input.client_version,
- })
- .await
- .map_err(ContactsError::from)?;
+ let api = Arc::new(Api::new(
+ Http::new().map_err(ente_contacts::Error::from)?,
+ ApiConfig {
+ origin: input.base_url,
+ client_package: input.client_package,
+ client_version: input.client_version,
+ user_agent: input.user_agent,
+ auth: Some(Auth::User(input.auth_token)),
+ },
+ ));
+ let master_key = Arc::new(SecretVec::new(input.master_key));
+ let opened = ente_contacts::ContactsClient::open(
+ Arc::clone(&api),
+ Arc::clone(&master_key),
+ ente_contacts::OpenContactsInput {
+ user_id: input.user_id,
+ cached_wrapped_root_contact_key: input.cached_wrapped_root_contact_key.map(Into::into),
+ },
+ )?;
+ let legacy = LegacyClient::new(Arc::clone(&api), master_key);
Ok(OpenContactsCtxResult {
ctx: ContactsCtx {
- inner: Arc::new(opened.ctx),
+ api,
+ contacts: Arc::new(opened.client),
+ legacy: Arc::new(legacy),
},
wrapped_root_contact_key: opened.wrapped_root_contact_key.map(Into::into),
root_key_source: opened.root_key_source.into(),
@@ -418,22 +448,22 @@ pub async fn open_contacts_ctx(
impl ContactsCtx {
#[frb(sync)]
pub fn user_id(&self) -> i64 {
- self.inner.user_id()
+ self.contacts.user_id()
}
pub fn update_auth_token(&self, auth_token: String) {
- self.inner.update_auth_token(auth_token);
+ self.api.set_auth(Some(Auth::User(auth_token)));
}
#[frb(sync)]
pub fn current_wrapped_root_contact_key(&self) -> Option<WrappedRootContactKey> {
- self.inner
+ self.contacts
.current_wrapped_root_contact_key()
.map(Into::into)
}
pub async fn create_contact(&self, data: ContactData) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.create_contact(&data.into())
.await
.map(Into::into)
@@ -441,7 +471,7 @@ impl ContactsCtx {
}
pub async fn get_contact(&self, contact_id: String) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.get_contact(&contact_id)
.await
.map(Into::into)
@@ -453,7 +483,7 @@ impl ContactsCtx {
since_time: i64,
limit: u16,
) -> Result<Vec<ContactRecord>, ContactsError> {
- self.inner
+ self.contacts
.get_diff(since_time, limit)
.await
.map(|records| records.into_iter().map(Into::into).collect())
@@ -465,7 +495,7 @@ impl ContactsCtx {
contact_id: String,
data: ContactData,
) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.update_contact(&contact_id, &data.into())
.await
.map(Into::into)
@@ -473,7 +503,7 @@ impl ContactsCtx {
}
pub async fn delete_contact(&self, contact_id: String) -> Result<(), ContactsError> {
- self.inner
+ self.contacts
.delete_contact(&contact_id)
.await
.map_err(Into::into)
@@ -485,7 +515,7 @@ impl ContactsCtx {
attachment_type: AttachmentType,
attachment_bytes: Vec<u8>,
) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.set_attachment(&contact_id, attachment_type.into(), &attachment_bytes)
.await
.map(Into::into)
@@ -497,7 +527,7 @@ impl ContactsCtx {
contact_id: String,
attachment_type: AttachmentType,
) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.delete_attachment(&contact_id, attachment_type.into())
.await
.map(Into::into)
@@ -505,15 +535,15 @@ impl ContactsCtx {
}
pub async fn get_profile_picture(&self, contact_id: String) -> Result<Vec<u8>, ContactsError> {
- self.inner
+ self.contacts
.get_profile_picture(&contact_id)
.await
.map_err(Into::into)
}
pub async fn legacy_kits(&self) -> Result<Vec<LegacyKit>, ContactsError> {
- self.inner
- .legacy_kits()
+ self.legacy
+ .kits()
.await
.map(|kits| kits.into_iter().map(Into::into).collect())
.map_err(Into::into)
@@ -531,8 +561,8 @@ impl ContactsCtx {
.map_err(|_| ContactsError::InvalidInput {
message: "legacy kit requires exactly three part names".into(),
})?;
- self.inner
- .legacy_kit_create(
+ self.legacy
+ .create_kit(
&current_user_key_attrs.into(),
part_names,
notice_period_in_hours,
@@ -546,8 +576,8 @@ impl ContactsCtx {
&self,
kit_id: String,
) -> Result<Vec<LegacyKitShare>, ContactsError> {
- self.inner
- .legacy_kit_download_shares(&kit_id)
+ self.legacy
+ .download_kit_shares(&kit_id)
.await
.map(|shares| shares.into_iter().map(Into::into).collect())
.map_err(Into::into)
@@ -557,8 +587,8 @@ impl ContactsCtx {
&self,
kit_id: String,
) -> Result<LegacyKitOwnerRecoverySessionDetails, ContactsError> {
- self.inner
- .legacy_kit_recovery_session(&kit_id)
+ self.legacy
+ .kit_recovery_session(&kit_id)
.await
.map(Into::into)
.map_err(Into::into)
@@ -569,23 +599,20 @@ impl ContactsCtx {
kit_id: String,
notice_period_in_hours: i32,
) -> Result<(), ContactsError> {
- self.inner
- .legacy_kit_update_recovery_notice(&kit_id, notice_period_in_hours)
+ self.legacy
+ .update_kit_recovery_notice(&kit_id, notice_period_in_hours)
.await
.map_err(Into::into)
}
pub async fn legacy_kit_block_recovery(&self, kit_id: String) -> Result<(), ContactsError> {
- self.inner
- .legacy_kit_block_recovery(&kit_id)
+ self.legacy
+ .block_kit_recovery(&kit_id)
.await
.map_err(Into::into)
}
pub async fn legacy_kit_delete(&self, kit_id: String) -> Result<(), ContactsError> {
- self.inner
- .legacy_kit_delete(&kit_id)
- .await
- .map_err(Into::into)
+ self.legacy.delete_kit(&kit_id).await.map_err(Into::into)
}
}
diff --git a/rust/bindings/frb/photos/src/api/contacts.rs b/rust/bindings/frb/photos/src/api/contacts.rs
index 110aa89ebd..e359aefbb7 100644
--- a/rust/bindings/frb/photos/src/api/contacts.rs
+++ b/rust/bindings/frb/photos/src/api/contacts.rs
@@ -1,5 +1,9 @@
use std::sync::Arc;
+use ente_core::{
+ crypto::SecretVec,
+ http::{Api, ApiConfig, Auth, Http},
+};
use flutter_rust_bridge::frb;
#[frb]
@@ -25,12 +29,10 @@ impl From<ente_contacts::Error> for ContactsError {
K::Http => Self::Http { message },
K::Parse => Self::Parse { message },
K::Crypto => Self::Crypto { message },
- K::Auth => Self::Auth { message },
K::InvalidInput => Self::InvalidInput { message },
K::MissingEncryptedData => Self::MissingEncryptedData { message },
K::MissingEncryptedKey => Self::MissingEncryptedKey { message },
K::ProfilePictureNotFound => Self::ProfilePictureNotFound { message },
- K::ActiveRecoverySession => Self::ActiveRecoverySession { message },
}
}
}
@@ -156,29 +158,37 @@ pub struct OpenContactsCtxResult {
#[frb(opaque)]
#[derive(Clone)]
pub struct ContactsCtx {
- inner: Arc<ente_contacts::ContactsCtx>,
+ api: Arc<Api>,
+ contacts: Arc<ente_contacts::ContactsClient>,
}
#[frb]
pub async fn open_contacts_ctx(
input: OpenContactsCtxInput,
) -> Result<OpenContactsCtxResult, ContactsError> {
- let opened = ente_contacts::ContactsCtx::open(ente_contacts::OpenContactsCtxInput {
- base_url: input.base_url,
- auth_token: input.auth_token,
- user_id: input.user_id,
- master_key: input.master_key,
- cached_wrapped_root_contact_key: input.cached_wrapped_root_contact_key.map(Into::into),
- user_agent: input.user_agent,
- client_package: input.client_package,
- client_version: input.client_version,
- })
- .await
- .map_err(ContactsError::from)?;
+ let api = Arc::new(Api::new(
+ Http::new().map_err(ente_contacts::Error::from)?,
+ ApiConfig {
+ origin: input.base_url,
+ client_package: input.client_package,
+ client_version: input.client_version,
+ user_agent: input.user_agent,
+ auth: Some(Auth::User(input.auth_token)),
+ },
+ ));
+ let opened = ente_contacts::ContactsClient::open(
+ Arc::clone(&api),
+ Arc::new(SecretVec::new(input.master_key)),
+ ente_contacts::OpenContactsInput {
+ user_id: input.user_id,
+ cached_wrapped_root_contact_key: input.cached_wrapped_root_contact_key.map(Into::into),
+ },
+ )?;
Ok(OpenContactsCtxResult {
ctx: ContactsCtx {
- inner: Arc::new(opened.ctx),
+ api,
+ contacts: Arc::new(opened.client),
},
wrapped_root_contact_key: opened.wrapped_root_contact_key.map(Into::into),
root_key_source: opened.root_key_source.into(),
@@ -188,22 +198,22 @@ pub async fn open_contacts_ctx(
impl ContactsCtx {
#[frb(sync)]
pub fn user_id(&self) -> i64 {
- self.inner.user_id()
+ self.contacts.user_id()
}
pub fn update_auth_token(&self, auth_token: String) {
- self.inner.update_auth_token(auth_token);
+ self.api.set_auth(Some(Auth::User(auth_token)));
}
#[frb(sync)]
pub fn current_wrapped_root_contact_key(&self) -> Option<WrappedRootContactKey> {
- self.inner
+ self.contacts
.current_wrapped_root_contact_key()
.map(Into::into)
}
pub async fn create_contact(&self, data: ContactData) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.create_contact(&data.into())
.await
.map(Into::into)
@@ -211,7 +221,7 @@ impl ContactsCtx {
}
pub async fn get_contact(&self, contact_id: String) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.get_contact(&contact_id)
.await
.map(Into::into)
@@ -223,7 +233,7 @@ impl ContactsCtx {
since_time: i64,
limit: u16,
) -> Result<Vec<ContactRecord>, ContactsError> {
- self.inner
+ self.contacts
.get_diff(since_time, limit)
.await
.map(|records| records.into_iter().map(Into::into).collect())
@@ -235,7 +245,7 @@ impl ContactsCtx {
contact_id: String,
data: ContactData,
) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.update_contact(&contact_id, &data.into())
.await
.map(Into::into)
@@ -243,7 +253,7 @@ impl ContactsCtx {
}
pub async fn delete_contact(&self, contact_id: String) -> Result<(), ContactsError> {
- self.inner
+ self.contacts
.delete_contact(&contact_id)
.await
.map_err(Into::into)
@@ -255,7 +265,7 @@ impl ContactsCtx {
attachment_type: AttachmentType,
attachment_bytes: Vec<u8>,
) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.set_attachment(&contact_id, attachment_type.into(), &attachment_bytes)
.await
.map(Into::into)
@@ -267,7 +277,7 @@ impl ContactsCtx {
contact_id: String,
attachment_type: AttachmentType,
) -> Result<ContactRecord, ContactsError> {
- self.inner
+ self.contacts
.delete_attachment(&contact_id, attachment_type.into())
.await
.map(Into::into)
@@ -275,7 +285,7 @@ impl ContactsCtx {
}
pub async fn get_profile_picture(&self, contact_id: String) -> Result<Vec<u8>, ContactsError> {
- self.inner
+ self.contacts
.get_profile_picture(&contact_id)
.await
.map_err(Into::into)
diff --git a/rust/bindings/wasm/core/Cargo.toml b/rust/bindings/wasm/core/Cargo.toml
index 607e8d8010..44a9d283fb 100644
--- a/rust/bindings/wasm/core/Cargo.toml
+++ b/rust/bindings/wasm/core/Cargo.toml
@@ -9,6 +9,7 @@ crate-type = ["cdylib"]
ente-accounts.workspace = true
ente-contacts.workspace = true
ente-core.workspace = true
+ente-legacy.workspace = true
ente-wasm-log.workspace = true
js-sys.workspace = true
md-5.workspace = true
diff --git a/rust/bindings/wasm/core/src/contacts.rs b/rust/bindings/wasm/core/src/contacts.rs
index 0c67247157..d1407e6821 100644
--- a/rust/bindings/wasm/core/src/contacts.rs
+++ b/rust/bindings/wasm/core/src/contacts.rs
@@ -1,8 +1,13 @@
+use std::sync::Arc;
+
use ente_accounts::auth::KeyAttributes;
-use ente_contacts::{
- ContactsCtx, LegacyContactState, OpenContactsCtxInput, RootKeySource, WrappedRootContactKey,
+use ente_contacts::{ContactsClient, OpenContactsInput, RootKeySource, WrappedRootContactKey};
+use ente_core::{
+ b64,
+ crypto::SecretVec,
+ http::{Api, ApiConfig, Auth, Http},
};
-use ente_core::b64;
+use ente_legacy::{LegacyClient, LegacyContactState};
use js_sys::{Object, Reflect};
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen as swb;
@@ -50,11 +55,25 @@ impl From<ente_contacts::Error> for ContactsError {
K::Http => Self::Http { message },
K::Parse => Self::Parse { message },
K::Crypto => Self::Crypto { message },
- K::Auth => Self::Auth { message },
K::InvalidInput => Self::InvalidInput { message },
K::MissingEncryptedData => Self::MissingEncryptedData { message },
K::MissingEncryptedKey => Self::MissingEncryptedKey { message },
K::ProfilePictureNotFound => Self::ProfilePictureNotFound { message },
+ }
+ }
+}
+
+impl From<ente_legacy::Error> for ContactsError {
+ fn from(e: ente_legacy::Error) -> Self {
+ use ente_legacy::ErrorKind as K;
+ let message = ente_core::error::chain(&e);
+ match e.kind() {
+ K::Network => Self::Network { message },
+ K::Http => Self::Http { message },
+ K::Parse => Self::Parse { message },
+ K::Crypto => Self::Crypto { message },
+ K::Auth => Self::Auth { message },
+ K::InvalidInput => Self::InvalidInput { message },
K::ActiveRecoverySession => Self::ActiveRecoverySession { message },
}
}
@@ -123,24 +142,36 @@ pub async fn contacts_open_ctx(input: JsValue) -> Result<JsValue, ContactsError>
let master_key = b64::decode(&input.master_key_b64).map_err(|e| ContactsError::Decode {
message: e.to_string(),
})?;
-
- let result = ContactsCtx::open(OpenContactsCtxInput {
- base_url: input.base_url,
- auth_token: input.auth_token,
- user_id: input.user_id,
- master_key,
- cached_wrapped_root_contact_key: input.cached_wrapped_root_contact_key,
- user_agent: input.user_agent,
- client_package: input.client_package,
- client_version: input.client_version,
- })
- .await?;
+ let api = Arc::new(Api::new(
+ Http::new().map_err(ente_contacts::Error::from)?,
+ ApiConfig {
+ origin: input.base_url,
+ client_package: input.client_package,
+ client_version: input.client_version,
+ user_agent: input.user_agent,
+ auth: Some(Auth::User(input.auth_token)),
+ },
+ ));
+ let master_key = Arc::new(SecretVec::new(master_key));
+ let result = ContactsClient::open(
+ Arc::clone(&api),
+ Arc::clone(&master_key),
+ OpenContactsInput {
+ user_id: input.user_id,
+ cached_wrapped_root_contact_key: input.cached_wrapped_root_contact_key,
+ },
+ )?;
+ let legacy = LegacyClient::new(Arc::clone(&api), master_key);
let output = Object::new();
Reflect::set(
&output,
&JsValue::from_str("ctx"),
- &JsValue::from(ContactsCtxHandle { inner: result.ctx }),
+ &JsValue::from(ContactsCtxHandle {
+ api,
+ contacts: result.client,
+ legacy,
+ }),
)
.expect("setting ctx should not fail");
Reflect::set(
@@ -164,22 +195,24 @@ pub async fn contacts_open_ctx(input: JsValue) -> Result<JsValue, ContactsError>
#[wasm_bindgen]
pub struct ContactsCtxHandle {
- inner: ContactsCtx,
+ api: Arc<Api>,
+ contacts: ContactsClient,
+ legacy: LegacyClient,
}
#[wasm_bindgen]
impl ContactsCtxHandle {
pub fn update_auth_token(&self, auth_token: String) {
- self.inner.update_auth_token(auth_token);
+ self.api.set_auth(Some(Auth::User(auth_token)));
}
pub fn current_wrapped_root_contact_key(&self) -> Result<JsValue, ContactsError> {
- swb::to_value(&self.inner.current_wrapped_root_contact_key()).map_err(Into::into)
+ swb::to_value(&self.contacts.current_wrapped_root_contact_key()).map_err(Into::into)
}
pub async fn get_diff(&self, since_time: i64, limit: u16) -> Result<JsValue, ContactsError> {
let diff: Vec<ContactRecordJs> = self
- .inner
+ .contacts
.get_diff(since_time, limit)
.await?
.into_iter()
@@ -189,25 +222,25 @@ impl ContactsCtxHandle {
}
pub async fn get_profile_picture(&self, contact_id: &str) -> Result<Vec<u8>, ContactsError> {
- self.inner
+ self.contacts
.get_profile_picture(contact_id)
.await
.map_err(Into::into)
}
pub async fn legacy_get_info(&self) -> Result<JsValue, ContactsError> {
- let info = self.inner.legacy_info().await?;
+ let info = self.legacy.info().await?;
swb::to_value(&info).map_err(Into::into)
}
pub async fn legacy_public_key(&self, email: String) -> Result<JsValue, ContactsError> {
- let public_key = self.inner.legacy_public_key(&email).await?;
+ let public_key = self.legacy.public_key(&email).await?;
swb::to_value(&public_key).map_err(Into::into)
}
pub fn legacy_verification_id(&self, public_key_b64: String) -> Result<String, ContactsError> {
- self.inner
- .legacy_verification_id(&public_key_b64)
+ self.legacy
+ .verification_id(&public_key_b64)
.map_err(Into::into)
}
@@ -218,8 +251,8 @@ impl ContactsCtxHandle {
recovery_notice_in_days: Option<i32>,
) -> Result<(), ContactsError> {
let current_user_key_attrs: KeyAttributes = swb::from_value(current_user_key_attrs)?;
- self.inner
- .legacy_add_contact(&email, &current_user_key_attrs, recovery_notice_in_days)
+ self.legacy
+ .add_contact(&email, &current_user_key_attrs, recovery_notice_in_days)
.await
.map_err(Into::into)
}
@@ -231,8 +264,8 @@ impl ContactsCtxHandle {
state: JsValue,
) -> Result<(), ContactsError> {
let state: LegacyContactState = swb::from_value(state)?;
- self.inner
- .legacy_update_contact(user_id, emergency_contact_id, state)
+ self.legacy
+ .update_contact(user_id, emergency_contact_id, state)
.await
.map_err(Into::into)
}
@@ -242,8 +275,8 @@ impl ContactsCtxHandle {
emergency_contact_id: i64,
recovery_notice_in_days: i32,
) -> Result<(), ContactsError> {
- self.inner
- .legacy_update_recovery_notice(emergency_contact_id, recovery_notice_in_days)
+ self.legacy
+ .update_recovery_notice(emergency_contact_id, recovery_notice_in_days)
.await
.map_err(Into::into)
}
@@ -253,8 +286,8 @@ impl ContactsCtxHandle {
user_id: i64,
emergency_contact_id: i64,
) -> Result<(), ContactsError> {
- self.inner
- .legacy_start_recovery(user_id, emergency_contact_id)
+ self.legacy
+ .start_recovery(user_id, emergency_contact_id)
.await
.map_err(Into::into)
}
@@ -265,8 +298,8 @@ impl ContactsCtxHandle {
user_id: i64,
emergency_contact_id: i64,
) -> Result<(), ContactsError> {
- self.inner
- .legacy_stop_recovery(&recovery_id, user_id, emergency_contact_id)
+ self.legacy
+ .stop_recovery(&recovery_id, user_id, emergency_contact_id)
.await
.map_err(Into::into)
}
@@ -277,8 +310,8 @@ impl ContactsCtxHandle {
user_id: i64,
emergency_contact_id: i64,
) -> Result<(), ContactsError> {
- self.inner
- .legacy_reject_recovery(&recovery_id, user_id, emergency_contact_id)
+ self.legacy
+ .reject_recovery(&recovery_id, user_id, emergency_contact_id)
.await
.map_err(Into::into)
}
@@ -289,8 +322,8 @@ impl ContactsCtxHandle {
user_id: i64,
emergency_contact_id: i64,
) -> Result<(), ContactsError> {
- self.inner
- .legacy_approve_recovery(&recovery_id, user_id, emergency_contact_id)
+ self.legacy
+ .approve_recovery(&recovery_id, user_id, emergency_contact_id)
.await
.map_err(Into::into)
}
@@ -302,8 +335,8 @@ impl ContactsCtxHandle {
) -> Result<JsValue, ContactsError> {
let current_user_key_attrs: KeyAttributes = swb::from_value(current_user_key_attrs)?;
let bundle = self
- .inner
- .legacy_recovery_bundle(&recovery_id, &current_user_key_attrs)
+ .legacy
+ .recovery_bundle(&recovery_id, &current_user_key_attrs)
.await?;
swb::to_value(&LegacyRecoveryBundleJs {
recovery_key: b64::encode(bundle.recovery_key.as_ref()),
@@ -319,8 +352,8 @@ impl ContactsCtxHandle {
new_password: String,
) -> Result<(), ContactsError> {
let current_user_key_attrs: KeyAttributes = swb::from_value(current_user_key_attrs)?;
- self.inner
- .legacy_change_password(&recovery_id, &current_user_key_attrs, &new_password)
+ self.legacy
+ .change_password(&recovery_id, &current_user_key_attrs, &new_password)
.await
.map_err(Into::into)
}
diff --git a/rust/bindings/wasm/legacy/Cargo.toml b/rust/bindings/wasm/legacy/Cargo.toml
index 559d6939cc..2ad0e7dec7 100644
--- a/rust/bindings/wasm/legacy/Cargo.toml
+++ b/rust/bindings/wasm/legacy/Cargo.toml
@@ -6,8 +6,8 @@ edition = "2024"
crate-type = ["cdylib"]
[dependencies]
-ente-contacts.workspace = true
ente-core.workspace = true
+ente-legacy.workspace = true
ente-wasm-log.workspace = true
js-sys.workspace = true
serde.workspace = true
diff --git a/rust/bindings/wasm/legacy/src/lib.rs b/rust/bindings/wasm/legacy/src/lib.rs
index 5df24b5388..c214ac9da6 100644
--- a/rust/bindings/wasm/legacy/src/lib.rs
+++ b/rust/bindings/wasm/legacy/src/lib.rs
@@ -1,4 +1,4 @@
-use ente_contacts::{LegacyKitRecoveryClient, LegacyKitShare};
+use ente_legacy::{LegacyKitRecoveryClient, LegacyKitShare};
use js_sys::Reflect;
use serde::Deserialize;
use serde_wasm_bindgen as swb;
@@ -24,9 +24,9 @@ impl From<LegacyError> for JsValue {
}
}
-impl From<ente_contacts::Error> for LegacyError {
- fn from(error: ente_contacts::Error) -> Self {
- use ente_contacts::ErrorKind as K;
+impl From<ente_legacy::Error> for LegacyError {
+ fn from(error: ente_legacy::Error) -> Self {
+ use ente_legacy::ErrorKind as K;
let kind = match error.kind() {
K::Network => "network",
K::Http => "http",
@@ -34,9 +34,6 @@ impl From<ente_contacts::Error> for LegacyError {
K::Crypto => "crypto",
K::Auth => "auth",
K::InvalidInput => "invalid_input",
- K::MissingEncryptedData => "missing_encrypted_data",
- K::MissingEncryptedKey => "missing_encrypted_key",
- K::ProfilePictureNotFound => "profile_picture_not_found",
K::ActiveRecoverySession => "active_recovery_session",
};
Self {
@@ -85,7 +82,7 @@ pub async fn legacy_kit_open_recovery(
#[wasm_bindgen]
pub struct LegacyKitRecoveryHandle {
- inner: ente_contacts::LegacyKitRecoveryHandle,
+ inner: ente_legacy::LegacyKitRecoveryHandle,
}
#[wasm_bindgen]
diff --git a/rust/crates/contacts/Cargo.toml b/rust/crates/contacts/Cargo.toml
index f0af16a915..e95638ed77 100644
--- a/rust/crates/contacts/Cargo.toml
+++ b/rust/crates/contacts/Cargo.toml
@@ -6,20 +6,20 @@ edition = "2024"
museum = []
[dependencies]
-ente-accounts.workspace = true
ente-core.workspace = true
md-5.workspace = true
serde.workspace = true
serde_json.workspace = true
-sha2.workspace = true
thiserror.workspace = true
-uuid = { version = "1", features = ["v4", "js"] }
[dev-dependencies]
+ente-accounts.workspace = true
+ente-legacy.workspace = true
ente-test-support.workspace = true
hmac = "0.13"
mockito.workspace = true
reqwest = { workspace = true, features = ["json"] }
sha1 = "0.11"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
+uuid = { version = "1", features = ["v4", "js"] }
zeroize.workspace = true
diff --git a/rust/crates/contacts/src/client.rs b/rust/crates/contacts/src/client.rs
index d3fdec0bd4..6f228a66fd 100644
--- a/rust/crates/contacts/src/client.rs
+++ b/rust/crates/contacts/src/client.rs
@@ -1,34 +1,10 @@
use std::sync::{Arc, RwLock};
-use ente_accounts::auth::{self, KeyAttributes, SrpSession};
-use ente_core::b64;
-use ente_core::crypto::{self, SecretVec, sealed, secretbox};
-use ente_core::http::{self, Api, ApiConfig, Auth, Http};
-use sha2::{Digest, Sha256};
-use uuid::Uuid;
+use ente_core::crypto::{self, SecretVec};
+use ente_core::http::Api;
use crate::crypto as contacts_crypto;
use crate::error::{Error, Result};
-use crate::legacy_kit::{
- create_legacy_kit_request, decode_download_content, decode_legacy_kit_record,
- validate_notice_period,
-};
-use crate::legacy_kit_models::{
- LegacyKit, LegacyKitCreateResult, LegacyKitOwnerRecoverySession, LegacyKitShare,
-};
-use crate::legacy_kit_transport::{
- LegacyKitDownloadContentResponse, LegacyKitOwnerActionRequest,
- LegacyKitOwnerRecoverySessionResponse, LegacyKitRecordResponse,
- LegacyKitUpdateRecoveryNoticeRequest, ListLegacyKitsResponse,
-};
-use crate::legacy_models::{LegacyContactState, LegacyInfo, LegacyRecoveryBundle};
-use crate::legacy_transport::{
- LegacyAddContactRequest, LegacyChangePasswordRequest, LegacyChangePasswordResponse,
- LegacyContactIdentifier, LegacyInfoResponse, LegacyInitChangePasswordRequest,
- LegacyPublicKeyResponse, LegacyRecoveryIdentifier, LegacyRecoveryInfoResponse,
- LegacySetupSrpRequest, LegacySetupSrpResponse, LegacyUpdateContactRequest,
- LegacyUpdateRecoveryNoticeRequest, LegacyUpdateSrpAndKeysRequest, LegacyUpdatedKeyAttr,
-};
use crate::models::{AttachmentType, ContactData, ContactRecord, WrappedRootContactKey};
use crate::transport::{
AttachmentUploadUrlRequest, AttachmentUploadUrlResponse, CommitAttachmentRequest,
@@ -44,27 +20,21 @@ pub enum RootKeySource {
Unresolved,
}
-pub struct OpenContactsCtxInput {
- pub base_url: String,
- pub auth_token: String,
+pub struct OpenContactsInput {
pub user_id: i64,
- pub master_key: Vec<u8>,
pub cached_wrapped_root_contact_key: Option<WrappedRootContactKey>,
- pub user_agent: Option<String>,
- pub client_package: Option<String>,
- pub client_version: Option<String>,
}
-pub struct OpenContactsCtxResult {
- pub ctx: ContactsCtx,
+pub struct OpenContactsResult {
+ pub client: ContactsClient,
pub wrapped_root_contact_key: Option<WrappedRootContactKey>,
pub root_key_source: RootKeySource,
}
-pub struct ContactsCtx {
+pub struct ContactsClient {
user_id: i64,
- api: Api,
- master_key: Arc<RwLock<SecretVec>>,
+ api: Arc<Api>,
+ master_key: Arc<SecretVec>,
root_contact_key: Arc<RwLock<Option<SecretVec>>>,
wrapped_root_contact_key: Arc<RwLock<Option<WrappedRootContactKey>>>,
}
@@ -78,24 +48,17 @@ fn wrapped_root_contact_key_from_response(
}
}
-impl ContactsCtx {
- pub async fn open(input: OpenContactsCtxInput) -> Result<OpenContactsCtxResult> {
- let api = Api::new(
- Http::new()?,
- ApiConfig {
- origin: input.base_url,
- client_package: input.client_package,
- client_version: input.client_version,
- user_agent: input.user_agent,
- auth: Some(Auth::User(input.auth_token)),
- },
- );
-
+impl ContactsClient {
+ pub fn open(
+ api: Arc<Api>,
+ master_key: Arc<SecretVec>,
+ input: OpenContactsInput,
+ ) -> Result<OpenContactsResult> {
let (root_contact_key, wrapped_root_contact_key, root_key_source) =
if let Some(cached_wrapped_root_contact_key) = input.cached_wrapped_root_contact_key {
let root_contact_key = contacts_crypto::decrypt_root_contact_key(
&cached_wrapped_root_contact_key,
- &input.master_key,
+ master_key.as_ref(),
)?;
(
Some(SecretVec::new(root_contact_key)),
@@ -105,16 +68,16 @@ impl ContactsCtx {
} else {
(None, None, RootKeySource::Unresolved)
};
- let ctx = Self {
+ let client = Self {
user_id: input.user_id,
api,
- master_key: Arc::new(RwLock::new(SecretVec::new(input.master_key))),
+ master_key,
root_contact_key: Arc::new(RwLock::new(root_contact_key)),
wrapped_root_contact_key: Arc::new(RwLock::new(wrapped_root_contact_key.clone())),
};
- Ok(OpenContactsCtxResult {
- ctx,
+ Ok(OpenContactsResult {
+ client,
wrapped_root_contact_key,
root_key_source,
})
@@ -124,10 +87,6 @@ impl ContactsCtx {
self.user_id
}
- pub fn update_auth_token(&self, auth_token: String) {
- self.api.set_auth(Some(Auth::User(auth_token)));
- }
-
pub fn current_wrapped_root_contact_key(&self) -> Option<WrappedRootContactKey> {
self.wrapped_root_contact_key
.read()
@@ -139,9 +98,10 @@ impl ContactsCtx {
&self,
wrapped_root_contact_key: WrappedRootContactKey,
) -> Result<()> {
- let master_key = self.master_key.read().expect("master key lock poisoned");
- let decrypted_root_key =
- contacts_crypto::decrypt_root_contact_key(&wrapped_root_contact_key, &master_key)?;
+ let decrypted_root_key = contacts_crypto::decrypt_root_contact_key(
+ &wrapped_root_contact_key,
+ self.master_key.as_ref(),
+ )?;
*self
.root_contact_key
.write()
@@ -459,371 +419,6 @@ impl ContactsCtx {
.await
}
- pub async fn legacy_info(&self) -> Result<LegacyInfo> {
- Ok(self
- .api
- .get("/emergency-contacts/info")
- .send()
- .await?
- .error_for_status()?
- .json::<LegacyInfoResponse>()
- .await?)
- }
-
- pub async fn legacy_public_key(&self, email: &str) -> Result<Option<String>> {
- let response = self
- .api
- .get("/users/public-key")
- .query(&[("email", email.trim())])
- .send()
- .await?;
- if response.status() == 404 {
- return Ok(None);
- }
- let response = response
- .error_for_status()?
- .json::<LegacyPublicKeyResponse>()
- .await?;
- Ok(Some(response.public_key))
- }
-
- pub fn legacy_verification_id(&self, public_key_b64: &str) -> Result<String> {
- let public_key = b64::decode(public_key_b64)?;
- let digest = Sha256::digest(&public_key);
- auth::recovery_key_to_mnemonic(&b64::encode(digest.as_slice())).map_err(Into::into)
- }
-
- pub async fn legacy_add_contact(
- &self,
- email: &str,
- current_user_key_attrs: &KeyAttributes,
- recovery_notice_in_days: Option<i32>,
- ) -> Result<()> {
- let public_key = self
- .legacy_public_key(email)
- .await?
- .ok_or_else(|| Error::InvalidInput("legacy contact is not on Ente".into()))?;
- let recovery_key = self.current_recovery_key(current_user_key_attrs)?;
- let recipient_public_key = b64::decode(&public_key)?;
- let encrypted_key = sealed::seal(
- &recovery_key,
- &crypto::PublicKey::try_from_slice(&recipient_public_key)?,
- )?;
-
- self.api
- .post("/emergency-contacts/add")
- .json(&LegacyAddContactRequest {
- email: email.trim().to_string(),
- encrypted_key: b64::encode(&encrypted_key),
- recovery_notice_in_days,
- })
- .send()
- .await?
- .error_for_status()?;
- Ok(())
- }
-
- pub async fn legacy_update_contact(
- &self,
- user_id: i64,
- emergency_contact_id: i64,
- state: LegacyContactState,
- ) -> Result<()> {
- self.api
- .post("/emergency-contacts/update")
- .json(&LegacyUpdateContactRequest {
- user_id,
- emergency_contact_id,
- state,
- })
- .send()
- .await?
- .error_for_status()?;
- Ok(())
- }
-
- pub async fn legacy_update_recovery_notice(
- &self,
- emergency_contact_id: i64,
- recovery_notice_in_days: i32,
- ) -> Result<()> {
- self.api
- .post("/emergency-contacts/update-recovery-notice")
- .json(&LegacyUpdateRecoveryNoticeRequest {
- emergency_contact_id,
- recovery_notice_in_days,
- })
- .send()
- .await?
- .error_for_status()?;
- Ok(())
- }
-
- pub async fn legacy_start_recovery(
- &self,
- user_id: i64,
- emergency_contact_id: i64,
- ) -> Result<()> {
- self.legacy_contact_action(
- "/emergency-contacts/start-recovery",
- user_id,
- emergency_contact_id,
- )
- .await
- }
-
- pub async fn legacy_stop_recovery(
- &self,
- recovery_id: &str,
- user_id: i64,
- emergency_contact_id: i64,
- ) -> Result<()> {
- self.legacy_recovery_action(
- "/emergency-contacts/stop-recovery",
- recovery_id,
- user_id,
- emergency_contact_id,
- )
- .await
- }
-
- pub async fn legacy_reject_recovery(
- &self,
- recovery_id: &str,
- user_id: i64,
- emergency_contact_id: i64,
- ) -> Result<()> {
- self.legacy_recovery_action(
- "/emergency-contacts/reject-recovery",
- recovery_id,
- user_id,
- emergency_contact_id,
- )
- .await
- }
-
- pub async fn legacy_approve_recovery(
- &self,
- recovery_id: &str,
- user_id: i64,
- emergency_contact_id: i64,
- ) -> Result<()> {
- self.legacy_recovery_action(
- "/emergency-contacts/approve-recovery",
- recovery_id,
- user_id,
- emergency_contact_id,
- )
- .await
- }
-
- pub async fn legacy_recovery_bundle(
- &self,
- recovery_id: &str,
- current_user_key_attrs: &KeyAttributes,
- ) -> Result<LegacyRecoveryBundle> {
- let response = self.legacy_recovery_info(recovery_id).await?;
- let recovery_key =
- self.decrypt_legacy_recovery_key(&response.encrypted_key, current_user_key_attrs)?;
-
- Ok(LegacyRecoveryBundle {
- recovery_key,
- user_key_attributes: response.user_key_attr,
- })
- }
-
- pub async fn legacy_change_password(
- &self,
- recovery_id: &str,
- current_user_key_attrs: &KeyAttributes,
- new_password: &str,
- ) -> Result<()> {
- let bundle = self
- .legacy_recovery_bundle(recovery_id, current_user_key_attrs)
- .await?;
- let target_master_key = decrypt_master_key_with_recovery_key(
- &bundle.user_key_attributes,
- &bundle.recovery_key,
- )?;
- let (updated_key_attrs, login_key) = auth::generate_key_attributes_for_new_password(
- &target_master_key,
- &bundle.user_key_attributes,
- new_password,
- )?;
- let srp_user_id = Uuid::new_v4().to_string();
- let (mut srp_session, setup_request) =
- password_reset_setup_request(&srp_user_id, &login_key)?;
- let init_response = self
- .api
- .post("/emergency-contacts/init-change-password")
- .json(&LegacyInitChangePasswordRequest {
- recovery_id: recovery_id.to_string(),
- setup_srp_request: setup_request,
- })
- .send()
- .await?
- .error_for_status()?
- .json::<LegacySetupSrpResponse>()
- .await?;
- let srp_m1 = srp_session_m1(&mut srp_session, &init_response)?;
- let updated_key_attr = LegacyUpdatedKeyAttr {
- kek_salt: updated_key_attrs.kek_salt.clone(),
- encrypted_key: updated_key_attrs.encrypted_key.clone(),
- key_decryption_nonce: updated_key_attrs.key_decryption_nonce.clone(),
- mem_limit: updated_key_attrs.mem_limit,
- ops_limit: updated_key_attrs.ops_limit,
- };
-
- let change_response = self
- .api
- .post("/emergency-contacts/change-password")
- .json(&LegacyChangePasswordRequest {
- recovery_id: recovery_id.to_string(),
- update_srp_and_keys_request: LegacyUpdateSrpAndKeysRequest {
- setup_id: init_response.setup_id,
- srp_m1,
- updated_key_attr,
- },
- })
- .send()
- .await?
- .error_for_status()?
- .json::<LegacyChangePasswordResponse>()
- .await?;
-
- let server_m2 = b64::decode(&change_response.srp_m2)?;
- srp_session.verify_m2(&server_m2)?;
- Ok(())
- }
-
- pub async fn legacy_kits(&self) -> Result<Vec<LegacyKit>> {
- let response = self
- .api
- .get("/legacy-kits")
- .send()
- .await?
- .error_for_status()?
- .json::<ListLegacyKitsResponse>()
- .await?;
- let master_key = self.master_key.read().expect("master key lock poisoned");
- response
- .kits
- .into_iter()
- .map(|kit| decode_legacy_kit_record(kit, &master_key))
- .collect()
- }
-
- pub async fn legacy_kit_create(
- &self,
- current_user_key_attrs: &KeyAttributes,
- part_names: [String; 3],
- notice_period_in_hours: i32,
- ) -> Result<LegacyKitCreateResult> {
- let (request, shares) = {
- let recovery_key = self.current_recovery_key(current_user_key_attrs)?;
- let master_key = self.master_key.read().expect("master key lock poisoned");
- create_legacy_kit_request(
- &recovery_key,
- &master_key,
- part_names,
- notice_period_in_hours,
- )?
- };
-
- let response = self
- .api
- .post("/legacy-kits")
- .json(&request)
- .send()
- .await?
- .error_for_status()?
- .json::<LegacyKitRecordResponse>()
- .await?;
- let master_key = self.master_key.read().expect("master key lock poisoned");
- let kit = decode_legacy_kit_record(response, &master_key)?;
- Ok(LegacyKitCreateResult { kit, shares })
- }
-
- pub async fn legacy_kit_download_shares(&self, kit_id: &str) -> Result<Vec<LegacyKitShare>> {
- let response = self
- .api
- .get(&format!("/legacy-kits/{kit_id}/download-content"))
- .send()
- .await?
- .error_for_status()?
- .json::<LegacyKitDownloadContentResponse>()
- .await?;
- let master_key = self.master_key.read().expect("master key lock poisoned");
- decode_download_content(response, &master_key)
- }
-
- pub async fn legacy_kit_recovery_session(
- &self,
- kit_id: &str,
- ) -> Result<LegacyKitOwnerRecoverySession> {
- let response = self
- .api
- .get(&format!("/legacy-kits/{kit_id}/recovery-session"))
- .send()
- .await?
- .error_for_status()?
- .json::<LegacyKitOwnerRecoverySessionResponse>()
- .await?;
- Ok(response.into())
- }
-
- pub async fn legacy_kit_update_recovery_notice(
- &self,
- kit_id: &str,
- notice_period_in_hours: i32,
- ) -> Result<()> {
- validate_notice_period(notice_period_in_hours)?;
- let path = "/legacy-kits/update-recovery-notice";
- let response = self
- .api
- .post(path)
- .json(&LegacyKitUpdateRecoveryNoticeRequest {
- kit_id: kit_id.to_string(),
- notice_period_in_hours,
- })
- .send()
- .await?;
- if response.status() == 400 {
- return if response.text().await?.contains("active recovery session") {
- Err(Error::ActiveRecoverySession)
- } else {
- Err(http::Error::Http {
- status: 400,
- path: path.into(),
- }
- .into())
- };
- }
- response.error_for_status()?;
- Ok(())
- }
-
- pub async fn legacy_kit_block_recovery(&self, kit_id: &str) -> Result<()> {
- self.api
- .post("/legacy-kits/block-recovery")
- .json(&LegacyKitOwnerActionRequest {
- kit_id: kit_id.to_string(),
- })
- .send()
- .await?
- .error_for_status()?;
- Ok(())
- }
-
- pub async fn legacy_kit_delete(&self, kit_id: &str) -> Result<()> {
- self.api
- .delete(&format!("/legacy-kits/{kit_id}"))
- .send()
- .await?
- .error_for_status()?;
- Ok(())
- }
-
fn decode_contact(&self, entity: ContactEntityResponse) -> Result<ContactRecord> {
if entity.is_deleted {
return Ok(ContactRecord {
@@ -885,8 +480,10 @@ impl ContactsCtx {
} else {
let generated_root_contact_key = SecretVec::new(crypto::random_bytes(32));
let generated_wrapped_root_contact_key = {
- let master_key = self.master_key.read().expect("master key lock poisoned");
- contacts_crypto::encrypt_root_contact_key(&generated_root_contact_key, &master_key)?
+ contacts_crypto::encrypt_root_contact_key(
+ &generated_root_contact_key,
+ self.master_key.as_ref(),
+ )?
};
if let Some(remote_root_key) =
create_root_key(&self.api, &generated_wrapped_root_contact_key).await?
@@ -901,89 +498,6 @@ impl ContactsCtx {
Ok(())
}
-
- async fn legacy_contact_action(
- &self,
- path: &str,
- user_id: i64,
- emergency_contact_id: i64,
- ) -> Result<()> {
- self.api
- .post(path)
- .json(&LegacyContactIdentifier {
- user_id,
- emergency_contact_id,
- })
- .send()
- .await?
- .error_for_status()?;
- Ok(())
- }
-
- async fn legacy_recovery_action(
- &self,
- path: &str,
- recovery_id: &str,
- user_id: i64,
- emergency_contact_id: i64,
- ) -> Result<()> {
- self.api
- .post(path)
- .json(&LegacyRecoveryIdentifier {
- id: recovery_id.to_string(),
- user_id,
- emergency_contact_id,
- })
- .send()
- .await?
- .error_for_status()?;
- Ok(())
- }
-
- async fn legacy_recovery_info(&self, recovery_id: &str) -> Result<LegacyRecoveryInfoResponse> {
- Ok(self
- .api
- .get(&format!("/emergency-contacts/recovery-info/{recovery_id}"))
- .send()
- .await?
- .error_for_status()?
- .json::<LegacyRecoveryInfoResponse>()
- .await?)
- }
-
- fn current_recovery_key(&self, current_user_key_attrs: &KeyAttributes) -> Result<SecretVec> {
- let master_key = self.master_key.read().expect("master key lock poisoned");
- let recovery_key_hex = auth::get_recovery_key(&master_key, current_user_key_attrs)?;
- Ok(auth::recovery_key_from_mnemonic_or_hex(&recovery_key_hex)?)
- }
-
- fn decrypt_legacy_recovery_key(
- &self,
- encrypted_key_b64: &str,
- current_user_key_attrs: &KeyAttributes,
- ) -> Result<SecretVec> {
- let public_key = b64::decode(&current_user_key_attrs.public_key)?;
- let encrypted_key = b64::decode(encrypted_key_b64)?;
- let secret_key = self.current_secret_key(current_user_key_attrs)?;
- let decrypted = sealed::open(
- &encrypted_key,
- &crypto::PublicKey::try_from_slice(&public_key)?,
- &crypto::SecretKey::try_from_slice(&secret_key)?,
- )?;
- Ok(SecretVec::new(decrypted))
- }
-
- fn current_secret_key(&self, current_user_key_attrs: &KeyAttributes) -> Result<SecretVec> {
- let encrypted_secret_key = b64::decode(&current_user_key_attrs.encrypted_secret_key)?;
- let secret_key_nonce = b64::decode(&current_user_key_attrs.secret_key_decryption_nonce)?;
- let master_key = self.master_key.read().expect("master key lock poisoned");
- let secret_key = secretbox::decrypt(
- &encrypted_secret_key,
- &crypto::Nonce::try_from_slice(&secret_key_nonce)?,
- &crypto::Key::try_from_slice(&master_key)?,
- )?;
- Ok(SecretVec::new(secret_key))
- }
}
async fn fetch_root_key(api: &Api) -> Result<Option<RootKeyResponse>> {
@@ -1017,64 +531,3 @@ async fn create_root_key(
response.error_for_status()?;
Ok(None)
}
-
-fn decrypt_master_key_with_recovery_key(
- key_attributes: &KeyAttributes,
- recovery_key: &[u8],
-) -> Result<SecretVec> {
- let encrypted_master_key = key_attributes
- .master_key_encrypted_with_recovery_key
- .as_ref()
- .ok_or_else(|| {
- Error::InvalidInput(
- "target key attributes missing masterKeyEncryptedWithRecoveryKey".into(),
- )
- })?;
- let master_key_nonce = key_attributes
- .master_key_decryption_nonce
- .as_ref()
- .ok_or_else(|| {
- Error::InvalidInput("target key attributes missing masterKeyDecryptionNonce".into())
- })?;
- let encrypted_master_key = b64::decode(encrypted_master_key)?;
- let master_key_nonce = b64::decode(master_key_nonce)?;
- secretbox::decrypt(
- &encrypted_master_key,
- &crypto::Nonce::try_from_slice(&master_key_nonce)?,
- &crypto::Key::try_from_slice(recovery_key)?,
- )
- .map(SecretVec::new)
- .map_err(Into::into)
-}
-
-fn password_reset_setup_request(
- srp_user_id: &str,
- login_key: &[u8],
-) -> Result<(SrpSession, LegacySetupSrpRequest)> {
- let generated_srp = auth::generate_srp_setup_with_login_key(login_key, srp_user_id)?;
- let srp_session = SrpSession::new(
- srp_user_id,
- &generated_srp.srp_salt,
- &generated_srp.login_sub_key,
- )?;
- let srp_a = b64::encode(&srp_session.public_a());
-
- Ok((
- srp_session,
- LegacySetupSrpRequest {
- srp_user_id: srp_user_id.to_string(),
- srp_salt: b64::encode(&generated_srp.srp_salt),
- srp_verifier: b64::encode(&generated_srp.srp_verifier),
- srp_a,
- },
- ))
-}
-
-fn srp_session_m1(
- srp_session: &mut SrpSession,
- init_response: &LegacySetupSrpResponse,
-) -> Result<String> {
- let server_b = b64::decode(&init_response.srp_b)?;
- let client_m1 = srp_session.compute_m1(&server_b)?;
- Ok(b64::encode(&client_m1))
-}
diff --git a/rust/crates/contacts/src/error.rs b/rust/crates/contacts/src/error.rs
index af31b20240..e7bd93d619 100644
--- a/rust/crates/contacts/src/error.rs
+++ b/rust/crates/contacts/src/error.rs
@@ -12,9 +12,6 @@ pub enum Error {
#[error("base64 decode error: {0}")]
Base64Decode(#[from] b64::DecodeError),
- #[error(transparent)]
- Accounts(#[from] ente_accounts::Error),
-
#[error("invalid input: {0}")]
InvalidInput(String),
@@ -26,9 +23,6 @@ pub enum Error {
#[error("profile picture not found")]
ProfilePictureNotFound,
-
- #[error("a recovery is already in progress")]
- ActiveRecoverySession,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -37,12 +31,10 @@ pub enum ErrorKind {
Http,
Parse,
Crypto,
- Auth,
InvalidInput,
MissingEncryptedData,
MissingEncryptedKey,
ProfilePictureNotFound,
- ActiveRecoverySession,
}
impl Error {
@@ -53,12 +45,10 @@ impl Error {
Error::Http(_) => ErrorKind::Http,
Error::Crypto(_) => ErrorKind::Crypto,
Error::Base64Decode(_) => ErrorKind::Crypto,
- Error::Accounts(_) => ErrorKind::Auth,
Error::InvalidInput(_) => ErrorKind::InvalidInput,
Error::MissingEncryptedData => ErrorKind::MissingEncryptedData,
Error::MissingEncryptedKey => ErrorKind::MissingEncryptedKey,
Error::ProfilePictureNotFound => ErrorKind::ProfilePictureNotFound,
- Error::ActiveRecoverySession => ErrorKind::ActiveRecoverySession,
}
}
}
diff --git a/rust/crates/contacts/src/lib.rs b/rust/crates/contacts/src/lib.rs
index d1defe8467..11c3d06f2d 100644
--- a/rust/crates/contacts/src/lib.rs
+++ b/rust/crates/contacts/src/lib.rs
@@ -1,25 +1,9 @@
pub mod client;
pub mod crypto;
pub mod error;
-pub mod legacy_kit;
-pub mod legacy_kit_models;
-pub mod legacy_kit_transport;
-pub mod legacy_models;
-pub mod legacy_transport;
pub mod models;
pub mod transport;
-pub use client::{ContactsCtx, OpenContactsCtxInput, OpenContactsCtxResult, RootKeySource};
+pub use client::{ContactsClient, OpenContactsInput, OpenContactsResult, RootKeySource};
pub use error::{Error, ErrorKind, Result};
-pub use legacy_kit::{LegacyKitRecoveryClient, LegacyKitRecoveryHandle};
-pub use legacy_kit_models::{
- LEGACY_KIT_PAYLOAD_VERSION, LegacyKit, LegacyKitCreateResult, LegacyKitMetadata,
- LegacyKitOwnerRecoverySession, LegacyKitPart, LegacyKitRecoveryBundle,
- LegacyKitRecoveryInitiator, LegacyKitRecoverySession, LegacyKitRecoveryStatus, LegacyKitShare,
- LegacyKitVariant,
-};
-pub use legacy_models::{
- LegacyContactRecord, LegacyContactState, LegacyInfo, LegacyRecoveryBundle,
- LegacyRecoverySession, LegacyRecoveryStatus, LegacyUser,
-};
pub use models::{AttachmentType, ContactData, ContactRecord, WrappedRootContactKey};
diff --git a/rust/crates/contacts/tests/contacts.rs b/rust/crates/contacts/tests/contacts.rs
index e0dbfdb81a..c2330ac210 100644
--- a/rust/crates/contacts/tests/contacts.rs
+++ b/rust/crates/contacts/tests/contacts.rs
@@ -3,11 +3,10 @@
mod support;
use ente_contacts::models::ContactData;
-use ente_contacts::{
- LegacyKitRecoveryClient, LegacyKitRecoveryStatus,
- legacy_models::{LegacyContactState, LegacyRecoveryStatus},
-};
use ente_core::http;
+use ente_legacy::{
+ LegacyContactState, LegacyKitRecoveryClient, LegacyKitRecoveryStatus, LegacyRecoveryStatus,
+};
use ente_test_support::{Museum, TestResult};
use serde::{Deserialize, Serialize};
use serde_json::json;
@@ -60,10 +59,10 @@ fn contacts() -> TestResult {
async fn run(endpoint: String) -> TestResult {
let endpoint = &endpoint;
let pair_state = legacy::create_accepted_pair_state(endpoint, 14).await;
- let pair = legacy::open_pair(endpoint, &pair_state).await;
- run_contacts_stage(&pair).await;
+ let pair = legacy::open_pair(endpoint, &pair_state);
+ run_contacts_stage(endpoint, &pair).await;
- let mut pair = legacy::open_pair(endpoint, &pair_state).await;
+ let mut pair = legacy::open_pair(endpoint, &pair_state);
ensure_totp_enabled(endpoint, &pair.owner).await;
run_legacy_reject_stage(&pair).await;
run_legacy_stop_stage(&pair).await;
@@ -92,22 +91,23 @@ async fn ensure_totp_enabled(endpoint: &str, owner: &auth::TestAccount) {
);
}
-async fn run_contacts_stage(pair: &legacy::LegacyPair) {
+async fn run_contacts_stage(endpoint: &str, pair: &legacy::LegacyPair) {
+ let owner_ctx = contacts::open_client(endpoint, &pair.owner);
+ let trusted_ctx = contacts::open_client(endpoint, &pair.trusted);
let initial_data = ContactData {
contact_user_id: pair.trusted.user_id,
name: "Trusted Contact".to_string(),
};
- let contact = pair.owner_ctx.create_contact(&initial_data).await.unwrap();
+ let contact = owner_ctx.create_contact(&initial_data).await.unwrap();
assert_eq!(contact.contact_user_id, pair.trusted.user_id);
assert_eq!(contact.email.as_deref(), Some(pair.trusted.email.as_str()));
- let fetched = pair.owner_ctx.get_contact(&contact.id).await.unwrap();
+ let fetched = owner_ctx.get_contact(&contact.id).await.unwrap();
assert_eq!(fetched.id, contact.id);
assert_eq!(fetched.name.as_deref(), Some("Trusted Contact"));
- let updated = pair
- .owner_ctx
+ let updated = owner_ctx
.update_contact(
&contact.id,
&ContactData {
@@ -119,83 +119,83 @@ async fn run_contacts_stage(pair: &legacy::LegacyPair) {
.unwrap();
assert_eq!(updated.name.as_deref(), Some("Trusted Contact Updated"));
- let diff = pair.owner_ctx.get_diff(0, 5000).await.unwrap();
+ let diff = owner_ctx.get_diff(0, 5000).await.unwrap();
assert!(diff.iter().any(|entry| entry.id == contact.id));
- match pair.trusted_ctx.get_contact(&contact.id).await {
+ match trusted_ctx.get_contact(&contact.id).await {
Err(ente_contacts::Error::Http(http::Error::Http { status: 404, .. })) => {}
other => panic!("expected trusted account to get 404 for owner contact, got {other:?}"),
}
- pair.owner_ctx.delete_contact(&contact.id).await.unwrap();
+ owner_ctx.delete_contact(&contact.id).await.unwrap();
}
async fn run_legacy_reject_stage(pair: &legacy::LegacyPair) {
pair.trusted_ctx
- .legacy_start_recovery(pair.owner.user_id, pair.trusted.user_id)
+ .start_recovery(pair.owner.user_id, pair.trusted.user_id)
.await
.unwrap();
- let owner_info = pair.owner_ctx.legacy_info().await.unwrap();
+ let owner_info = pair.owner_ctx.info().await.unwrap();
let recovery =
- contacts::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.expect("owner recovery session missing");
assert_eq!(recovery.status, LegacyRecoveryStatus::Waiting);
pair.owner_ctx
- .legacy_reject_recovery(&recovery.id, pair.owner.user_id, pair.trusted.user_id)
+ .reject_recovery(&recovery.id, pair.owner.user_id, pair.trusted.user_id)
.await
.unwrap();
- let owner_info = pair.owner_ctx.legacy_info().await.unwrap();
- let trusted_info = pair.trusted_ctx.legacy_info().await.unwrap();
+ let owner_info = pair.owner_ctx.info().await.unwrap();
+ let trusted_info = pair.trusted_ctx.info().await.unwrap();
assert!(
- contacts::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.is_none()
);
assert!(
- contacts::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
.is_none()
);
let owner_contact =
- contacts::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.expect("legacy contact should stay accepted after rejection");
assert_eq!(owner_contact.state, LegacyContactState::Accepted);
}
async fn run_legacy_stop_stage(pair: &legacy::LegacyPair) {
pair.trusted_ctx
- .legacy_start_recovery(pair.owner.user_id, pair.trusted.user_id)
+ .start_recovery(pair.owner.user_id, pair.trusted.user_id)
.await
.unwrap();
- let trusted_info = pair.trusted_ctx.legacy_info().await.unwrap();
+ let trusted_info = pair.trusted_ctx.info().await.unwrap();
let recovery =
- contacts::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
.expect("trusted recovery session missing");
assert_eq!(recovery.status, LegacyRecoveryStatus::Waiting);
pair.trusted_ctx
- .legacy_stop_recovery(&recovery.id, pair.owner.user_id, pair.trusted.user_id)
+ .stop_recovery(&recovery.id, pair.owner.user_id, pair.trusted.user_id)
.await
.unwrap();
- let owner_info = pair.owner_ctx.legacy_info().await.unwrap();
- let trusted_info = pair.trusted_ctx.legacy_info().await.unwrap();
+ let owner_info = pair.owner_ctx.info().await.unwrap();
+ let trusted_info = pair.trusted_ctx.info().await.unwrap();
assert!(
- contacts::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.is_none()
);
assert!(
- contacts::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
.is_none()
);
}
async fn run_legacy_reinvite_stage(pair: &legacy::LegacyPair) {
pair.owner_ctx
- .legacy_update_contact(
+ .update_contact(
pair.owner.user_id,
pair.trusted.user_id,
LegacyContactState::Revoked,
@@ -203,22 +203,19 @@ async fn run_legacy_reinvite_stage(pair: &legacy::LegacyPair) {
.await
.unwrap();
- let owner_info = pair.owner_ctx.legacy_info().await.unwrap();
- let trusted_info = pair.trusted_ctx.legacy_info().await.unwrap();
+ let owner_info = pair.owner_ctx.info().await.unwrap();
+ let trusted_info = pair.trusted_ctx.info().await.unwrap();
+ assert!(legacy::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id).is_none());
assert!(
- contacts::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id).is_none()
- );
- assert!(
- contacts::trusted_contact(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
- .is_none()
+ legacy::trusted_contact(&trusted_info, pair.owner.user_id, pair.trusted.user_id).is_none()
);
pair.owner_ctx
- .legacy_add_contact(&pair.trusted.email, &pair.owner.key_attributes, Some(14))
+ .add_contact(&pair.trusted.email, &pair.owner.key_attributes, Some(14))
.await
.unwrap();
pair.trusted_ctx
- .legacy_update_contact(
+ .update_contact(
pair.owner.user_id,
pair.trusted.user_id,
LegacyContactState::Accepted,
@@ -226,13 +223,13 @@ async fn run_legacy_reinvite_stage(pair: &legacy::LegacyPair) {
.await
.unwrap();
- let owner_info = pair.owner_ctx.legacy_info().await.unwrap();
- let trusted_info = pair.trusted_ctx.legacy_info().await.unwrap();
+ let owner_info = pair.owner_ctx.info().await.unwrap();
+ let trusted_info = pair.trusted_ctx.info().await.unwrap();
let owner_contact =
- contacts::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.expect("reinvited contact missing from owner view");
let trusted_contact =
- contacts::trusted_contact(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::trusted_contact(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
.expect("reinvited contact missing from trusted view");
assert_eq!(owner_contact.state, LegacyContactState::Accepted);
assert_eq!(trusted_contact.state, LegacyContactState::Accepted);
@@ -246,31 +243,31 @@ async fn run_legacy_reset_stage(endpoint: &str, pair: &mut legacy::LegacyPair) {
);
pair.trusted_ctx
- .legacy_start_recovery(pair.owner.user_id, pair.trusted.user_id)
+ .start_recovery(pair.owner.user_id, pair.trusted.user_id)
.await
.unwrap();
- let owner_info = pair.owner_ctx.legacy_info().await.unwrap();
+ let owner_info = pair.owner_ctx.info().await.unwrap();
let recovery =
- contacts::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.expect("owner recovery session missing");
assert_eq!(recovery.status, LegacyRecoveryStatus::Waiting);
pair.owner_ctx
- .legacy_approve_recovery(&recovery.id, pair.owner.user_id, pair.trusted.user_id)
+ .approve_recovery(&recovery.id, pair.owner.user_id, pair.trusted.user_id)
.await
.unwrap();
- let owner_info = pair.owner_ctx.legacy_info().await.unwrap();
+ let owner_info = pair.owner_ctx.info().await.unwrap();
let recovery =
- contacts::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.expect("approved recovery session missing");
assert_eq!(recovery.status, LegacyRecoveryStatus::Ready);
let previous_password = pair.owner.password.clone();
let new_password = support::unique_password("LegacyRecovered");
pair.trusted_ctx
- .legacy_change_password(&recovery.id, &pair.trusted.key_attributes, &new_password)
+ .change_password(&recovery.id, &pair.trusted.key_attributes, &new_password)
.await
.unwrap();
@@ -296,20 +293,20 @@ async fn run_legacy_reset_stage(endpoint: &str, pair: &mut legacy::LegacyPair) {
.expect("two-factor status after recovery fetch failed")
);
- let recovered_owner_ctx = contacts::open_ctx(endpoint, &recovered_owner).await;
- let owner_info = recovered_owner_ctx.legacy_info().await.unwrap();
- let trusted_info = pair.trusted_ctx.legacy_info().await.unwrap();
+ let recovered_owner_ctx = legacy::open_client(endpoint, &recovered_owner);
+ let owner_info = recovered_owner_ctx.info().await.unwrap();
+ let trusted_info = pair.trusted_ctx.info().await.unwrap();
assert!(
- contacts::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_recovery_session(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.is_none()
);
assert!(
- contacts::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::trusted_recovery_session(&trusted_info, pair.owner.user_id, pair.trusted.user_id)
.is_none()
);
let owner_contact =
- contacts::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id)
+ legacy::owner_contact(&owner_info, pair.owner.user_id, pair.trusted.user_id)
.expect("legacy contact should remain configured after recovery");
assert_eq!(owner_contact.state, LegacyContactState::Accepted);
@@ -358,7 +355,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
let waiting_kit = owner
.owner_ctx
- .legacy_kit_create(
+ .create_kit(
&owner.owner.key_attributes,
["North".into(), "East".into(), "West".into()],
24,
@@ -371,7 +368,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
let listed = owner
.owner_ctx
- .legacy_kits()
+ .kits()
.await
.expect("legacy kit list failed");
let listed_waiting_kit = listed
@@ -383,7 +380,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
let downloaded_shares = owner
.owner_ctx
- .legacy_kit_download_shares(&waiting_kit.kit.id)
+ .download_kit_shares(&waiting_kit.kit.id)
.await
.expect("legacy kit share download failed");
assert_eq!(downloaded_shares.len(), 3);
@@ -425,7 +422,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
let listed_after_invalid_open = owner
.owner_ctx
- .legacy_kits()
+ .kits()
.await
.expect("legacy kit list after invalid challenge failed");
let listed_waiting_after_invalid_open = listed_after_invalid_open
@@ -527,7 +524,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
assert_eq!(resumed_session.status, LegacyKitRecoveryStatus::Waiting);
let owner_recovery_session = owner
.owner_ctx
- .legacy_kit_recovery_session(&waiting_kit.kit.id)
+ .kit_recovery_session(&waiting_kit.kit.id)
.await
.expect("owner legacy kit recovery session fetch failed");
let owner_active_session = owner_recovery_session
@@ -559,7 +556,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
owner
.owner_ctx
- .legacy_kit_block_recovery(&waiting_kit.kit.id)
+ .block_kit_recovery(&waiting_kit.kit.id)
.await
.expect("legacy kit block failed");
let blocked_session = resumed_waiting_handle
@@ -577,7 +574,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
);
let blocked_owner_recovery_session = owner
.owner_ctx
- .legacy_kit_recovery_session(&waiting_kit.kit.id)
+ .kit_recovery_session(&waiting_kit.kit.id)
.await
.expect("owner legacy kit recovery session fetch after block failed");
assert!(blocked_owner_recovery_session.session.is_none());
@@ -585,12 +582,12 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
owner
.owner_ctx
- .legacy_kit_delete(&waiting_kit.kit.id)
+ .delete_kit(&waiting_kit.kit.id)
.await
.expect("legacy kit delete failed");
let listed_after_delete = owner
.owner_ctx
- .legacy_kits()
+ .kits()
.await
.expect("legacy kit list after delete failed");
assert!(
@@ -601,7 +598,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
let immediate_kit = owner
.owner_ctx
- .legacy_kit_create(
+ .create_kit(
&owner.owner.key_attributes,
["Alpha".into(), "Bravo".into(), "Charlie".into()],
0,
diff --git a/rust/crates/contacts/tests/contacts_mock.rs b/rust/crates/contacts/tests/contacts_mock.rs
index 99a2cf32fd..9df67642c1 100644
--- a/rust/crates/contacts/tests/contacts_mock.rs
+++ b/rust/crates/contacts/tests/contacts_mock.rs
@@ -1,7 +1,13 @@
-use ente_contacts::client::{ContactsCtx, OpenContactsCtxInput, RootKeySource};
+use std::sync::Arc;
+
+use ente_contacts::client::{ContactsClient, OpenContactsInput, OpenContactsResult, RootKeySource};
use ente_contacts::crypto as contacts_crypto;
use ente_contacts::models::{AttachmentType, ContactData, WrappedRootContactKey};
-use ente_core::{b64, crypto::Key};
+use ente_core::{
+ b64,
+ crypto::{Key, SecretVec},
+ http::{Api, ApiConfig, Auth, Http},
+};
use md5::Digest;
use mockito::{Matcher, Server};
@@ -12,17 +18,29 @@ fn sample_contact() -> ContactData {
}
}
-fn open_input(base_url: String, master_key: Vec<u8>) -> OpenContactsCtxInput {
- OpenContactsCtxInput {
- base_url,
- auth_token: "auth-token".to_string(),
- user_id: 7,
- master_key,
- cached_wrapped_root_contact_key: None,
- user_agent: Some("ente-contacts-test".to_string()),
- client_package: Some("io.ente.photos".to_string()),
- client_version: Some("1.0.0".to_string()),
- }
+fn open(
+ base_url: String,
+ master_key: Vec<u8>,
+ cached_wrapped_root_contact_key: Option<WrappedRootContactKey>,
+) -> ente_contacts::Result<OpenContactsResult> {
+ let api = Api::new(
+ Http::new()?,
+ ApiConfig {
+ origin: base_url,
+ client_package: Some("io.ente.photos".to_string()),
+ client_version: Some("1.0.0".to_string()),
+ user_agent: Some("ente-contacts-test".to_string()),
+ auth: Some(Auth::User("auth-token".to_string())),
+ },
+ );
+ ContactsClient::open(
+ Arc::new(api),
+ Arc::new(SecretVec::new(master_key)),
+ OpenContactsInput {
+ user_id: 7,
+ cached_wrapped_root_contact_key,
+ },
+ )
}
fn wrap_root(root_key: &[u8], master_key: &[u8]) -> WrappedRootContactKey {
@@ -78,9 +96,7 @@ async fn open_without_cached_wrapped_root_contact_key_is_unresolved() {
.create_async()
.await;
- let opened = ContactsCtx::open(open_input(server.url(), master_key.clone()))
- .await
- .unwrap();
+ let opened = open(server.url(), master_key.clone(), None).unwrap();
root_mock.assert_async().await;
assert_eq!(opened.root_key_source, RootKeySource::Unresolved);
@@ -130,16 +146,14 @@ async fn get_contact_fetches_root_key_when_unresolved_context_reads_live_contact
.create_async()
.await;
- let opened = ContactsCtx::open(open_input(server.url(), master_key))
- .await
- .unwrap();
- let fetched = opened.ctx.get_contact("ct_contact1").await.unwrap();
+ let opened = open(server.url(), master_key, None).unwrap();
+ let fetched = opened.client.get_contact("ct_contact1").await.unwrap();
root_fetch_mock.assert_async().await;
get_contact_mock.assert_async().await;
assert_eq!(opened.root_key_source, RootKeySource::Unresolved);
assert_eq!(
- opened.ctx.current_wrapped_root_contact_key(),
+ opened.client.current_wrapped_root_contact_key(),
Some(server_wrapped_root)
);
assert_eq!(fetched.name.as_deref(), Some(contact.name.as_str()));
@@ -193,13 +207,9 @@ async fn create_contact_uses_cached_wrapped_root_contact_key_without_fetching_re
.create_async()
.await;
- let ctx = ContactsCtx::open(OpenContactsCtxInput {
- cached_wrapped_root_contact_key: Some(wrapped_root),
- ..open_input(server.url(), master_key)
- })
- .await
- .unwrap()
- .ctx;
+ let ctx = open(server.url(), master_key, Some(wrapped_root))
+ .unwrap()
+ .client;
let created = ctx.create_contact(&contact).await.unwrap();
@@ -298,10 +308,7 @@ async fn set_profile_picture_uses_signed_upload_url_and_commit() {
.create_async()
.await;
- let ctx = ContactsCtx::open(open_input(server.url(), master_key))
- .await
- .unwrap()
- .ctx;
+ let ctx = open(server.url(), master_key, None).unwrap().client;
let updated = ctx
.set_profile_picture("ct_picture1", &picture_bytes)
@@ -395,10 +402,7 @@ async fn get_profile_picture_uses_signed_download_url() {
.create_async()
.await;
- let ctx = ContactsCtx::open(open_input(server.url(), master_key))
- .await
- .unwrap()
- .ctx;
+ let ctx = open(server.url(), master_key, None).unwrap().client;
let downloaded = ctx.get_profile_picture("ct_picture1").await.unwrap();
@@ -454,10 +458,7 @@ async fn delete_profile_picture_fetches_root_key_when_unresolved_context_decodes
.create_async()
.await;
- let ctx = ContactsCtx::open(open_input(server.url(), master_key))
- .await
- .unwrap()
- .ctx;
+ let ctx = open(server.url(), master_key, None).unwrap().client;
let updated = ctx.delete_profile_picture("ct_picture1").await.unwrap();
@@ -519,10 +520,7 @@ async fn get_attachment_uses_generic_signed_download_url() {
.create_async()
.await;
- let ctx = ContactsCtx::open(open_input(server.url(), master_key))
- .await
- .unwrap()
- .ctx;
+ let ctx = open(server.url(), master_key, None).unwrap().client;
let downloaded = ctx
.get_attachment_encrypted(AttachmentType::ProfilePicture, "ua_generic1")
@@ -586,10 +584,7 @@ async fn deleted_contacts_surface_as_tombstones() {
.create_async()
.await;
- let ctx = ContactsCtx::open(open_input(server.url(), master_key))
- .await
- .unwrap()
- .ctx;
+ let ctx = open(server.url(), master_key, None).unwrap().client;
let diff = ctx.get_diff(0, 10).await.unwrap();
root_mock.assert_async().await;
@@ -640,13 +635,9 @@ async fn get_diff_uses_cached_wrapped_root_contact_key_for_reads_without_fetchin
.create_async()
.await;
- let ctx = ContactsCtx::open(OpenContactsCtxInput {
- cached_wrapped_root_contact_key: Some(cached_wrapped_root),
- ..open_input(server.url(), master_key)
- })
- .await
- .unwrap()
- .ctx;
+ let ctx = open(server.url(), master_key, Some(cached_wrapped_root))
+ .unwrap()
+ .client;
let diff = ctx.get_diff(0, 10).await.unwrap();
diff --git a/rust/crates/contacts/tests/support/contacts.rs b/rust/crates/contacts/tests/support/contacts.rs
index 3c675c952c..8d9f7f5901 100644
--- a/rust/crates/contacts/tests/support/contacts.rs
+++ b/rust/crates/contacts/tests/support/contacts.rs
@@ -1,88 +1,33 @@
-use ente_contacts::{
- client::{ContactsCtx, OpenContactsCtxInput},
- legacy_models::{LegacyContactRecord, LegacyInfo, LegacyRecoverySession},
+use std::sync::Arc;
+
+use ente_contacts::{ContactsClient, OpenContactsInput};
+use ente_core::{
+ crypto::SecretVec,
+ http::{Api, ApiConfig, Auth, Http},
};
use crate::CLIENT_PACKAGE;
use crate::support::auth::TestAccount;
-pub async fn open_ctx(endpoint: &str, account: &TestAccount) -> ContactsCtx {
- ContactsCtx::open(OpenContactsCtxInput {
- base_url: endpoint.to_string(),
- auth_token: account.auth_token.clone(),
- user_id: account.user_id,
- master_key: account.master_key.clone(),
- cached_wrapped_root_contact_key: None,
- user_agent: Some("ente-contacts-e2e".to_string()),
- client_package: Some(CLIENT_PACKAGE.to_string()),
- client_version: Some("0.0.1".to_string()),
- })
- .await
+pub fn open_client(endpoint: &str, account: &TestAccount) -> ContactsClient {
+ let api = Api::new(
+ Http::new().unwrap(),
+ ApiConfig {
+ origin: endpoint.to_string(),
+ client_package: Some(CLIENT_PACKAGE.to_string()),
+ client_version: Some("0.0.1".to_string()),
+ user_agent: Some("ente-contacts-e2e".to_string()),
+ auth: Some(Auth::User(account.auth_token.clone())),
+ },
+ );
+ ContactsClient::open(
+ Arc::new(api),
+ Arc::new(SecretVec::new(account.master_key.clone())),
+ OpenContactsInput {
+ user_id: account.user_id,
+ cached_wrapped_root_contact_key: None,
+ },
+ )
.unwrap()
- .ctx
-}
-
-pub async fn establish_legacy_contact(
- owner_ctx: &ContactsCtx,
- owner: &TestAccount,
- trusted_ctx: &ContactsCtx,
- trusted: &TestAccount,
- recovery_notice_in_days: i32,
-) {
- owner_ctx
- .legacy_add_contact(
- &trusted.email,
- &owner.key_attributes,
- Some(recovery_notice_in_days),
- )
- .await
- .unwrap();
- trusted_ctx
- .legacy_update_contact(
- owner.user_id,
- trusted.user_id,
- ente_contacts::legacy_models::LegacyContactState::Accepted,
- )
- .await
- .unwrap();
-}
-
-pub fn owner_contact(
- info: &LegacyInfo,
- owner_user_id: i64,
- trusted_user_id: i64,
-) -> Option<&LegacyContactRecord> {
- info.contacts.iter().find(|record| {
- record.user.id == owner_user_id && record.emergency_contact.id == trusted_user_id
- })
-}
-
-pub fn trusted_contact(
- info: &LegacyInfo,
- owner_user_id: i64,
- trusted_user_id: i64,
-) -> Option<&LegacyContactRecord> {
- info.others_emergency_contact.iter().find(|record| {
- record.user.id == owner_user_id && record.emergency_contact.id == trusted_user_id
- })
-}
-
-pub fn owner_recovery_session(
- info: &LegacyInfo,
- owner_user_id: i64,
- trusted_user_id: i64,
-) -> Option<&LegacyRecoverySession> {
- info.recover_sessions.iter().find(|session| {
- session.user.id == owner_user_id && session.emergency_contact.id == trusted_user_id
- })
-}
-
-pub fn trusted_recovery_session(
- info: &LegacyInfo,
- owner_user_id: i64,
- trusted_user_id: i64,
-) -> Option<&LegacyRecoverySession> {
- info.others_recovery_session.iter().find(|session| {
- session.user.id == owner_user_id && session.emergency_contact.id == trusted_user_id
- })
+ .client
}
diff --git a/rust/crates/contacts/tests/support/legacy.rs b/rust/crates/contacts/tests/support/legacy.rs
index 94c9666955..d51b545b45 100644
--- a/rust/crates/contacts/tests/support/legacy.rs
+++ b/rust/crates/contacts/tests/support/legacy.rs
@@ -1,8 +1,15 @@
-use crate::support::{
- auth::{self, TestAccount},
- contacts,
+use std::sync::Arc;
+
+use ente_core::{
+ crypto::SecretVec,
+ http::{Api, ApiConfig, Auth, Http},
+};
+use ente_legacy::{
+ LegacyClient, LegacyContactRecord, LegacyContactState, LegacyInfo, LegacyRecoverySession,
};
-use ente_contacts::client::ContactsCtx;
+
+use crate::CLIENT_PACKAGE;
+use crate::support::auth::{self, TestAccount};
pub struct LegacyPairState {
pub owner: TestAccount,
@@ -12,8 +19,25 @@ pub struct LegacyPairState {
pub struct LegacyPair {
pub owner: TestAccount,
pub trusted: TestAccount,
- pub owner_ctx: ContactsCtx,
- pub trusted_ctx: ContactsCtx,
+ pub owner_ctx: LegacyClient,
+ pub trusted_ctx: LegacyClient,
+}
+
+pub fn open_client(endpoint: &str, account: &TestAccount) -> LegacyClient {
+ let api = Api::new(
+ Http::new().unwrap(),
+ ApiConfig {
+ origin: endpoint.to_string(),
+ client_package: Some(CLIENT_PACKAGE.to_string()),
+ client_version: Some("0.0.1".to_string()),
+ user_agent: Some("ente-legacy-e2e".to_string()),
+ auth: Some(Auth::User(account.auth_token.clone())),
+ },
+ );
+ LegacyClient::new(
+ Arc::new(api),
+ Arc::new(SecretVec::new(account.master_key.clone())),
+ )
}
pub async fn create_accepted_pair_state(
@@ -23,30 +47,30 @@ pub async fn create_accepted_pair_state(
let owner = auth::create_account_strict(endpoint, "legacy-owner", "LegacyOwner").await;
let trusted = auth::create_fixture_account(endpoint, "legacy-trusted").await;
- let (owner_ctx, trusted_ctx) = tokio::join!(
- contacts::open_ctx(endpoint, &owner),
- contacts::open_ctx(endpoint, &trusted)
- );
+ let owner_ctx = open_client(endpoint, &owner);
+ let trusted_ctx = open_client(endpoint, &trusted);
- contacts::establish_legacy_contact(
- &owner_ctx,
- &owner,
- &trusted_ctx,
- &trusted,
- recovery_notice_in_days,
- )
- .await;
+ owner_ctx
+ .add_contact(
+ &trusted.email,
+ &owner.key_attributes,
+ Some(recovery_notice_in_days),
+ )
+ .await
+ .unwrap();
+ trusted_ctx
+ .update_contact(owner.user_id, trusted.user_id, LegacyContactState::Accepted)
+ .await
+ .unwrap();
LegacyPairState { owner, trusted }
}
-pub async fn open_pair(endpoint: &str, state: &LegacyPairState) -> LegacyPair {
+pub fn open_pair(endpoint: &str, state: &LegacyPairState) -> LegacyPair {
let owner = state.owner.clone();
let trusted = state.trusted.clone();
- let (owner_ctx, trusted_ctx) = tokio::join!(
- contacts::open_ctx(endpoint, &owner),
- contacts::open_ctx(endpoint, &trusted)
- );
+ let owner_ctx = open_client(endpoint, &owner);
+ let trusted_ctx = open_client(endpoint, &trusted);
LegacyPair {
owner,
@@ -55,3 +79,43 @@ pub async fn open_pair(endpoint: &str, state: &LegacyPairState) -> LegacyPair {
trusted_ctx,
}
}
+
+pub fn owner_contact(
+ info: &LegacyInfo,
+ owner_user_id: i64,
+ trusted_user_id: i64,
+) -> Option<&LegacyContactRecord> {
+ info.contacts.iter().find(|record| {
+ record.user.id == owner_user_id && record.emergency_contact.id == trusted_user_id
+ })
+}
+
+pub fn trusted_contact(
+ info: &LegacyInfo,
+ owner_user_id: i64,
+ trusted_user_id: i64,
+) -> Option<&LegacyContactRecord> {
+ info.others_emergency_contact.iter().find(|record| {
+ record.user.id == owner_user_id && record.emergency_contact.id == trusted_user_id
+ })
+}
+
+pub fn owner_recovery_session(
+ info: &LegacyInfo,
+ owner_user_id: i64,
+ trusted_user_id: i64,
+) -> Option<&LegacyRecoverySession> {
+ info.recover_sessions.iter().find(|session| {
+ session.user.id == owner_user_id && session.emergency_contact.id == trusted_user_id
+ })
+}
+
+pub fn trusted_recovery_session(
+ info: &LegacyInfo,
+ owner_user_id: i64,
+ trusted_user_id: i64,
+) -> Option<&LegacyRecoverySession> {
+ info.others_recovery_session.iter().find(|session| {
+ session.user.id == owner_user_id && session.emergency_contact.id == trusted_user_id
+ })
+}
diff --git a/rust/crates/contacts/tests/support/legacy_kit.rs b/rust/crates/contacts/tests/support/legacy_kit.rs
index fa043fb9cb..002730558e 100644
--- a/rust/crates/contacts/tests/support/legacy_kit.rs
+++ b/rust/crates/contacts/tests/support/legacy_kit.rs
@@ -1,17 +1,17 @@
-use ente_contacts::client::ContactsCtx;
+use ente_legacy::LegacyClient;
use crate::support::{
auth::{self, TestAccount},
- contacts,
+ legacy,
};
pub struct LegacyKitOwner {
pub owner: TestAccount,
- pub owner_ctx: ContactsCtx,
+ pub owner_ctx: LegacyClient,
}
pub async fn create_owner(endpoint: &str) -> LegacyKitOwner {
let owner = auth::create_fixture_account(endpoint, "legacy-kit-owner").await;
- let owner_ctx = contacts::open_ctx(endpoint, &owner).await;
+ let owner_ctx = legacy::open_client(endpoint, &owner);
LegacyKitOwner { owner, owner_ctx }
}
diff --git a/rust/crates/legacy/Cargo.toml b/rust/crates/legacy/Cargo.toml
new file mode 100644
index 0000000000..00c4512d99
--- /dev/null
+++ b/rust/crates/legacy/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "ente-legacy"
+edition = "2024"
+
+[dependencies]
+ente-accounts.workspace = true
+ente-core.workspace = true
+serde.workspace = true
+serde_json.workspace = true
+sha2.workspace = true
+thiserror.workspace = true
+uuid = { version = "1", features = ["v4", "js"] }
diff --git a/rust/crates/legacy/src/client.rs b/rust/crates/legacy/src/client.rs
new file mode 100644
index 0000000000..fd1f294a9a
--- /dev/null
+++ b/rust/crates/legacy/src/client.rs
@@ -0,0 +1,541 @@
+use std::sync::Arc;
+
+use ente_accounts::auth::{self, KeyAttributes, SrpSession};
+use ente_core::b64;
+use ente_core::crypto::{self, SecretVec, sealed, secretbox};
+use ente_core::http::{self, Api};
+use sha2::{Digest, Sha256};
+use uuid::Uuid;
+
+use crate::error::{Error, Result};
+use crate::kit::{
+ create_legacy_kit_request, decode_download_content, decode_legacy_kit_record,
+ validate_notice_period,
+};
+use crate::kit_models::{
+ LegacyKit, LegacyKitCreateResult, LegacyKitOwnerRecoverySession, LegacyKitShare,
+};
+use crate::kit_transport::{
+ LegacyKitDownloadContentResponse, LegacyKitOwnerActionRequest,
+ LegacyKitOwnerRecoverySessionResponse, LegacyKitRecordResponse,
+ LegacyKitUpdateRecoveryNoticeRequest, ListLegacyKitsResponse,
+};
+use crate::models::{LegacyContactState, LegacyInfo, LegacyRecoveryBundle};
+use crate::transport::{
+ LegacyAddContactRequest, LegacyChangePasswordRequest, LegacyChangePasswordResponse,
+ LegacyContactIdentifier, LegacyInfoResponse, LegacyInitChangePasswordRequest,
+ LegacyPublicKeyResponse, LegacyRecoveryIdentifier, LegacyRecoveryInfoResponse,
+ LegacySetupSrpRequest, LegacySetupSrpResponse, LegacyUpdateContactRequest,
+ LegacyUpdateRecoveryNoticeRequest, LegacyUpdateSrpAndKeysRequest, LegacyUpdatedKeyAttr,
+};
+
+pub struct LegacyClient {
+ api: Arc<Api>,
+ master_key: Arc<SecretVec>,
+}
+
+impl LegacyClient {
+ pub fn new(api: Arc<Api>, master_key: Arc<SecretVec>) -> Self {
+ Self { api, master_key }
+ }
+
+ pub async fn info(&self) -> Result<LegacyInfo> {
+ Ok(self
+ .api
+ .get("/emergency-contacts/info")
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<LegacyInfoResponse>()
+ .await?)
+ }
+
+ pub async fn public_key(&self, email: &str) -> Result<Option<String>> {
+ let response = self
+ .api
+ .get("/users/public-key")
+ .query(&[("email", email.trim())])
+ .send()
+ .await?;
+ if response.status() == 404 {
+ return Ok(None);
+ }
+ let response = response
+ .error_for_status()?
+ .json::<LegacyPublicKeyResponse>()
+ .await?;
+ Ok(Some(response.public_key))
+ }
+
+ pub fn verification_id(&self, public_key_b64: &str) -> Result<String> {
+ let public_key = b64::decode(public_key_b64)?;
+ let digest = Sha256::digest(&public_key);
+ auth::recovery_key_to_mnemonic(&b64::encode(digest.as_slice())).map_err(Into::into)
+ }
+
+ pub async fn add_contact(
+ &self,
+ email: &str,
+ current_user_key_attrs: &KeyAttributes,
+ recovery_notice_in_days: Option<i32>,
+ ) -> Result<()> {
+ let public_key = self
+ .public_key(email)
+ .await?
+ .ok_or_else(|| Error::InvalidInput("legacy contact is not on Ente".into()))?;
+ let recovery_key = self.current_recovery_key(current_user_key_attrs)?;
+ let recipient_public_key = b64::decode(&public_key)?;
+ let encrypted_key = sealed::seal(
+ &recovery_key,
+ &crypto::PublicKey::try_from_slice(&recipient_public_key)?,
+ )?;
+
+ self.api
+ .post("/emergency-contacts/add")
+ .json(&LegacyAddContactRequest {
+ email: email.trim().to_string(),
+ encrypted_key: b64::encode(&encrypted_key),
+ recovery_notice_in_days,
+ })
+ .send()
+ .await?
+ .error_for_status()?;
+ Ok(())
+ }
+
+ pub async fn update_contact(
+ &self,
+ user_id: i64,
+ emergency_contact_id: i64,
+ state: LegacyContactState,
+ ) -> Result<()> {
+ self.api
+ .post("/emergency-contacts/update")
+ .json(&LegacyUpdateContactRequest {
+ user_id,
+ emergency_contact_id,
+ state,
+ })
+ .send()
+ .await?
+ .error_for_status()?;
+ Ok(())
+ }
+
+ pub async fn update_recovery_notice(
+ &self,
+ emergency_contact_id: i64,
+ recovery_notice_in_days: i32,
+ ) -> Result<()> {
+ self.api
+ .post("/emergency-contacts/update-recovery-notice")
+ .json(&LegacyUpdateRecoveryNoticeRequest {
+ emergency_contact_id,
+ recovery_notice_in_days,
+ })
+ .send()
+ .await?
+ .error_for_status()?;
+ Ok(())
+ }
+
+ pub async fn start_recovery(&self, user_id: i64, emergency_contact_id: i64) -> Result<()> {
+ self.contact_action(
+ "/emergency-contacts/start-recovery",
+ user_id,
+ emergency_contact_id,
+ )
+ .await
+ }
+
+ pub async fn stop_recovery(
+ &self,
+ recovery_id: &str,
+ user_id: i64,
+ emergency_contact_id: i64,
+ ) -> Result<()> {
+ self.recovery_action(
+ "/emergency-contacts/stop-recovery",
+ recovery_id,
+ user_id,
+ emergency_contact_id,
+ )
+ .await
+ }
+
+ pub async fn reject_recovery(
+ &self,
+ recovery_id: &str,
+ user_id: i64,
+ emergency_contact_id: i64,
+ ) -> Result<()> {
+ self.recovery_action(
+ "/emergency-contacts/reject-recovery",
+ recovery_id,
+ user_id,
+ emergency_contact_id,
+ )
+ .await
+ }
+
+ pub async fn approve_recovery(
+ &self,
+ recovery_id: &str,
+ user_id: i64,
+ emergency_contact_id: i64,
+ ) -> Result<()> {
+ self.recovery_action(
+ "/emergency-contacts/approve-recovery",
+ recovery_id,
+ user_id,
+ emergency_contact_id,
+ )
+ .await
+ }
+
+ pub async fn recovery_bundle(
+ &self,
+ recovery_id: &str,
+ current_user_key_attrs: &KeyAttributes,
+ ) -> Result<LegacyRecoveryBundle> {
+ let response = self.recovery_info(recovery_id).await?;
+ let recovery_key =
+ self.decrypt_recovery_key(&response.encrypted_key, current_user_key_attrs)?;
+
+ Ok(LegacyRecoveryBundle {
+ recovery_key,
+ user_key_attributes: response.user_key_attr,
+ })
+ }
+
+ pub async fn change_password(
+ &self,
+ recovery_id: &str,
+ current_user_key_attrs: &KeyAttributes,
+ new_password: &str,
+ ) -> Result<()> {
+ let bundle = self
+ .recovery_bundle(recovery_id, current_user_key_attrs)
+ .await?;
+ let target_master_key = decrypt_master_key_with_recovery_key(
+ &bundle.user_key_attributes,
+ &bundle.recovery_key,
+ )?;
+ let (updated_key_attrs, login_key) = auth::generate_key_attributes_for_new_password(
+ &target_master_key,
+ &bundle.user_key_attributes,
+ new_password,
+ )?;
+ let srp_user_id = Uuid::new_v4().to_string();
+ let (mut srp_session, setup_request) =
+ password_reset_setup_request(&srp_user_id, &login_key)?;
+ let init_response = self
+ .api
+ .post("/emergency-contacts/init-change-password")
+ .json(&LegacyInitChangePasswordRequest {
+ recovery_id: recovery_id.to_string(),
+ setup_srp_request: setup_request,
+ })
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<LegacySetupSrpResponse>()
+ .await?;
+ let srp_m1 = srp_session_m1(&mut srp_session, &init_response)?;
+ let updated_key_attr = LegacyUpdatedKeyAttr {
+ kek_salt: updated_key_attrs.kek_salt.clone(),
+ encrypted_key: updated_key_attrs.encrypted_key.clone(),
+ key_decryption_nonce: updated_key_attrs.key_decryption_nonce.clone(),
+ mem_limit: updated_key_attrs.mem_limit,
+ ops_limit: updated_key_attrs.ops_limit,
+ };
+
+ let change_response = self
+ .api
+ .post("/emergency-contacts/change-password")
+ .json(&LegacyChangePasswordRequest {
+ recovery_id: recovery_id.to_string(),
+ update_srp_and_keys_request: LegacyUpdateSrpAndKeysRequest {
+ setup_id: init_response.setup_id,
+ srp_m1,
+ updated_key_attr,
+ },
+ })
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<LegacyChangePasswordResponse>()
+ .await?;
+
+ let server_m2 = b64::decode(&change_response.srp_m2)?;
+ srp_session.verify_m2(&server_m2)?;
+ Ok(())
+ }
+
+ pub async fn kits(&self) -> Result<Vec<LegacyKit>> {
+ let response = self
+ .api
+ .get("/legacy-kits")
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<ListLegacyKitsResponse>()
+ .await?;
+ response
+ .kits
+ .into_iter()
+ .map(|kit| decode_legacy_kit_record(kit, self.master_key.as_ref()))
+ .collect()
+ }
+
+ pub async fn create_kit(
+ &self,
+ current_user_key_attrs: &KeyAttributes,
+ part_names: [String; 3],
+ notice_period_in_hours: i32,
+ ) -> Result<LegacyKitCreateResult> {
+ let (request, shares) = {
+ let recovery_key = self.current_recovery_key(current_user_key_attrs)?;
+ create_legacy_kit_request(
+ &recovery_key,
+ self.master_key.as_ref(),
+ part_names,
+ notice_period_in_hours,
+ )?
+ };
+
+ let response = self
+ .api
+ .post("/legacy-kits")
+ .json(&request)
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<LegacyKitRecordResponse>()
+ .await?;
+ let kit = decode_legacy_kit_record(response, self.master_key.as_ref())?;
+ Ok(LegacyKitCreateResult { kit, shares })
+ }
+
+ pub async fn download_kit_shares(&self, kit_id: &str) -> Result<Vec<LegacyKitShare>> {
+ let response = self
+ .api
+ .get(&format!("/legacy-kits/{kit_id}/download-content"))
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<LegacyKitDownloadContentResponse>()
+ .await?;
+ decode_download_content(response, self.master_key.as_ref())
+ }
+
+ pub async fn kit_recovery_session(
+ &self,
+ kit_id: &str,
+ ) -> Result<LegacyKitOwnerRecoverySession> {
+ let response = self
+ .api
+ .get(&format!("/legacy-kits/{kit_id}/recovery-session"))
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<LegacyKitOwnerRecoverySessionResponse>()
+ .await?;
+ Ok(response.into())
+ }
+
+ pub async fn update_kit_recovery_notice(
+ &self,
+ kit_id: &str,
+ notice_period_in_hours: i32,
+ ) -> Result<()> {
+ validate_notice_period(notice_period_in_hours)?;
+ let path = "/legacy-kits/update-recovery-notice";
+ let response = self
+ .api
+ .post(path)
+ .json(&LegacyKitUpdateRecoveryNoticeRequest {
+ kit_id: kit_id.to_string(),
+ notice_period_in_hours,
+ })
+ .send()
+ .await?;
+ if response.status() == 400 {
+ return if response.text().await?.contains("active recovery session") {
+ Err(Error::ActiveRecoverySession)
+ } else {
+ Err(http::Error::Http {
+ status: 400,
+ path: path.into(),
+ }
+ .into())
+ };
+ }
+ response.error_for_status()?;
+ Ok(())
+ }
+
+ pub async fn block_kit_recovery(&self, kit_id: &str) -> Result<()> {
+ self.api
+ .post("/legacy-kits/block-recovery")
+ .json(&LegacyKitOwnerActionRequest {
+ kit_id: kit_id.to_string(),
+ })
+ .send()
+ .await?
+ .error_for_status()?;
+ Ok(())
+ }
+
+ pub async fn delete_kit(&self, kit_id: &str) -> Result<()> {
+ self.api
+ .delete(&format!("/legacy-kits/{kit_id}"))
+ .send()
+ .await?
+ .error_for_status()?;
+ Ok(())
+ }
+
+ async fn contact_action(
+ &self,
+ path: &str,
+ user_id: i64,
+ emergency_contact_id: i64,
+ ) -> Result<()> {
+ self.api
+ .post(path)
+ .json(&LegacyContactIdentifier {
+ user_id,
+ emergency_contact_id,
+ })
+ .send()
+ .await?
+ .error_for_status()?;
+ Ok(())
+ }
+
+ async fn recovery_action(
+ &self,
+ path: &str,
+ recovery_id: &str,
+ user_id: i64,
+ emergency_contact_id: i64,
+ ) -> Result<()> {
+ self.api
+ .post(path)
+ .json(&LegacyRecoveryIdentifier {
+ id: recovery_id.to_string(),
+ user_id,
+ emergency_contact_id,
+ })
+ .send()
+ .await?
+ .error_for_status()?;
+ Ok(())
+ }
+
+ async fn recovery_info(&self, recovery_id: &str) -> Result<LegacyRecoveryInfoResponse> {
+ Ok(self
+ .api
+ .get(&format!("/emergency-contacts/recovery-info/{recovery_id}"))
+ .send()
+ .await?
+ .error_for_status()?
+ .json::<LegacyRecoveryInfoResponse>()
+ .await?)
+ }
+
+ fn current_recovery_key(&self, current_user_key_attrs: &KeyAttributes) -> Result<SecretVec> {
+ let recovery_key_hex =
+ auth::get_recovery_key(self.master_key.as_ref(), current_user_key_attrs)?;
+ Ok(auth::recovery_key_from_mnemonic_or_hex(&recovery_key_hex)?)
+ }
+
+ fn decrypt_recovery_key(
+ &self,
+ encrypted_key_b64: &str,
+ current_user_key_attrs: &KeyAttributes,
+ ) -> Result<SecretVec> {
+ let public_key = b64::decode(&current_user_key_attrs.public_key)?;
+ let encrypted_key = b64::decode(encrypted_key_b64)?;
+ let secret_key = self.current_secret_key(current_user_key_attrs)?;
+ let decrypted = sealed::open(
+ &encrypted_key,
+ &crypto::PublicKey::try_from_slice(&public_key)?,
+ &crypto::SecretKey::try_from_slice(&secret_key)?,
+ )?;
+ Ok(SecretVec::new(decrypted))
+ }
+
+ fn current_secret_key(&self, current_user_key_attrs: &KeyAttributes) -> Result<SecretVec> {
+ let encrypted_secret_key = b64::decode(&current_user_key_attrs.encrypted_secret_key)?;
+ let secret_key_nonce = b64::decode(&current_user_key_attrs.secret_key_decryption_nonce)?;
+ let secret_key = secretbox::decrypt(
+ &encrypted_secret_key,
+ &crypto::Nonce::try_from_slice(&secret_key_nonce)?,
+ &crypto::Key::try_from_slice(self.master_key.as_ref())?,
+ )?;
+ Ok(SecretVec::new(secret_key))
+ }
+}
+
+fn decrypt_master_key_with_recovery_key(
+ key_attributes: &KeyAttributes,
+ recovery_key: &[u8],
+) -> Result<SecretVec> {
+ let encrypted_master_key = key_attributes
+ .master_key_encrypted_with_recovery_key
+ .as_ref()
+ .ok_or_else(|| {
+ Error::InvalidInput(
+ "target key attributes missing masterKeyEncryptedWithRecoveryKey".into(),
+ )
+ })?;
+ let master_key_nonce = key_attributes
+ .master_key_decryption_nonce
+ .as_ref()
+ .ok_or_else(|| {
+ Error::InvalidInput("target key attributes missing masterKeyDecryptionNonce".into())
+ })?;
+ let encrypted_master_key = b64::decode(encrypted_master_key)?;
+ let master_key_nonce = b64::decode(master_key_nonce)?;
+ secretbox::decrypt(
+ &encrypted_master_key,
+ &crypto::Nonce::try_from_slice(&master_key_nonce)?,
+ &crypto::Key::try_from_slice(recovery_key)?,
+ )
+ .map(SecretVec::new)
+ .map_err(Into::into)
+}
+
+fn password_reset_setup_request(
+ srp_user_id: &str,
+ login_key: &[u8],
+) -> Result<(SrpSession, LegacySetupSrpRequest)> {
+ let generated_srp = auth::generate_srp_setup_with_login_key(login_key, srp_user_id)?;
+ let srp_session = SrpSession::new(
+ srp_user_id,
+ &generated_srp.srp_salt,
+ &generated_srp.login_sub_key,
+ )?;
+ let srp_a = b64::encode(&srp_session.public_a());
+
+ Ok((
+ srp_session,
+ LegacySetupSrpRequest {
+ srp_user_id: srp_user_id.to_string(),
+ srp_salt: b64::encode(&generated_srp.srp_salt),
+ srp_verifier: b64::encode(&generated_srp.srp_verifier),
+ srp_a,
+ },
+ ))
+}
+
+fn srp_session_m1(
+ srp_session: &mut SrpSession,
+ init_response: &LegacySetupSrpResponse,
+) -> Result<String> {
+ let server_b = b64::decode(&init_response.srp_b)?;
+ let client_m1 = srp_session.compute_m1(&server_b)?;
+ Ok(b64::encode(&client_m1))
+}
diff --git a/rust/crates/legacy/src/error.rs b/rust/crates/legacy/src/error.rs
new file mode 100644
index 0000000000..ad615acc39
--- /dev/null
+++ b/rust/crates/legacy/src/error.rs
@@ -0,0 +1,50 @@
+use ente_core::{b64, crypto, http};
+use thiserror::Error;
+
+#[derive(Debug, Error)]
+pub enum Error {
+ #[error(transparent)]
+ Http(#[from] http::Error),
+
+ #[error(transparent)]
+ Crypto(#[from] crypto::Error),
+
+ #[error("base64 decode error: {0}")]
+ Base64Decode(#[from] b64::DecodeError),
+
+ #[error(transparent)]
+ Accounts(#[from] ente_accounts::Error),
+
+ #[error("invalid input: {0}")]
+ InvalidInput(String),
+
+ #[error("a recovery is already in progress")]
+ ActiveRecoverySession,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum ErrorKind {
+ Network,
+ Http,
+ Parse,
+ Crypto,
+ Auth,
+ InvalidInput,
+ ActiveRecoverySession,
+}
+
+impl Error {
+ pub fn kind(&self) -> ErrorKind {
+ match self {
+ Error::Http(http::Error::Network(_)) => ErrorKind::Network,
+ Error::Http(http::Error::Parse(_)) => ErrorKind::Parse,
+ Error::Http(_) => ErrorKind::Http,
+ Error::Crypto(_) | Error::Base64Decode(_) => ErrorKind::Crypto,
+ Error::Accounts(_) => ErrorKind::Auth,
+ Error::InvalidInput(_) => ErrorKind::InvalidInput,
+ Error::ActiveRecoverySession => ErrorKind::ActiveRecoverySession,
+ }
+ }
+}
+
+pub type Result<T> = std::result::Result<T, Error>;
diff --git a/rust/crates/contacts/src/legacy_kit/mod.rs b/rust/crates/legacy/src/kit/mod.rs
similarity index 99%
rename from rust/crates/contacts/src/legacy_kit/mod.rs
rename to rust/crates/legacy/src/kit/mod.rs
index 4bb88a3c67..f732ea00ed 100644
--- a/rust/crates/contacts/src/legacy_kit/mod.rs
+++ b/rust/crates/legacy/src/kit/mod.rs
@@ -13,11 +13,11 @@ use uuid::Uuid;
use crate::{
Error, Result,
- legacy_kit_models::{
+ kit_models::{
LEGACY_KIT_PAYLOAD_VERSION, LegacyKit, LegacyKitRecoveryBundle, LegacyKitRecoverySession,
LegacyKitShare, LegacyKitVariant,
},
- legacy_kit_transport::{
+ kit_transport::{
CreateLegacyKitRequest, LegacyKitChallengeRequest, LegacyKitChallengeResponse,
LegacyKitChangePasswordRequest, LegacyKitChangePasswordResponse,
LegacyKitDownloadContentResponse, LegacyKitInitChangePasswordRequest,
diff --git a/rust/crates/contacts/src/legacy_kit/owner_blob.rs b/rust/crates/legacy/src/kit/owner_blob.rs
similarity index 97%
rename from rust/crates/contacts/src/legacy_kit/owner_blob.rs
rename to rust/crates/legacy/src/kit/owner_blob.rs
index ca1a0d5809..5f71968ebc 100644
--- a/rust/crates/contacts/src/legacy_kit/owner_blob.rs
+++ b/rust/crates/legacy/src/kit/owner_blob.rs
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize, de::DeserializeOwned};
use crate::{
Error, Result,
- legacy_kit_models::{LegacyKitMetadata, LegacyKitPart, LegacyKitShare},
+ kit_models::{LegacyKitMetadata, LegacyKitPart, LegacyKitShare},
};
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/rust/crates/contacts/src/legacy_kit/shares.rs b/rust/crates/legacy/src/kit/shares.rs
similarity index 98%
rename from rust/crates/contacts/src/legacy_kit/shares.rs
rename to rust/crates/legacy/src/kit/shares.rs
index 386eba086d..a08e24fdc2 100644
--- a/rust/crates/contacts/src/legacy_kit/shares.rs
+++ b/rust/crates/legacy/src/kit/shares.rs
@@ -4,7 +4,7 @@ use sha2::{Digest, Sha256};
use crate::{
Error, Result,
- legacy_kit_models::{LEGACY_KIT_PAYLOAD_VERSION, LegacyKitShare, LegacyKitVariant},
+ kit_models::{LEGACY_KIT_PAYLOAD_VERSION, LegacyKitShare, LegacyKitVariant},
};
pub(super) fn checksum(
diff --git a/rust/crates/contacts/src/legacy_kit_models.rs b/rust/crates/legacy/src/kit_models.rs
similarity index 100%
rename from rust/crates/contacts/src/legacy_kit_models.rs
rename to rust/crates/legacy/src/kit_models.rs
diff --git a/rust/crates/contacts/src/legacy_kit_transport.rs b/rust/crates/legacy/src/kit_transport.rs
similarity index 98%
rename from rust/crates/contacts/src/legacy_kit_transport.rs
rename to rust/crates/legacy/src/kit_transport.rs
index c79ada31da..6eb70b304b 100644
--- a/rust/crates/contacts/src/legacy_kit_transport.rs
+++ b/rust/crates/legacy/src/kit_transport.rs
@@ -1,7 +1,7 @@
use ente_accounts::auth::KeyAttributes;
use serde::{Deserialize, Serialize};
-use crate::legacy_kit_models::{
+use crate::kit_models::{
LegacyKitOwnerRecoverySession, LegacyKitRecoverySession, LegacyKitVariant,
};
@@ -95,7 +95,7 @@ pub struct LegacyKitOpenRecoveryResponse {
#[serde(rename_all = "camelCase")]
pub struct LegacyKitOwnerRecoverySessionResponse {
pub session: Option<LegacyKitRecoverySession>,
- pub initiators: Vec<crate::legacy_kit_models::LegacyKitRecoveryInitiator>,
+ pub initiators: Vec<crate::kit_models::LegacyKitRecoveryInitiator>,
}
impl From<LegacyKitOwnerRecoverySessionResponse> for LegacyKitOwnerRecoverySession {
diff --git a/rust/crates/legacy/src/lib.rs b/rust/crates/legacy/src/lib.rs
new file mode 100644
index 0000000000..9dc28e4f4a
--- /dev/null
+++ b/rust/crates/legacy/src/lib.rs
@@ -0,0 +1,21 @@
+pub mod client;
+pub mod error;
+pub mod kit;
+pub mod kit_models;
+pub mod kit_transport;
+pub mod models;
+pub mod transport;
+
+pub use client::LegacyClient;
+pub use error::{Error, ErrorKind, Result};
+pub use kit::{LegacyKitRecoveryClient, LegacyKitRecoveryHandle};
+pub use kit_models::{
+ LEGACY_KIT_PAYLOAD_VERSION, LegacyKit, LegacyKitCreateResult, LegacyKitMetadata,
+ LegacyKitOwnerRecoverySession, LegacyKitPart, LegacyKitRecoveryBundle,
+ LegacyKitRecoveryInitiator, LegacyKitRecoverySession, LegacyKitRecoveryStatus, LegacyKitShare,
+ LegacyKitVariant,
+};
+pub use models::{
+ LegacyContactRecord, LegacyContactState, LegacyInfo, LegacyRecoveryBundle,
+ LegacyRecoverySession, LegacyRecoveryStatus, LegacyUser,
+};
diff --git a/rust/crates/contacts/src/legacy_models.rs b/rust/crates/legacy/src/models.rs
similarity index 100%
rename from rust/crates/contacts/src/legacy_models.rs
rename to rust/crates/legacy/src/models.rs
diff --git a/rust/crates/contacts/src/legacy_transport.rs b/rust/crates/legacy/src/transport.rs
similarity index 99%
rename from rust/crates/contacts/src/legacy_transport.rs
rename to rust/crates/legacy/src/transport.rs
index c160b4b074..d64dc5a911 100644
--- a/rust/crates/contacts/src/legacy_transport.rs
+++ b/rust/crates/legacy/src/transport.rs
@@ -1,7 +1,7 @@
use ente_accounts::auth::KeyAttributes;
use serde::{Deserialize, Serialize};
-use crate::legacy_models::{LegacyContactState, LegacyInfo};
+use crate::models::{LegacyContactState, LegacyInfo};
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]