π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use the Session recovery key for Legacy Kit creation
Manav Rathiaec20b6d2974
diff --git a/mobile/apps/locker/lib/services/legacy_kit.dart b/mobile/apps/locker/lib/services/legacy_kit.dartdeleted file mode 100644index b51cab6944..0000000000--- a/mobile/apps/locker/lib/services/legacy_kit.dart+++ /dev/null@@ -1,43 +0,0 @@-import 'package:ente_base/models/key_attributes.dart';-import 'package:ente_frb/legacy.dart';-import 'package:locker/src/rust/api/legacy.dart' as rust;-import 'package:locker/src/rust/third_party/ente_frb_lib/session.dart';--export 'package:locker/src/rust/api/legacy.dart'- show- blockKitRecovery,- deleteKit,- downloadKitShares,- kits,- updateKitRecoveryNotice;--Future<LegacyKitCreateResult> createKit({- required Session session,- required KeyAttributes currentUserKeyAttrs,- required List<String> partNames,- required int noticePeriodInHours,-}) => rust.createKit(- session: session,- currentUserKeyAttrs: _toRustKeyAttributes(currentUserKeyAttrs),- partNames: partNames,- noticePeriodInHours: noticePeriodInHours,-);--rust.AccountKeyAttributes _toRustKeyAttributes(KeyAttributes attributes) {- return rust.AccountKeyAttributes(- kekSalt: attributes.kekSalt,- encryptedKey: attributes.encryptedKey,- keyDecryptionNonce: attributes.keyDecryptionNonce,- publicKey: attributes.publicKey,- encryptedSecretKey: attributes.encryptedSecretKey,- secretKeyDecryptionNonce: attributes.secretKeyDecryptionNonce,- memLimit: attributes.memLimit,- opsLimit: attributes.opsLimit,- masterKeyEncryptedWithRecoveryKey:- attributes.masterKeyEncryptedWithRecoveryKey,- masterKeyDecryptionNonce: attributes.masterKeyDecryptionNonce,- recoveryKeyEncryptedWithMasterKey:- attributes.recoveryKeyEncryptedWithMasterKey,- recoveryKeyDecryptionNonce: attributes.recoveryKeyDecryptionNonce,- );-}diff --git a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart b/mobile/apps/locker/lib/ui/utils/legacy_utils.dartindex 78d709be26..80f92c1f22 100644--- a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart+++ b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart@@ -9,7 +9,7 @@ import "package:ente_strings/ente_strings.dart";import "package:flutter/material.dart";import "package:locker/services/authenticated_session.dart";import "package:locker/services/configuration.dart";-import "package:locker/services/legacy_kit.dart" as legacy;+import "package:locker/src/rust/api/legacy.dart" as legacy;import "package:logging/logging.dart";final _logger = Logger("LegacyUtils");@@ -109,13 +109,8 @@ Future<LegacyKitCreateResult> _createLegacyKit(List<String> partNames,int noticePeriodInHours,) async {- final keyAttributes = Configuration.instance.getKeyAttributes();- if (keyAttributes == null) {- throw StateError("Missing account key attributes");- }final result = await legacy.createKit(session: authenticatedSession(),- currentUserKeyAttrs: keyAttributes,partNames: partNames,noticePeriodInHours: noticePeriodInHours,);diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 275789937b..5307c278f7 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2656,7 +2656,6 @@ dependencies = [name = "ente-locker-frb"version = "0.0.0"dependencies = [- "ente-accounts","ente-assets","ente-core","ente-frb-lib",diff --git a/rust/bindings/frb/locker/Cargo.toml b/rust/bindings/frb/locker/Cargo.tomlindex 17bf23b1aa..cfa26b0945 100644--- a/rust/bindings/frb/locker/Cargo.toml+++ b/rust/bindings/frb/locker/Cargo.toml@@ -6,7 +6,6 @@ edition.workspace = truecrate-type = ["cdylib", "staticlib"][dependencies]-ente-accounts.workspace = trueente-assets.workspace = trueente-core.workspace = trueente-frb-lib = { workspace = true, features = ["contacts", "legacy", "locker"] }diff --git a/rust/bindings/frb/locker/src/api/legacy.rs b/rust/bindings/frb/locker/src/api/legacy.rsindex be93833928..45068dffc8 100644--- a/rust/bindings/frb/locker/src/api/legacy.rs+++ b/rust/bindings/frb/locker/src/api/legacy.rs@@ -1,45 +1,6 @@-use flutter_rust_bridge::frb;-use ente_frb_lib::legacy::{LegacyError, LegacyKit, LegacyKitCreateResult, LegacyKitShare};use ente_frb_lib::session::Session;-#[frb]-#[derive(Clone)]-pub struct AccountKeyAttributes {- pub kek_salt: String,- pub encrypted_key: String,- pub key_decryption_nonce: String,- pub public_key: String,- pub encrypted_secret_key: String,- pub secret_key_decryption_nonce: String,- pub mem_limit: u32,- pub ops_limit: u32,- pub master_key_encrypted_with_recovery_key: Option<String>,- pub master_key_decryption_nonce: Option<String>,- pub recovery_key_encrypted_with_master_key: Option<String>,- pub recovery_key_decryption_nonce: Option<String>,-}--impl From<AccountKeyAttributes> for ente_accounts::auth::KeyAttributes {- fn from(value: AccountKeyAttributes) -> Self {- Self {- kek_salt: value.kek_salt,- kek_hash: None,- encrypted_key: value.encrypted_key,- key_decryption_nonce: value.key_decryption_nonce,- public_key: value.public_key,- encrypted_secret_key: value.encrypted_secret_key,- secret_key_decryption_nonce: value.secret_key_decryption_nonce,- mem_limit: value.mem_limit,- ops_limit: value.ops_limit,- master_key_encrypted_with_recovery_key: value.master_key_encrypted_with_recovery_key,- master_key_decryption_nonce: value.master_key_decryption_nonce,- recovery_key_encrypted_with_master_key: value.recovery_key_encrypted_with_master_key,- recovery_key_decryption_nonce: value.recovery_key_decryption_nonce,- }- }-}-pub async fn kits(session: &Session) -> Result<Vec<LegacyKit>, LegacyError> {ente_legacy::kits(session.as_ref()).await@@ -49,21 +10,15 @@ pub async fn kits(session: &Session) -> Result<Vec<LegacyKit>, LegacyError> {pub async fn create_kit(session: &Session,- current_user_key_attrs: AccountKeyAttributes,part_names: Vec<String>,notice_period_in_hours: i32,) -> Result<LegacyKitCreateResult, LegacyError> {let part_names: [String; 3] = part_names.try_into().map_err(|_| LegacyError::Other {message: "legacy kit requires exactly three part names".into(),})?;- ente_legacy::create_kit(- session.as_ref(),- ¤t_user_key_attrs.into(),- part_names,- notice_period_in_hours,- )- .await?- .try_into()+ ente_legacy::create_kit(session.as_ref(), part_names, notice_period_in_hours)+ .await?+ .try_into()}pub async fn download_kit_shares(diff --git a/rust/crates/contacts/tests/contacts.rs b/rust/crates/contacts/tests/contacts.rsindex 14eb03e6be..a6580d7f83 100644--- a/rust/crates/contacts/tests/contacts.rs+++ b/rust/crates/contacts/tests/contacts.rs@@ -382,7 +382,6 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitOlet waiting_kit = ente_legacy::create_kit(&owner.owner_session,- &owner.owner.key_attributes,["North".into(), "East".into(), "West".into()],24,)@@ -614,7 +613,6 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitOlet immediate_kit = ente_legacy::create_kit(&owner.owner_session,- &owner.owner.key_attributes,["Alpha".into(), "Bravo".into(), "Charlie".into()],0,)diff --git a/rust/crates/legacy/src/client/kit/mod.rs b/rust/crates/legacy/src/client/kit/mod.rsindex a81f512d87..bc7f99a7fe 100644--- a/rust/crates/legacy/src/client/kit/mod.rs+++ b/rust/crates/legacy/src/client/kit/mod.rs@@ -1,12 +1,11 @@mod owner_blob;-use ente_accounts::auth::KeyAttributes;use ente_core::crypto::{self, Key, SecretVec, secretbox};use ente_core::{Session, b64};use serde::{Deserialize, Serialize};use uuid::Uuid;-use super::{current_recovery_key, map_recovery_notice_error};+use super::map_recovery_notice_error;use crate::kit::{LEGACY_KIT_PAYLOAD_VERSION, LegacyKit, LegacyKitCreateResult, LegacyKitOwnerRecoverySession,LegacyKitRecoveryInitiator, LegacyKitRecoverySession, LegacyKitShare, LegacyKitVariant,@@ -37,19 +36,15 @@ pub async fn kits(session: &Session) -> Result<Vec<LegacyKit>> {pub async fn create_kit(session: &Session,- key_attributes: &KeyAttributes,part_names: [String; 3],notice_period_in_hours: i32,) -> Result<LegacyKitCreateResult> {- let (request, shares) = {- let recovery_key = current_recovery_key(session, key_attributes)?;- create_kit_request(- &recovery_key,- &session.master_key,- part_names,- notice_period_in_hours,- )?- };+ let (request, shares) = create_kit_request(+ session.recovery_key.as_bytes(),+ &session.master_key,+ part_names,+ notice_period_in_hours,+ )?;let response = session.api