Skip to content

armgit / ente

Public Imported from GitHub
0

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

[auth] consolidate backup password storage into Configuration

Prateek Sunale92e5b6cfd1e
diff --git a/mobile/apps/auth/lib/core/configuration.dart b/mobile/apps/auth/lib/core/configuration.dart
index bc1c496f9f..d06538a28a 100644
--- a/mobile/apps/auth/lib/core/configuration.dart
+++ b/mobile/apps/auth/lib/core/configuration.dart
@@ -15,6 +15,7 @@ class Configuration extends BaseConfiguration {
static const authSecretKeyKey = "auth_secret_key";
static const offlineAuthSecretKey = "offline_auth_secret_key";
static const hasOptedForOfflineModeKey = "has_opted_for_offline_mode";
+ static const autoBackupPasswordKey = "autoBackupPassword";
late SharedPreferences _preferences;
String? _authSecretKey;
@@ -55,8 +56,8 @@ class Configuration extends BaseConfiguration {
BaseConfiguration.keyKey,
BaseConfiguration.secretKeyKey,
authSecretKeyKey,
- // Note: offlineAuthSecretKey is intentionally not included here
- // as it persists across logouts
+ // Note: offlineAuthSecretKey and autoBackupPasswordKey are intentionally
+ // not included here as they persist across logouts for offline mode
];
@override
@@ -105,4 +106,17 @@ class Configuration extends BaseConfiguration {
}
await _preferences.setBool(hasOptedForOfflineModeKey, true);
}
+
+ // Backup password methods
+ Future<String?> getBackupPassword() async {
+ return _secureStorage.read(key: autoBackupPasswordKey);
+ }
+
+ Future<void> setBackupPassword(String password) async {
+ await _secureStorage.write(key: autoBackupPasswordKey, value: password);
+ }
+
+ Future<void> clearBackupPassword() async {
+ await _secureStorage.delete(key: autoBackupPasswordKey);
+ }
}
diff --git a/mobile/apps/auth/lib/main.dart b/mobile/apps/auth/lib/main.dart
index 74f799e49b..d3df28d3ff 100644
--- a/mobile/apps/auth/lib/main.dart
+++ b/mobile/apps/auth/lib/main.dart
@@ -187,7 +187,6 @@ Future<void> _init(bool bool, {String? via}) async {
hasOptedForOfflineMode: Configuration.instance.hasOptedForOfflineMode(),
);
await LocalBackupService.instance.init(
- Configuration.instance,
hasOptedForOfflineMode: Configuration.instance.hasOptedForOfflineMode(),
);
}
diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dart
index 1a780c7843..77b9b71ac0 100644
--- a/mobile/apps/auth/lib/services/local_backup_service.dart
+++ b/mobile/apps/auth/lib/services/local_backup_service.dart
@@ -3,10 +3,9 @@ import 'dart:io';
import 'dart:typed_data';
import 'package:dir_utils/dir_utils.dart';
+import 'package:ente_auth/core/configuration.dart';
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_configuration/base_configuration.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
import 'package:ente_events/event_bus.dart';
import 'package:ente_events/models/signed_out_event.dart';
@@ -24,11 +23,8 @@ class LocalBackupService {
static const _lastBackupDayKey = 'lastBackupDay';
static const _iosBookmarkKey = 'autoBackupIosBookmark';
- Future<void> init(
- BaseConfiguration config, {
- bool hasOptedForOfflineMode = false,
- }) async {
- await _clearBackupPasswordIfFreshInstall(config, hasOptedForOfflineMode);
+ Future<void> init({bool hasOptedForOfflineMode = false}) async {
+ await _clearBackupPasswordIfFreshInstall(hasOptedForOfflineMode);
Bus.instance.on<SignedOutEvent>().listen((event) {
_clearBackupPassword();
@@ -38,19 +34,15 @@ class LocalBackupService {
/// Clear backup password on fresh install (like lock screen does).
/// Only clears if not logged in and not in offline mode.
Future<void> _clearBackupPasswordIfFreshInstall(
- BaseConfiguration config,
bool hasOptedForOfflineMode,
) async {
- if ((Platform.isIOS || Platform.isMacOS) &&
- !config.isLoggedIn() &&
- !hasOptedForOfflineMode) {
+ if (!Configuration.instance.isLoggedIn() && !hasOptedForOfflineMode) {
await _clearBackupPassword();
}
}
Future<void> _clearBackupPassword() async {
- await SecureStorageService.instance
- .delete(AuthSecureStorageKeys.autoBackupPasswordKey);
+ await Configuration.instance.clearBackupPassword();
}
Future<bool> triggerAutomaticBackup({bool isManual = false}) async {
@@ -306,8 +298,7 @@ class LocalBackupService {
Future<String?> _readPassword() async {
try {
- return SecureStorageService.instance
- .read(AuthSecureStorageKeys.autoBackupPasswordKey);
+ return Configuration.instance.getBackupPassword();
} 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.dart
deleted file mode 100644
index c3de3a22e2..0000000000
--- a/mobile/apps/auth/lib/services/secure_storage_service.dart
+++ /dev/null
@@ -1,10 +0,0 @@
-// Re-export the common SecureStorageService from ente_configuration package
-export 'package:ente_configuration/secure_storage_service.dart';
-
-/// Auth app-specific secure storage keys
-class AuthSecureStorageKeys {
- AuthSecureStorageKeys._();
-
- /// Key for storing the local backup password
- static const autoBackupPasswordKey = 'autoBackupPassword';
-}
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.dart
index 622c057128..91fad1616b 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
@@ -1,9 +1,9 @@
import 'dart:io';
import 'package:dir_utils/dir_utils.dart';
+import 'package:ente_auth/core/configuration.dart';
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/services/security_bookmark_service.dart';
import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
@@ -367,8 +367,7 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
return false;
}
- await SecureStorageService.instance
- .write(AuthSecureStorageKeys.autoBackupPasswordKey, password);
+ await Configuration.instance.setBackupPassword(password);
return true;
}
@@ -381,16 +380,14 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
if (_isBackupEnabled) {
return false;
}
- await SecureStorageService.instance
- .delete(AuthSecureStorageKeys.autoBackupPasswordKey);
+ await Configuration.instance.clearBackupPassword();
_showSnackBar(context.l10n.backupPasswordCleared);
return true;
}
Future<String?> _readStoredPassword() async {
try {
- return SecureStorageService.instance
- .read(AuthSecureStorageKeys.autoBackupPasswordKey);
+ return Configuration.instance.getBackupPassword();
} catch (e) {
_logger.severe('Failed to read backup password: $e');
return null;
diff --git a/mobile/packages/configuration/lib/secure_storage_service.dart b/mobile/packages/configuration/lib/secure_storage_service.dart
deleted file mode 100644
index 5bbe51b7be..0000000000
--- a/mobile/packages/configuration/lib/secure_storage_service.dart
+++ /dev/null
@@ -1,26 +0,0 @@
-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,
- ),
- );
-
- 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);
-}