π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[auth] unify secure storage config and allow iCloud backup location
Prateek Sunal9547c3a2414d
diff --git a/mobile/apps/auth/ios/Podfile.lock b/mobile/apps/auth/ios/Podfile.lockindex 9fcf20b48e..985a9edc8d 100644--- a/mobile/apps/auth/ios/Podfile.lock+++ b/mobile/apps/auth/ios/Podfile.lock@@ -90,6 +90,8 @@ PODS:- SDWebImage (5.21.2):- SDWebImage/Core (= 5.21.2)- SDWebImage/Core (5.21.2)+ - security_scoped_resource (0.0.1):+ - Flutter- Sentry/HybridSDK (8.46.0)- sentry_flutter (8.14.2):- Flutter@@ -157,6 +159,7 @@ DEPENDENCIES:- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)- privacy_screen (from `.symlinks/plugins/privacy_screen/ios`)- qr_code_scanner (from `.symlinks/plugins/qr_code_scanner/ios`)+ - security_scoped_resource (from `.symlinks/plugins/security_scoped_resource/ios`)- sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`)- share_plus (from `.symlinks/plugins/share_plus/ios`)- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)@@ -224,6 +227,8 @@ EXTERNAL SOURCES::path: ".symlinks/plugins/privacy_screen/ios"qr_code_scanner::path: ".symlinks/plugins/qr_code_scanner/ios"+ security_scoped_resource:+ :path: ".symlinks/plugins/security_scoped_resource/ios"sentry_flutter::path: ".symlinks/plugins/sentry_flutter/ios"share_plus:@@ -270,6 +275,7 @@ SPEC CHECKSUMS:privacy_screen: 3159a541f5d3a31bea916cfd4e58f9dc722b3fd4qr_code_scanner: d77f94ecc9abf96d9b9b8fc04ef13f611e5a147aSDWebImage: 9f177d83116802728e122410fb25ad88f5c7608a+ security_scoped_resource: 8b95b9c0e93ae4e03b60e9b6be9c2d61e3751ec1Sentry: da60d980b197a46db0b35ea12cb8f39af48d8854sentry_flutter: 27892878729f42701297c628eb90e7c6529f3684share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58adiff --git a/mobile/apps/auth/ios/Runner/Runner.entitlements b/mobile/apps/auth/ios/Runner/Runner.entitlementsindex 0a7198161c..4ea99d80fc 100644--- a/mobile/apps/auth/ios/Runner/Runner.entitlements+++ b/mobile/apps/auth/ios/Runner/Runner.entitlements@@ -9,5 +9,9 @@<string>webcredentials:web.ente.io</string><string>webcredentials:auth.ente.io</string></array>+ <key>com.apple.developer.icloud-services</key>+ <array>+ <string>CloudDocuments</string>+ </array></dict></plist>diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dartindex 02f2fab6fe..42c1c3c143 100644--- a/mobile/apps/auth/lib/services/local_backup_service.dart+++ b/mobile/apps/auth/lib/services/local_backup_service.dart@@ -3,9 +3,9 @@ import 'dart:io';import 'dart:typed_data';import 'package:ente_auth/models/export/ente.dart';+import 'package:ente_auth/services/secure_storage_service.dart';import 'package:ente_auth/store/code_store.dart';import 'package:ente_crypto_dart/ente_crypto_dart.dart';-import 'package:flutter_secure_storage/flutter_secure_storage.dart';import 'package:intl/intl.dart';import 'package:logging/logging.dart';import 'package:saf_stream/saf_stream.dart';@@ -158,8 +158,7 @@ class LocalBackupService {.listSync().where((entity) =>- entity is File &&- _isBackupFile(entity.path.split('/').last),+ entity is File && _isBackupFile(entity.path.split('/').last),).map((entity) => entity as File).toList();@@ -247,9 +246,8 @@ class LocalBackupService {}Future<String?> _readPassword() async {- const storage = FlutterSecureStorage();try {- return storage.read(key: 'autoBackupPassword');+ return SecureStorageService.instance.read('autoBackupPassword');} catch (e, s) {_logger.severe('Unable to read backup password', e, s);return null;diff --git a/mobile/apps/auth/lib/services/secure_storage_service.dart b/mobile/apps/auth/lib/services/secure_storage_service.dartnew file mode 100644index 0000000000..447bd1cad0--- /dev/null+++ b/mobile/apps/auth/lib/services/secure_storage_service.dart@@ -0,0 +1,29 @@+import 'package:flutter_secure_storage/flutter_secure_storage.dart';++/// Unified secure storage service with consistent platform configuration.+///+/// This ensures all secure storage operations use the same security settings+/// across the app, particularly for iOS Keychain accessibility.+class SecureStorageService {+ SecureStorageService._();++ static final SecureStorageService instance = SecureStorageService._();++ final FlutterSecureStorage _storage = const FlutterSecureStorage(+ iOptions: IOSOptions(+ accessibility: KeychainAccessibility.first_unlock_this_device,+ ),+ aOptions: AndroidOptions(+ encryptedSharedPreferences: true,+ ),+ );++ Future<String?> read(String key) => _storage.read(key: key);++ Future<void> write(String key, String value) =>+ _storage.write(key: key, value: value);++ Future<void> delete(String key) => _storage.delete(key: key);++ Future<bool> containsKey(String key) => _storage.containsKey(key: key);+}diff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dartindex ae8687ca4b..b3787e2a27 100644--- a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart@@ -2,6 +2,7 @@ import 'dart:io';import 'package:ente_auth/l10n/l10n.dart';import 'package:ente_auth/services/local_backup_service.dart';+import 'package:ente_auth/services/secure_storage_service.dart';import 'package:ente_auth/theme/ente_theme.dart';import 'package:ente_auth/ui/components/buttons/button_widget.dart';import 'package:ente_auth/ui/components/dialog_widget.dart';@@ -9,9 +10,9 @@ import 'package:ente_auth/ui/components/models/button_type.dart';import 'package:ente_lock_screen/local_authentication_service.dart';import 'package:file_picker/file_picker.dart';import 'package:flutter/material.dart';-import 'package:flutter_secure_storage/flutter_secure_storage.dart';import 'package:path_provider/path_provider.dart';import 'package:saf_util/saf_util.dart';+import 'package:security_scoped_resource/security_scoped_resource.dart';import 'package:shared_preferences/shared_preferences.dart';typedef LocalBackupVariantBuilder = Widget Function(@@ -319,8 +320,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return false;}- const storage = FlutterSecureStorage();- await storage.write(key: _passwordKey, value: password);+ await SecureStorageService.instance.write(_passwordKey, password);return true;}@@ -333,16 +333,14 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {if (_isBackupEnabled) {return false;}- const storage = FlutterSecureStorage();- await storage.delete(key: _passwordKey);+ await SecureStorageService.instance.delete(_passwordKey);_showSnackBar(context.l10n.backupPasswordCleared);return true;}Future<String?> _readStoredPassword() async {- const storage = FlutterSecureStorage();try {- return storage.read(key: _passwordKey);+ return SecureStorageService.instance.read(_passwordKey);} catch (_) {return null;}@@ -526,11 +524,6 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {if (result?.action == ButtonAction.second) {final pickedPath = await FilePicker.platform.getDirectoryPath();if (pickedPath != null) {- // Reject iCloud Drive paths on iOS- if (_isICloudPath(pickedPath)) {- _showSnackBar(context.l10n.iCloudNotSupported);- return false;- }return _persistLocation(pickedPath,successMessage: context.l10n.initialBackupCreated,@@ -662,12 +655,6 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {String? directoryPath = await FilePicker.platform.getDirectoryPath();if (directoryPath != null) {- // On iOS, reject iCloud Drive paths as they don't work reliably- if (Platform.isIOS && _isICloudPath(directoryPath)) {- _showSnackBar(context.l10n.iCloudNotSupported);- return false;- }-final saved = await _persistLocation(directoryPath,successMessage:@@ -689,44 +676,55 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {}}- /// Check if the path is an iCloud Drive path- bool _isICloudPath(String path) {- return path.contains('/Mobile Documents/') ||- path.contains('com~apple~CloudDocs');- }-Future<bool> _persistLocation(String path, {String? successMessage,}) async {+ // On iOS, create an EnteAuthBackups subdirectory within the selected folder+ final targetPath = Platform.isIOS ? '$path/EnteAuthBackups' : path;+final prefs = await SharedPreferences.getInstance();Future<bool> savePath(String target) async {try {- await Directory(target).create(recursive: true);- await prefs.setString('autoBackupPath', target);- await prefs.remove(_treeUriKey);- await prefs.setBool(_locationConfiguredKey, true);- if (!mounted) return false;- setState(() {- _backupPath = target;- _backupTreeUri = null;- });- if (successMessage != null) {- _showSnackBar(successMessage);+ // On iOS, we need security-scoped access to the user-selected directory+ // before we can create subdirectories in it+ if (Platform.isIOS) {+ await SecurityScopedResource.instance+ .startAccessingSecurityScopedResource(Directory(path));+ }++ try {+ await Directory(target).create(recursive: true);+ await prefs.setString('autoBackupPath', target);+ await prefs.remove(_treeUriKey);+ await prefs.setBool(_locationConfiguredKey, true);+ if (!mounted) return false;+ setState(() {+ _backupPath = target;+ _backupTreeUri = null;+ });+ if (successMessage != null) {+ _showSnackBar(successMessage);+ }+ return true;+ } finally {+ if (Platform.isIOS) {+ await SecurityScopedResource.instance+ .stopAccessingSecurityScopedResource(Directory(path));+ }}- return true;} catch (_) {return false;}}- if (await savePath(path)) {+ if (await savePath(targetPath)) {return true;}if (Platform.isAndroid) {final fallbackPath = await _androidPrivateBackupPath();- if (fallbackPath != null && fallbackPath != path) {+ if (fallbackPath != null && fallbackPath != targetPath) {final savedFallback = await savePath(fallbackPath);if (savedFallback) {return true;