π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][contacts] scope wrapped root keys by user
Neeraj Guptafc56bbfde9be
diff --git a/mobile/packages/contacts/lib/src/service/contacts_service.dart b/mobile/packages/contacts/lib/src/service/contacts_service.dartindex 8454909ae7..ac0c8ceb0b 100644--- a/mobile/packages/contacts/lib/src/service/contacts_service.dart+++ b/mobile/packages/contacts/lib/src/service/contacts_service.dart@@ -10,8 +10,6 @@ import 'package:logging/logging.dart';import 'package:shared_preferences/shared_preferences.dart';class ContactsService {- static const _entityKeyPref = 'entity_key_contact';- static const _entityHeaderPref = 'entity_key_header_contact';static const _syncLimit = 5000;ContactsService({@@ -32,7 +30,7 @@ class ContactsService {Future<void> open(ContactsSession session) async {final accountKey = await session.resolveAccountKey();- final cachedRootKey = _cachedRootKey();+ final cachedRootKey = _cachedRootKey(session.userId);final opened = await _rustApi.open(OpenContactsContextInput(baseUrl: session.baseUrl,@@ -49,7 +47,7 @@ class ContactsService {_ctx = opened.ctx;_session = session;await _database.configure(userId: session.userId);- await _persistWrappedRootKey(opened.wrappedRootKey);+ await _persistWrappedRootKey(session.userId, opened.wrappedRootKey);_logger.info('Opened contacts context for user ${session.userId}');}@@ -186,17 +184,25 @@ class ContactsService {return ctx;}- WrappedRootContactKey? _cachedRootKey() {- final encryptedKey = _preferences.getString(_entityKeyPref);- final header = _preferences.getString(_entityHeaderPref);+ WrappedRootContactKey? _cachedRootKey(int userId) {+ final encryptedKey = _preferences.getString(_entityKeyPref(userId));+ final header = _preferences.getString(_entityHeaderPref(userId));if (encryptedKey == null || header == null) {return null;}return WrappedRootContactKey(encryptedKey: encryptedKey, header: header);}- Future<void> _persistWrappedRootKey(WrappedRootContactKey key) async {- await _preferences.setString(_entityKeyPref, key.encryptedKey);- await _preferences.setString(_entityHeaderPref, key.header);+ Future<void> _persistWrappedRootKey(+ int userId,+ WrappedRootContactKey key,+ ) async {+ await _preferences.setString(_entityKeyPref(userId), key.encryptedKey);+ await _preferences.setString(_entityHeaderPref(userId), key.header);}++ String _entityKeyPref(int userId) => 'entity_key_contact_$userId';++ String _entityHeaderPref(int userId) =>+ 'entity_key_header_contact_$userId';}diff --git a/mobile/packages/contacts/test/contacts_service_test.dart b/mobile/packages/contacts/test/contacts_service_test.dartindex aa9cc7699c..75ad12d670 100644--- a/mobile/packages/contacts/test/contacts_service_test.dart+++ b/mobile/packages/contacts/test/contacts_service_test.dart@@ -69,8 +69,11 @@ void main() {),);- expect(preferences.getString('entity_key_contact'), 'enc-key');- expect(preferences.getString('entity_key_header_contact'), 'enc-header');+ expect(preferences.getString('entity_key_contact_1'), 'enc-key');+ expect(+ preferences.getString('entity_key_header_contact_1'),+ 'enc-header',+ );final synced = await service.sync();expect(synced, hasLength(1));