From 0a1bcc863b58d229602fa8aa960f079dda8a5829 Mon Sep 17 00:00:00 2001 From: a5xwin Date: Thu, 11 Sep 2025 11:12:19 +0530 Subject: [PATCH] fixed review changes --- .../lib/services/local_backup_service.dart | 24 ++++++++++++++++++- .../data/import/encrypted_ente_import.dart | 21 +++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dart index 587ad5f1db..ab496fe172 100644 --- a/mobile/apps/auth/lib/services/local_backup_service.dart +++ b/mobile/apps/auth/lib/services/local_backup_service.dart @@ -7,6 +7,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:intl/intl.dart'; //for time based file naming import 'package:logging/logging.dart'; import 'package:shared_preferences/shared_preferences.dart'; +//we gonn change class LocalBackupService { final _logger = Logger('LocalBackupService'); @@ -40,7 +41,28 @@ class LocalBackupService { _logger.info("Change detected, triggering automatic encrypted backup..."); - final plainTextContent = await CodeStore.instance.getCodesForExport(); + + String rawContent = await CodeStore.instance.getCodesForExport(); + + List lines = rawContent.split('\n'); + List cleanedLines = []; + + for (String line in lines) { + if (line.trim().isEmpty) continue; + + String cleanUrl; + if (line.startsWith('"') && line.endsWith('"')) { + cleanUrl = jsonDecode(line); + } + + else { + cleanUrl = line; + } + + cleanedLines.add(cleanUrl); + } + + final plainTextContent = cleanedLines.join('\n'); if (plainTextContent.trim().isEmpty) { return; diff --git a/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart index ac26ecc1c7..e86e8b3521 100644 --- a/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart +++ b/mobile/apps/auth/lib/ui/settings/data/import/encrypted_ente_import.dart @@ -46,7 +46,7 @@ Future showEncryptedImportInstruction(BuildContext context) async { if (result?.action != null && result!.action != ButtonAction.cancel) { if (result.action == ButtonAction.first) { await _pickEnteJsonFile(context); - } + } else {} } } @@ -85,6 +85,7 @@ Future _decryptExportData( enteAuthExport.kdfParams.opsLimit, ); Uint8List? decryptedContent; + // Encrypt the key with this derived key try { decryptedContent = await CryptoUtil.decryptData( CryptoUtil.base642bin(enteAuthExport.encryptedData), @@ -98,6 +99,7 @@ Future _decryptExportData( } if (isPasswordIncorrect) { await progressDialog.hide(); + Future.delayed(const Duration(seconds: 0), () { _decryptExportData(context, enteAuthExport, password: password); }); @@ -107,28 +109,17 @@ Future _decryptExportData( List splitCodes = content.split("\n"); final parsedCodes = []; for (final code in splitCodes) { - if (code.trim().isEmpty) continue; try { - String otpUrl; - if (code.startsWith('"') && code.endsWith('"')) { - otpUrl = jsonDecode(code); // decode json wrapped URL - } - else { - otpUrl = code; // use raw URL directly - } - parsedCodes.add(Code.fromOTPAuthUrl(otpUrl)); - } - catch (e) { + parsedCodes.add(Code.fromOTPAuthUrl(code)); + } catch (e) { Logger('EncryptedText').severe("Could not parse code", e); } - } - + } for (final code in parsedCodes) { await CodeStore.instance.addCode(code, shouldSync: false); } unawaited(AuthenticatorService.instance.onlineSync()); importedCodeCount = parsedCodes.length; - await progressDialog.hide(); } catch (e, s) { await progressDialog.hide();