Skip to content

armgit / ente

Public Imported from GitHub
0

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

[auth] improve local backup password handling

Prateek Sunal4a154c5f3f2b
diff --git a/mobile/apps/auth/lib/core/configuration.dart b/mobile/apps/auth/lib/core/configuration.dart
index bc1c496f9f..c1baee13e8 100644
--- a/mobile/apps/auth/lib/core/configuration.dart
+++ b/mobile/apps/auth/lib/core/configuration.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:typed_data';
+import 'package:ente_auth/services/secure_storage_service.dart';
import 'package:ente_base/models/database.dart';
import 'package:ente_configuration/base_configuration.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
@@ -55,6 +56,7 @@ class Configuration extends BaseConfiguration {
BaseConfiguration.keyKey,
BaseConfiguration.secretKeyKey,
authSecretKeyKey,
+ SecureStorageService.autoBackupPasswordKey,
// Note: offlineAuthSecretKey is intentionally not included here
// as it persists across logouts
];
diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dart
index 42c1c3c143..3f790aa041 100644
--- a/mobile/apps/auth/lib/services/local_backup_service.dart
+++ b/mobile/apps/auth/lib/services/local_backup_service.dart
@@ -247,7 +247,8 @@ class LocalBackupService {
Future<String?> _readPassword() async {
try {
- return SecureStorageService.instance.read('autoBackupPassword');
+ return SecureStorageService.instance
+ .read(SecureStorageService.autoBackupPasswordKey);
} 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
index 447bd1cad0..282c843da6 100644
--- a/mobile/apps/auth/lib/services/secure_storage_service.dart
+++ b/mobile/apps/auth/lib/services/secure_storage_service.dart
@@ -9,6 +9,9 @@ class SecureStorageService {
static final SecureStorageService instance = SecureStorageService._();
+ /// Key for storing the local backup password
+ static const autoBackupPasswordKey = 'autoBackupPassword';
+
final FlutterSecureStorage _storage = const FlutterSecureStorage(
iOptions: IOSOptions(
accessibility: KeychainAccessibility.first_unlock_this_device,
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 b3787e2a27..bca62ee670 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
@@ -70,7 +70,6 @@ class LocalBackupExperienceController {
}
class _LocalBackupExperienceState extends State<LocalBackupExperience> {
- static const _passwordKey = 'autoBackupPassword';
static const _locationConfiguredKey = 'hasConfiguredBackupLocation';
static const _treeUriKey = 'autoBackupTreeUri';
@@ -131,7 +130,13 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
}
Future<bool> _startEnableFlow() async {
- final hasPassword = await _ensurePasswordConfigured(disableOnCancel: true);
+ // Always prompt for password when enabling backups, even if one exists.
+ // This ensures the user knows/remembers the password they'll need for restore.
+ final hasPassword = await _promptPassword(
+ forcePrompt: true,
+ disableOnCancel: true,
+ isUpdateFlow: false,
+ );
if (!hasPassword) {
return false;
}
@@ -320,7 +325,8 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
return false;
}
- await SecureStorageService.instance.write(_passwordKey, password);
+ await SecureStorageService.instance
+ .write(SecureStorageService.autoBackupPasswordKey, password);
return true;
}
@@ -333,14 +339,16 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
if (_isBackupEnabled) {
return false;
}
- await SecureStorageService.instance.delete(_passwordKey);
+ await SecureStorageService.instance
+ .delete(SecureStorageService.autoBackupPasswordKey);
_showSnackBar(context.l10n.backupPasswordCleared);
return true;
}
Future<String?> _readStoredPassword() async {
try {
- return SecureStorageService.instance.read(_passwordKey);
+ return SecureStorageService.instance
+ .read(SecureStorageService.autoBackupPasswordKey);
} catch (_) {
return null;
}
@@ -524,10 +532,16 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
if (result?.action == ButtonAction.second) {
final pickedPath = await FilePicker.platform.getDirectoryPath();
if (pickedPath != null) {
- return _persistLocation(
- pickedPath,
- successMessage: context.l10n.initialBackupCreated,
- );
+ final saved = await _persistLocation(pickedPath);
+ if (saved) {
+ final backupSuccess = await LocalBackupService.instance
+ .triggerAutomaticBackup(isManual: true);
+ if (backupSuccess) {
+ _showSnackBar(context.l10n.initialBackupCreated);
+ }
+ // If backup fails, location is still saved - UI will reflect the change
+ }
+ return saved;
}
}
return false;