Skip to content

armgit / ente

Public Imported from GitHub
0

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

[auth] Additional import option

Neeraj Gupta431ab7fcc7b1
diff --git a/mobile/apps/auth/ios/Podfile.lock b/mobile/apps/auth/ios/Podfile.lock
index 688ae6f430..7893816108 100644
--- a/mobile/apps/auth/ios/Podfile.lock
+++ b/mobile/apps/auth/ios/Podfile.lock
@@ -126,6 +126,8 @@ PODS:
- sqlite3/perf-threadsafe
- sqlite3/rtree
- SwiftyGif (5.4.5)
+ - ua_client_hints (1.4.1):
+ - Flutter
- url_launcher_ios (0.0.1):
- Flutter
@@ -158,6 +160,7 @@ DEPENDENCIES:
- sodium_libs (from `.symlinks/plugins/sodium_libs/ios`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/darwin`)
+ - ua_client_hints (from `.symlinks/plugins/ua_client_hints/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
SPEC REPOS:
@@ -228,6 +231,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/sqflite_darwin/darwin"
sqlite3_flutter_libs:
:path: ".symlinks/plugins/sqlite3_flutter_libs/darwin"
+ ua_client_hints:
+ :path: ".symlinks/plugins/ua_client_hints/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
@@ -268,6 +273,7 @@ SPEC CHECKSUMS:
sqlite3: 3e82a2daae39ba3b41ae6ee84a130494585460fc
sqlite3_flutter_libs: 2c48c4ee7217fd653251975e43412250d5bcbbe2
SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4
+ ua_client_hints: aeabd123262c087f0ce151ef96fa3ab77bfc8b38
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
PODFILE CHECKSUM: 78f002751f1a8f65042b8da97902ba4124271c5a
diff --git a/mobile/apps/auth/lib/l10n/arb/app_en.arb b/mobile/apps/auth/lib/l10n/arb/app_en.arb
index a0a94c5045..0ac0aafbb0 100644
--- a/mobile/apps/auth/lib/l10n/arb/app_en.arb
+++ b/mobile/apps/auth/lib/l10n/arb/app_en.arb
@@ -111,6 +111,7 @@
"importAegisGuide": "Use the \"Export the vault\" option in Aegis's Settings.\n\nIf your vault is encrypted, you will need to enter vault password to decrypt the vault.",
"import2FasGuide": "Use the \"Settings->Backup -Export\" option in 2FAS.\n\nIf your backup is encrypted, you will need to enter the password to decrypt the backup",
"importLastpassGuide": "Use the \"Transfer accounts\" option within Lastpass Authenticator Settings and press \"Export accounts to file\". Import the JSON downloaded.",
+ "importProtonAuthGuide": "Use the \"Export\" option in Proton Authenticator Settings to export your codes.",
"exportCodes": "Export codes",
"importLabel": "Import",
"importInstruction": "Please select a file that contains a list of your codes in the following format",
diff --git a/mobile/apps/auth/lib/ui/settings/data/import/import_service.dart b/mobile/apps/auth/lib/ui/settings/data/import/import_service.dart
index a315c16796..ee5cd7eb68 100644
--- a/mobile/apps/auth/lib/ui/settings/data/import/import_service.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/import/import_service.dart
@@ -4,6 +4,7 @@ import 'package:ente_auth/ui/settings/data/import/encrypted_ente_import.dart';
import 'package:ente_auth/ui/settings/data/import/google_auth_import.dart';
import 'package:ente_auth/ui/settings/data/import/lastpass_import.dart';
import 'package:ente_auth/ui/settings/data/import/plain_text_import.dart';
+import 'package:ente_auth/ui/settings/data/import/proton_import.dart';
import 'package:ente_auth/ui/settings/data/import/raivo_plain_text_import.dart';
import 'package:ente_auth/ui/settings/data/import/two_fas_import.dart';
import 'package:ente_auth/ui/settings/data/import_page.dart';
@@ -43,6 +44,9 @@ class ImportService {
case ImportType.lastpass:
await showLastpassImportInstruction(context);
break;
+ case ImportType.proton:
+ await showProtonImportInstruction(context);
+ break;
}
}
}
diff --git a/mobile/apps/auth/lib/ui/settings/data/import/proton_import.dart b/mobile/apps/auth/lib/ui/settings/data/import/proton_import.dart
new file mode 100644
index 0000000000..7d0e541639
--- /dev/null
+++ b/mobile/apps/auth/lib/ui/settings/data/import/proton_import.dart
@@ -0,0 +1,171 @@
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:ente_auth/l10n/l10n.dart';
+import 'package:ente_auth/models/code.dart';
+import 'package:ente_auth/services/authenticator_service.dart';
+import 'package:ente_auth/store/code_store.dart';
+import 'package:ente_auth/ui/common/progress_dialog.dart';
+import 'package:ente_auth/ui/components/buttons/button_widget.dart';
+import 'package:ente_auth/ui/components/dialog_widget.dart';
+import 'package:ente_auth/ui/components/models/button_type.dart';
+import 'package:ente_auth/ui/settings/data/import/import_success.dart';
+import 'package:ente_auth/utils/dialog_util.dart';
+import 'package:file_picker/file_picker.dart';
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'package:logging/logging.dart';
+
+Future<void> showProtonImportInstruction(BuildContext context) async {
+ final l10n = context.l10n;
+ final result = await showDialogWidget(
+ context: context,
+ title: l10n.importFromApp("Proton Authenticator"),
+ body: l10n.importProtonAuthGuide,
+ buttons: [
+ ButtonWidget(
+ buttonType: ButtonType.primary,
+ labelText: l10n.importSelectJsonFile,
+ isInAlert: true,
+ buttonSize: ButtonSize.large,
+ buttonAction: ButtonAction.first,
+ ),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ labelText: context.l10n.cancel,
+ buttonSize: ButtonSize.large,
+ isInAlert: true,
+ buttonAction: ButtonAction.second,
+ ),
+ ],
+ );
+ if (result?.action != null && result!.action != ButtonAction.cancel) {
+ if (result.action == ButtonAction.first) {
+ await _pickProtonJsonFile(context);
+ }
+ }
+}
+
+Future<void> _pickProtonJsonFile(BuildContext context) async {
+ final l10n = context.l10n;
+ FilePickerResult? result = await FilePicker.platform
+ .pickFiles(dialogTitle: l10n.importSelectJsonFile);
+ if (result == null) {
+ return;
+ }
+ final ProgressDialog progressDialog =
+ createProgressDialog(context, l10n.pleaseWait);
+ await progressDialog.show();
+ try {
+ String path = result.files.single.path!;
+ int? count = await _processProtonExportFile(context, path, progressDialog);
+ await progressDialog.hide();
+ if (count != null) {
+ await importSuccessDialog(context, count);
+ }
+ } catch (e, s) {
+ Logger('ProtonImport')
+ .severe('exception while processing proton import', e, s);
+ await progressDialog.hide();
+ await showErrorDialog(
+ context,
+ context.l10n.sorry,
+ "${context.l10n.importFailureDescNew}\n Error: ${e.toString()}",
+ );
+ }
+}
+
+Future<int?> _processProtonExportFile(
+ BuildContext context,
+ String path,
+ final ProgressDialog dialog,
+) async {
+ File file = File(path);
+
+ final jsonString = await file.readAsString();
+ final decodedJson = jsonDecode(jsonString);
+
+ // Validate that this is a Proton export
+ if (decodedJson['version'] == null || decodedJson['entries'] == null) {
+ await dialog.hide();
+ await showErrorDialog(
+ context,
+ 'Invalid Proton export',
+ 'The selected file is not a valid Proton Authenticator export.',
+ );
+ return null;
+ }
+
+ final parsedCodes = <Code>[];
+ final entries = decodedJson['entries'] as List;
+
+ for (var entry in entries) {
+ try {
+ final content = entry['content'];
+ if (content == null) {
+ continue; // Skip entries without content
+ }
+
+ final entryType = content['entry_type'] as String?;
+ if (entryType != 'Totp' && entryType != 'Steam') {
+ // log warning
+ Logger('ProtonImport').warning('Unsupported entry type: $entryType');
+ continue; // Skip non-TOTP and non-Steam entries
+ }
+
+ Code code;
+
+ if (entryType == 'Steam') {
+ // Handle Steam entries with steam:// format
+ final steamUri = content['uri'] as String?;
+ if (steamUri == null || !steamUri.startsWith('steam://')) {
+ continue; // Skip invalid Steam URIs
+ }
+
+ final secret = steamUri.split('steam://')[1];
+ final name = content['name'] as String? ?? '';
+
+ code = Code.fromAccountAndSecret(
+ Type.steam,
+ '', // Steam doesn't typically have separate account
+ name, // Use name as issuer
+ secret,
+ null,
+ Code.steamDigits,
+ );
+ } else {
+ // Handle TOTP entries with otpauth:// format
+ final otpUri = content['uri'] as String?;
+ if (otpUri == null || !otpUri.startsWith('otpauth://')) {
+ continue; // Skip invalid OTP URIs
+ }
+ // Create code from OTP auth URL
+ code = Code.fromOTPAuthUrl(otpUri);
+ }
+
+ // Add note if present
+ final note = entry['note'] as String?;
+ if (note != null && note.isNotEmpty) {
+ code = code.copyWith(
+ display: code.display.copyWith(note: note),
+ );
+ }
+
+ parsedCodes.add(code);
+ } catch (e, s) {
+ Logger('ProtonImport').warning('Failed to parse entry', e, s);
+ // Continue processing other entries
+ }
+ }
+
+ // Add all parsed codes to the store
+ for (final code in parsedCodes) {
+ await CodeStore.instance.addCode(code, shouldSync: false);
+ }
+
+ // Trigger sync
+ unawaited(AuthenticatorService.instance.onlineSync());
+
+ return parsedCodes.length;
+}
diff --git a/mobile/apps/auth/lib/ui/settings/data/import_page.dart b/mobile/apps/auth/lib/ui/settings/data/import_page.dart
index 72ad143137..28e4d6a9c5 100644
--- a/mobile/apps/auth/lib/ui/settings/data/import_page.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/import_page.dart
@@ -17,6 +17,7 @@ enum ImportType {
twoFas,
bitwarden,
lastpass,
+ proton,
}
class ImportCodePage extends StatelessWidget {
@@ -29,6 +30,7 @@ class ImportCodePage extends StatelessWidget {
ImportType.aegis,
ImportType.bitwarden,
ImportType.googleAuthenticator,
+ ImportType.proton,
ImportType.ravio,
ImportType.lastpass,
];
@@ -51,6 +53,8 @@ class ImportCodePage extends StatelessWidget {
return 'Bitwarden';
case ImportType.lastpass:
return 'LastPass Authenticator';
+ case ImportType.proton:
+ return 'Proton Authenticator';
}
}
diff --git a/mobile/apps/auth/pubspec.lock b/mobile/apps/auth/pubspec.lock
index 7799f96b4e..e869ebebc6 100644
--- a/mobile/apps/auth/pubspec.lock
+++ b/mobile/apps/auth/pubspec.lock
@@ -540,10 +540,10 @@ packages:
dependency: "direct main"
description:
name: file_picker
- sha256: ef9908739bdd9c476353d6adff72e88fd00c625f5b959ae23f7567bd5137db0a
+ sha256: e7e16c9d15c36330b94ca0e2ad8cb61f93cd5282d0158c09805aed13b5452f22
url: "https://pub.dev"
source: hosted
- version: "10.2.0"
+ version: "10.3.2"
file_saver:
dependency: "direct main"
description:
diff --git a/mobile/apps/auth/pubspec.yaml b/mobile/apps/auth/pubspec.yaml
index 74dd6ffe01..89c6908f19 100644
--- a/mobile/apps/auth/pubspec.yaml
+++ b/mobile/apps/auth/pubspec.yaml
@@ -50,7 +50,7 @@ dependencies:
expansion_tile_card: ^3.0.0
ffi: ^2.1.0
figma_squircle: ^0.6.3
- file_picker: ^10.2.0
+ file_picker: ^10.3.2
file_saver: ^0.3.1
fixnum: ^1.1.0
fk_user_agent: # no package updates on pub.dev