Skip to content

armgit / ente

Public Imported from GitHub
0

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

Common config

vishnukvmd134314c28534
diff --git a/mobile/apps/auth/docs/vscode/launch.json b/mobile/apps/auth/docs/vscode/launch.json
index cf6e037e34..1430e5bd9d 100644
--- a/mobile/apps/auth/docs/vscode/launch.json
+++ b/mobile/apps/auth/docs/vscode/launch.json
@@ -6,14 +6,14 @@
"request": "launch",
"type": "dart",
"flutterMode": "debug",
- "program": "auth/lib/main.dart",
+ "program": "mobile/apps/auth/lib/main.dart",
"args": ["--dart-define", "endpoint=http://localhost:8080"]
},
{
"name": "Auth Android Dev",
"request": "launch",
"type": "dart",
- "program": "auth/lib/main.dart",
+ "program": "mobile/apps/auth/lib/main.dart",
"args": [
"--dart-define",
"endpoint=http://192.168.1.3:8080",
@@ -25,21 +25,21 @@
"name": "Auth iOS Dev",
"request": "launch",
"type": "dart",
- "program": "auth/lib/main.dart",
+ "program": "mobile/apps/auth/lib/main.dart",
"args": ["--dart-define", "endpoint=http://192.168.1.30:8080"]
},
{
"name": "Auth iOS Prod",
"request": "launch",
"type": "dart",
- "program": "auth/lib/main.dart",
+ "program": "mobile/apps/auth/lib/main.dart",
"args": ["--target", "lib/main.dart"]
},
{
"name": "Auth Android Prod",
"request": "launch",
"type": "dart",
- "program": "auth/lib/main.dart",
+ "program": "mobile/apps/auth/lib/main.dart",
"args": ["--target", "lib/main.dart", "--flavor", "independent"]
}
]
diff --git a/mobile/apps/auth/ios/Podfile.lock b/mobile/apps/auth/ios/Podfile.lock
index 6a2db70ea9..688ae6f430 100644
--- a/mobile/apps/auth/ios/Podfile.lock
+++ b/mobile/apps/auth/ios/Podfile.lock
@@ -3,7 +3,6 @@ PODS:
- Flutter
- connectivity_plus (0.0.1):
- Flutter
- - FlutterMacOS
- cupertino_http (0.0.1):
- Flutter
- FlutterMacOS
@@ -61,13 +60,12 @@ PODS:
- Flutter
- flutter_local_notifications (0.0.1):
- Flutter
- - flutter_native_splash (0.0.1):
+ - flutter_native_splash (2.4.3):
- Flutter
- flutter_secure_storage (6.0.0):
- Flutter
- fluttertoast (0.0.2):
- Flutter
- - Toast
- local_auth_darwin (0.0.1):
- Flutter
- FlutterMacOS
@@ -87,9 +85,9 @@ PODS:
- qr_code_scanner (0.2.0):
- Flutter
- MTBBarcodeScanner
- - SDWebImage (5.21.0):
- - SDWebImage/Core (= 5.21.0)
- - SDWebImage/Core (5.21.0)
+ - SDWebImage (5.21.1):
+ - SDWebImage/Core (= 5.21.1)
+ - SDWebImage/Core (5.21.1)
- Sentry/HybridSDK (8.46.0)
- sentry_flutter (8.14.2):
- Flutter
@@ -102,35 +100,38 @@ PODS:
- FlutterMacOS
- sodium_libs (2.2.1):
- Flutter
- - sqflite (0.0.3):
+ - sqflite_darwin (0.0.4):
- Flutter
- FlutterMacOS
- - "sqlite3 (3.46.1+1)":
- - "sqlite3/common (= 3.46.1+1)"
- - "sqlite3/common (3.46.1+1)"
- - "sqlite3/dbstatvtab (3.46.1+1)":
+ - sqlite3 (3.50.2):
+ - sqlite3/common (= 3.50.2)
+ - sqlite3/common (3.50.2)
+ - sqlite3/dbstatvtab (3.50.2):
+ - sqlite3/common
+ - sqlite3/fts5 (3.50.2):
- sqlite3/common
- - "sqlite3/fts5 (3.46.1+1)":
+ - sqlite3/math (3.50.2):
- sqlite3/common
- - "sqlite3/perf-threadsafe (3.46.1+1)":
+ - sqlite3/perf-threadsafe (3.50.2):
- sqlite3/common
- - "sqlite3/rtree (3.46.1+1)":
+ - sqlite3/rtree (3.50.2):
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- - "sqlite3 (~> 3.46.0+1)"
+ - FlutterMacOS
+ - sqlite3 (~> 3.50.1)
- sqlite3/dbstatvtab
- sqlite3/fts5
+ - sqlite3/math
- sqlite3/perf-threadsafe
- sqlite3/rtree
- SwiftyGif (5.4.5)
- - Toast (4.1.1)
- url_launcher_ios (0.0.1):
- Flutter
DEPENDENCIES:
- app_links (from `.symlinks/plugins/app_links/ios`)
- - connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
+ - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- cupertino_http (from `.symlinks/plugins/cupertino_http/darwin`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
@@ -155,8 +156,8 @@ DEPENDENCIES:
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sodium_libs (from `.symlinks/plugins/sodium_libs/ios`)
- - sqflite (from `.symlinks/plugins/sqflite/darwin`)
- - sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`)
+ - sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
+ - sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
SPEC REPOS:
@@ -169,13 +170,12 @@ SPEC REPOS:
- Sentry
- sqlite3
- SwiftyGif
- - Toast
EXTERNAL SOURCES:
app_links:
:path: ".symlinks/plugins/app_links/ios"
connectivity_plus:
- :path: ".symlinks/plugins/connectivity_plus/darwin"
+ :path: ".symlinks/plugins/connectivity_plus/ios"
cupertino_http:
:path: ".symlinks/plugins/cupertino_http/darwin"
device_info_plus:
@@ -224,51 +224,50 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
sodium_libs:
:path: ".symlinks/plugins/sodium_libs/ios"
- sqflite:
- :path: ".symlinks/plugins/sqflite/darwin"
+ sqflite_darwin:
+ :path: ".symlinks/plugins/sqflite_darwin/darwin"
sqlite3_flutter_libs:
- :path: ".symlinks/plugins/sqlite3_flutter_libs/ios"
+ :path: ".symlinks/plugins/sqlite3_flutter_libs/darwin"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
SPEC CHECKSUMS:
- app_links: e7a6750a915a9e161c58d91bc610e8cd1d4d0ad0
- connectivity_plus: ddd7f30999e1faaef5967c23d5b6d503d10434db
+ app_links: f3e17e4ee5e357b39d8b95290a9b2c299fca71c6
+ connectivity_plus: 2a701ffec2c0ae28a48cf7540e279787e77c447d
cupertino_http: 947a233f40cfea55167a49f2facc18434ea117ba
device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
- file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655
+ file_picker: b159e0c068aef54932bb15dc9fd1571818edaf49
file_saver: 503e386464dbe118f630e17b4c2e1190fa0cf808
fk_user_agent: 1f47ec39291e8372b1d692b50084b0d54103c545
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
- flutter_email_sender: 10a22605f92809a11ef52b2f412db806c6082d40
+ flutter_email_sender: e03bdda7637bcd3539bfe718fddd980e9508efaa
flutter_inappwebview_ios: 6f63631e2c62a7c350263b13fa5427aedefe81d4
flutter_local_authentication: 1172a4dd88f6306dadce067454e2c4caf07977bb
- flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086
- flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778
+ flutter_local_notifications: df98d66e515e1ca797af436137b4459b160ad8c9
+ flutter_native_splash: df59bb2e1421aa0282cb2e95618af4dcb0c56c29
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
- fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c
- local_auth_darwin: 66e40372f1c29f383a314c738c7446e2f7fdadc3
+ fluttertoast: 21eecd6935e7064cc1fcb733a4c5a428f3f24f0f
+ local_auth_darwin: fa4b06454df7df8e97c18d7ee55151c57e7af0de
move_to_background: 39a5b79b26d577b0372cbe8a8c55e7aa9fcd3a2d
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
objective_c: 77e887b5ba1827970907e10e832eec1683f3431d
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
- package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
+ package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
privacy_screen: 1a131c052ceb3c3659934b003b0d397c2381a24e
qr_code_scanner: bb67d64904c3b9658ada8c402e8b4d406d5d796e
- SDWebImage: f84b0feeb08d2d11e6a9b843cb06d75ebf5b8868
+ SDWebImage: f29024626962457f3470184232766516dee8dfea
Sentry: da60d980b197a46db0b35ea12cb8f39af48d8854
sentry_flutter: 2df8b0aab7e4aba81261c230cbea31c82a62dd1b
- share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad
+ share_plus: 8b6f8b3447e494cca5317c8c3073de39b3600d1f
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sodium_libs: 1faae17af662384acbd13e41867a0008cd2e2318
- sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
- sqlite3: 0bb0e6389d824e40296f531b858a2a0b71c0d2fb
- sqlite3_flutter_libs: c00457ebd31e59fa6bb830380ddba24d44fbcd3b
+ sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d
+ sqlite3: 3e82a2daae39ba3b41ae6ee84a130494585460fc
+ sqlite3_flutter_libs: 2c48c4ee7217fd653251975e43412250d5bcbbe2
SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4
- Toast: 1f5ea13423a1e6674c4abdac5be53587ae481c4e
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
PODFILE CHECKSUM: 78f002751f1a8f65042b8da97902ba4124271c5a
diff --git a/mobile/apps/auth/lib/app/view/app.dart b/mobile/apps/auth/lib/app/view/app.dart
index b6ff65001b..aee7b610b5 100644
--- a/mobile/apps/auth/lib/app/view/app.dart
+++ b/mobile/apps/auth/lib/app/view/app.dart
@@ -3,10 +3,7 @@ import 'dart:io';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:ente_auth/core/configuration.dart';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/ente_theme_data.dart';
-import 'package:ente_auth/events/signed_in_event.dart';
-import 'package:ente_auth/events/signed_out_event.dart';
import "package:ente_auth/l10n/l10n.dart";
import 'package:ente_auth/locale.dart';
import "package:ente_auth/onboarding/view/onboarding_page.dart";
@@ -16,6 +13,9 @@ import 'package:ente_auth/services/user_service.dart';
import 'package:ente_auth/services/window_listener_service.dart';
import 'package:ente_auth/ui/home_page.dart';
import 'package:ente_auth/ui/settings/app_update_dialog.dart';
+import 'package:ente_events/event_bus.dart';
+import 'package:ente_events/models/signed_in_event.dart';
+import 'package:ente_events/models/signed_out_event.dart';
import 'package:flutter/foundation.dart';
import "package:flutter/material.dart";
import 'package:flutter_localizations/flutter_localizations.dart';
diff --git a/mobile/apps/auth/lib/core/configuration.dart b/mobile/apps/auth/lib/core/configuration.dart
index 7ba6fa4922..79299ed3c6 100644
--- a/mobile/apps/auth/lib/core/configuration.dart
+++ b/mobile/apps/auth/lib/core/configuration.dart
@@ -1,95 +1,36 @@
import 'dart:async';
-import 'dart:convert';
-import 'dart:io' as io;
import 'dart:typed_data';
-import 'package:bip39/bip39.dart' as bip39;
-import 'package:ente_auth/core/constants.dart';
-import 'package:ente_auth/core/event_bus.dart';
-import 'package:ente_auth/events/endpoint_updated_event.dart';
-import 'package:ente_auth/events/signed_in_event.dart';
-import 'package:ente_auth/events/signed_out_event.dart';
-import 'package:ente_auth/models/key_attributes.dart';
-import 'package:ente_auth/models/key_gen_result.dart';
-import 'package:ente_auth/models/private_key_attributes.dart';
-import 'package:ente_auth/store/authenticator_db.dart';
-import 'package:ente_auth/utils/directory_utils.dart';
+import 'package:ente_base/models/database.dart';
+import 'package:ente_configuration/base_configuration.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
-import 'package:logging/logging.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
-import 'package:tuple/tuple.dart';
-class Configuration {
+class Configuration extends BaseConfiguration {
Configuration._privateConstructor();
static final Configuration instance = Configuration._privateConstructor();
- static const endpoint = String.fromEnvironment(
- "endpoint",
- defaultValue: kDefaultProductionEndpoint,
- );
- static const emailKey = "email";
- static const keyAttributesKey = "key_attributes";
-
- static const lastTempFolderClearTimeKey = "last_temp_folder_clear_time";
- static const keyKey = "key";
- static const secretKeyKey = "secret_key";
static const authSecretKeyKey = "auth_secret_key";
static const offlineAuthSecretKey = "offline_auth_secret_key";
- static const tokenKey = "token";
- static const encryptedTokenKey = "encrypted_token";
- static const userIDKey = "user_id";
- static const hasMigratedSecureStorageKey = "has_migrated_secure_storage";
static const hasOptedForOfflineModeKey = "has_opted_for_offline_mode";
- static const endPointKey = "endpoint";
- final List<String> onlineSecureKeys = [
- keyKey,
- secretKeyKey,
- authSecretKeyKey,
- ];
-
- final kTempFolderDeletionTimeBuffer = const Duration(days: 1).inMicroseconds;
- static final _logger = Logger("Configuration");
-
- String? _cachedToken;
late SharedPreferences _preferences;
- String? _key;
- String? _secretKey;
String? _authSecretKey;
String? _offlineAuthKey;
late FlutterSecureStorage _secureStorage;
- late String _tempDirectory;
-
- String? _volatilePassword;
- Future<void> init() async {
+ @override
+ Future<void> init(List<EnteBaseDatabase> dbs) async {
+ await super.init(dbs);
_preferences = await SharedPreferences.getInstance();
- sqfliteFfiInit();
_secureStorage = const FlutterSecureStorage(
iOptions: IOSOptions(
accessibility: KeychainAccessibility.first_unlock_this_device,
),
);
- _tempDirectory = (await DirectoryUtils.getDirectoryForInit()).path;
- final tempDirectory = io.Directory(_tempDirectory);
- try {
- final currentTime = DateTime.now().microsecondsSinceEpoch;
- if (tempDirectory.existsSync() &&
- (_preferences.getInt(lastTempFolderClearTimeKey) ?? 0) <
- (currentTime - kTempFolderDeletionTimeBuffer)) {
- await tempDirectory.delete(recursive: true);
- await _preferences.setInt(lastTempFolderClearTimeKey, currentTime);
- _logger.info("Cleared temp folder");
- } else {
- _logger.info("Skipping temp folder clear");
- }
- } catch (e) {
- _logger.warning(e);
- }
- tempDirectory.createSync(recursive: true);
- await _initOnlineAccount();
+ sqfliteFfiInit();
await _initOfflineAccount();
}
@@ -99,303 +40,10 @@ class Configuration {
);
}
- Future<void> _initOnlineAccount() async {
- if (!_preferences.containsKey(tokenKey)) {
- for (final key in onlineSecureKeys) {
- unawaited(
- _secureStorage.delete(
- key: key,
- ),
- );
- }
- } else {
- _key = await _secureStorage.read(
- key: keyKey,
- );
- _secretKey = await _secureStorage.read(
- key: secretKeyKey,
- );
- _authSecretKey = await _secureStorage.read(
- key: authSecretKeyKey,
- );
- if (_key == null) {
- await logout(autoLogout: true);
- }
- }
- }
-
+ @override
Future<void> logout({bool autoLogout = false}) async {
- await _preferences.clear();
- for (String key in onlineSecureKeys) {
- await _secureStorage.delete(
- key: key,
- );
- }
- await AuthenticatorDB.instance.clearTable();
- _key = null;
- _cachedToken = null;
- _secretKey = null;
_authSecretKey = null;
- Bus.instance.fire(SignedOutEvent());
- }
-
- Future<KeyGenResult> generateKey(String password) async {
- // Create a master key
- final masterKey = CryptoUtil.generateKey();
-
- // Create a recovery key
- final recoveryKey = CryptoUtil.generateKey();
-
- // Encrypt master key and recovery key with each other
- final encryptedMasterKey = CryptoUtil.encryptSync(masterKey, recoveryKey);
- final encryptedRecoveryKey = CryptoUtil.encryptSync(recoveryKey, masterKey);
-
- // Derive a key from the password that will be used to encrypt and
- // decrypt the master key
- final kekSalt = CryptoUtil.getSaltToDeriveKey();
- final derivedKeyResult = await CryptoUtil.deriveSensitiveKey(
- utf8.encode(password),
- kekSalt,
- );
- final loginKey = await CryptoUtil.deriveLoginKey(derivedKeyResult.key);
-
- // Encrypt the key with this derived key
- final encryptedKeyData =
- CryptoUtil.encryptSync(masterKey, derivedKeyResult.key);
-
- // Generate a public-private keypair and encrypt the latter
- final keyPair = CryptoUtil.generateKeyPair();
- final encryptedSecretKeyData =
- CryptoUtil.encryptSync(keyPair.secretKey.extractBytes(), masterKey);
-
- final attributes = KeyAttributes(
- CryptoUtil.bin2base64(kekSalt),
- CryptoUtil.bin2base64(encryptedKeyData.encryptedData!),
- CryptoUtil.bin2base64(encryptedKeyData.nonce!),
- CryptoUtil.bin2base64(keyPair.publicKey),
- CryptoUtil.bin2base64(encryptedSecretKeyData.encryptedData!),
- CryptoUtil.bin2base64(encryptedSecretKeyData.nonce!),
- derivedKeyResult.memLimit,
- derivedKeyResult.opsLimit,
- CryptoUtil.bin2base64(encryptedMasterKey.encryptedData!),
- CryptoUtil.bin2base64(encryptedMasterKey.nonce!),
- CryptoUtil.bin2base64(encryptedRecoveryKey.encryptedData!),
- CryptoUtil.bin2base64(encryptedRecoveryKey.nonce!),
- );
- final privateAttributes = PrivateKeyAttributes(
- CryptoUtil.bin2base64(masterKey),
- CryptoUtil.bin2hex(recoveryKey),
- CryptoUtil.bin2base64(keyPair.secretKey.extractBytes()),
- );
- return KeyGenResult(attributes, privateAttributes, loginKey);
- }
-
- Future<Tuple2<KeyAttributes, Uint8List>> getAttributesForNewPassword(
- String password,
- ) async {
- // Get master key
- final masterKey = getKey();
-
- // Derive a key from the password that will be used to encrypt and
- // decrypt the master key
- final kekSalt = CryptoUtil.getSaltToDeriveKey();
- final derivedKeyResult = await CryptoUtil.deriveSensitiveKey(
- utf8.encode(password),
- kekSalt,
- );
- final loginKey = await CryptoUtil.deriveLoginKey(derivedKeyResult.key);
-
- // Encrypt the key with this derived key
- final encryptedKeyData =
- CryptoUtil.encryptSync(masterKey!, derivedKeyResult.key);
-
- final existingAttributes = getKeyAttributes();
-
- final updatedAttributes = existingAttributes!.copyWith(
- kekSalt: CryptoUtil.bin2base64(kekSalt),
- encryptedKey: CryptoUtil.bin2base64(encryptedKeyData.encryptedData!),
- keyDecryptionNonce: CryptoUtil.bin2base64(encryptedKeyData.nonce!),
- memLimit: derivedKeyResult.memLimit,
- opsLimit: derivedKeyResult.opsLimit,
- );
- return Tuple2(updatedAttributes, loginKey);
- }
-
- // decryptSecretsAndGetLoginKey decrypts the master key and recovery key
- // with the given password and save them in local secure storage.
- // This method also returns the keyEncKey that can be used for performing
- // SRP setup for existing users.
- Future<Uint8List> decryptSecretsAndGetKeyEncKey(
- String password,
- KeyAttributes attributes, {
- Uint8List? keyEncryptionKey,
- }) async {
- _logger.info('Start decryptAndSaveSecrets');
- keyEncryptionKey ??= await CryptoUtil.deriveKey(
- utf8.encode(password),
- CryptoUtil.base642bin(attributes.kekSalt),
- attributes.memLimit,
- attributes.opsLimit,
- );
-
- _logger.info('user-key done');
- Uint8List key;
- try {
- key = CryptoUtil.decryptSync(
- CryptoUtil.base642bin(attributes.encryptedKey),
- keyEncryptionKey,
- CryptoUtil.base642bin(attributes.keyDecryptionNonce),
- );
- } catch (e) {
- _logger.severe('master-key failed, incorrect password?', e);
- throw Exception("Incorrect password");
- }
- _logger.info("master-key done");
- await setKey(CryptoUtil.bin2base64(key));
- final secretKey = CryptoUtil.decryptSync(
- CryptoUtil.base642bin(attributes.encryptedSecretKey),
- key,
- CryptoUtil.base642bin(attributes.secretKeyDecryptionNonce),
- );
- _logger.info("secret-key done");
- await setSecretKey(CryptoUtil.bin2base64(secretKey));
- final token = CryptoUtil.openSealSync(
- CryptoUtil.base642bin(getEncryptedToken()!),
- CryptoUtil.base642bin(attributes.publicKey),
- secretKey,
- );
- _logger.info('appToken done');
- await setToken(
- CryptoUtil.bin2base64(token, urlSafe: true),
- );
- return keyEncryptionKey;
- }
-
- Future<void> recover(String recoveryKey) async {
- // check if user has entered mnemonic code
- if (recoveryKey.contains(' ')) {
- final split = recoveryKey.split(' ');
- if (split.length != mnemonicKeyWordCount) {
- String wordThatIsFollowedByEmptySpaceInSplit = '';
- for (int i = 0; i < split.length; i++) {
- String word = split[i];
- if (word.isEmpty) {
- wordThatIsFollowedByEmptySpaceInSplit =
- '\n\nExtra space after word at position $i';
- break;
- }
- }
- throw AssertionError(
- '\nRecovery code should have $mnemonicKeyWordCount words, '
- 'found ${split.length} words instead.$wordThatIsFollowedByEmptySpaceInSplit',
- );
- }
- recoveryKey = bip39.mnemonicToEntropy(recoveryKey);
- }
- final attributes = getKeyAttributes();
- Uint8List masterKey;
- try {
- masterKey = await CryptoUtil.decrypt(
- CryptoUtil.base642bin(attributes!.masterKeyEncryptedWithRecoveryKey),
- CryptoUtil.hex2bin(recoveryKey),
- CryptoUtil.base642bin(attributes.masterKeyDecryptionNonce),
- );
- } catch (e) {
- _logger.severe(e);
- rethrow;
- }
- await setKey(CryptoUtil.bin2base64(masterKey));
- final secretKey = CryptoUtil.decryptSync(
- CryptoUtil.base642bin(attributes.encryptedSecretKey),
- masterKey,
- CryptoUtil.base642bin(attributes.secretKeyDecryptionNonce),
- );
- await setSecretKey(CryptoUtil.bin2base64(secretKey));
- final token = CryptoUtil.openSealSync(
- CryptoUtil.base642bin(getEncryptedToken()!),
- CryptoUtil.base642bin(attributes.publicKey),
- secretKey,
- );
- await setToken(
- CryptoUtil.bin2base64(token, urlSafe: true),
- );
- }
-
- String getHttpEndpoint() {
- return _preferences.getString(endPointKey) ?? endpoint;
- }
-
- Future<void> setHttpEndpoint(String endpoint) async {
- await _preferences.setString(endPointKey, endpoint);
- Bus.instance.fire(EndpointUpdatedEvent());
- }
-
- String? getToken() {
- _cachedToken ??= _preferences.getString(tokenKey);
- return _cachedToken;
- }
-
- bool isLoggedIn() {
- return getToken() != null;
- }
-
- Future<void> setToken(String token) async {
- _cachedToken = token;
- await _preferences.setString(tokenKey, token);
- Bus.instance.fire(SignedInEvent());
- }
-
- Future<void> setEncryptedToken(String encryptedToken) async {
- await _preferences.setString(encryptedTokenKey, encryptedToken);
- }
-
- String? getEncryptedToken() {
- return _preferences.getString(encryptedTokenKey);
- }
-
- String? getEmail() {
- return _preferences.getString(emailKey);
- }
-
- Future<void> setEmail(String email) async {
- await _preferences.setString(emailKey, email);
- }
-
- int? getUserID() {
- return _preferences.getInt(userIDKey);
- }
-
- Future<void> setUserID(int userID) async {
- await _preferences.setInt(userIDKey, userID);
- }
-
- Future<void> setKeyAttributes(KeyAttributes attributes) async {
- await _preferences.setString(keyAttributesKey, attributes.toJson());
- }
-
- KeyAttributes? getKeyAttributes() {
- final jsonValue = _preferences.getString(keyAttributesKey);
- if (jsonValue == null) {
- return null;
- } else {
- return KeyAttributes.fromJson(jsonValue);
- }
- }
-
- Future<void> setKey(String key) async {
- _key = key;
- await _secureStorage.write(
- key: keyKey,
- value: key,
- );
- }
-
- Future<void> setSecretKey(String? secretKey) async {
- _secretKey = secretKey;
- await _secureStorage.write(
- key: secretKeyKey,
- value: secretKey,
- );
+ await super.logout();
}
Future<void> setAuthSecretKey(String? authSecretKey) async {
@@ -406,14 +54,6 @@ class Configuration {
);
}
- Uint8List? getKey() {
- return _key == null ? null : CryptoUtil.base642bin(_key!);
- }
-
- Uint8List? getSecretKey() {
- return _secretKey == null ? null : CryptoUtil.base642bin(_secretKey!);
- }
-
Uint8List? getAuthSecretKey() {
return _authSecretKey == null
? null
@@ -426,24 +66,6 @@ class Configuration {
: CryptoUtil.base642bin(_offlineAuthKey!);
}
- Uint8List getRecoveryKey() {
- final keyAttributes = getKeyAttributes()!;
- return CryptoUtil.decryptSync(
- CryptoUtil.base642bin(keyAttributes.recoveryKeyEncryptedWithMasterKey),
- getKey()!,
- CryptoUtil.base642bin(keyAttributes.recoveryKeyDecryptionNonce),
- );
- }
-
- // Caution: This directory is cleared on app start
- String getTempDirectory() {
- return _tempDirectory;
- }
-
- bool hasConfiguredAccount() {
- return getToken() != null && _key != null;
- }
-
bool hasOptedForOfflineMode() {
return _preferences.getBool(hasOptedForOfflineModeKey) ?? false;
}
@@ -464,16 +86,4 @@ class Configuration {
}
await _preferences.setBool(hasOptedForOfflineModeKey, true);
}
-
- void setVolatilePassword(String volatilePassword) {
- _volatilePassword = volatilePassword;
- }
-
- void resetVolatilePassword() {
- _volatilePassword = null;
- }
-
- String? getVolatilePassword() {
- return _volatilePassword;
- }
}
diff --git a/mobile/apps/auth/lib/core/event_bus.dart b/mobile/apps/auth/lib/core/event_bus.dart
deleted file mode 100644
index 162a107439..0000000000
--- a/mobile/apps/auth/lib/core/event_bus.dart
+++ /dev/null
@@ -1,5 +0,0 @@
-import 'package:event_bus/event_bus.dart';
-
-class Bus {
- static final EventBus instance = EventBus();
-}
diff --git a/mobile/apps/auth/lib/core/network.dart b/mobile/apps/auth/lib/core/network.dart
index 0f5ae3555d..9e884fa159 100644
--- a/mobile/apps/auth/lib/core/network.dart
+++ b/mobile/apps/auth/lib/core/network.dart
@@ -2,10 +2,10 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:ente_auth/core/configuration.dart';
-import 'package:ente_auth/core/event_bus.dart';
-import 'package:ente_auth/events/endpoint_updated_event.dart';
import 'package:ente_auth/utils/package_info_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
+import 'package:ente_events/event_bus.dart';
+import 'package:ente_events/models/endpoint_updated_event.dart';
import 'package:fk_user_agent/fk_user_agent.dart';
import 'package:flutter/foundation.dart';
import 'package:native_dio_adapter/native_dio_adapter.dart';
diff --git a/mobile/apps/auth/lib/events/codes_updated_event.dart b/mobile/apps/auth/lib/events/codes_updated_event.dart
index b678413e8d..2966735f73 100644
--- a/mobile/apps/auth/lib/events/codes_updated_event.dart
+++ b/mobile/apps/auth/lib/events/codes_updated_event.dart
@@ -1,3 +1,3 @@
-import 'package:ente_auth/events/event.dart';
+import 'package:ente_events/models/event.dart';
class CodesUpdatedEvent extends Event {}
diff --git a/mobile/apps/auth/lib/events/endpoint_updated_event.dart b/mobile/apps/auth/lib/events/endpoint_updated_event.dart
deleted file mode 100644
index 0a9915479a..0000000000
--- a/mobile/apps/auth/lib/events/endpoint_updated_event.dart
+++ /dev/null
@@ -1,3 +0,0 @@
-import 'package:ente_auth/events/event.dart';
-
-class EndpointUpdatedEvent extends Event {}
diff --git a/mobile/apps/auth/lib/events/event.dart b/mobile/apps/auth/lib/events/event.dart
deleted file mode 100644
index bd21892935..0000000000
--- a/mobile/apps/auth/lib/events/event.dart
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-class Event {}
diff --git a/mobile/apps/auth/lib/events/icons_changed_event.dart b/mobile/apps/auth/lib/events/icons_changed_event.dart
index 5cc3d8b419..545ce0a49d 100644
--- a/mobile/apps/auth/lib/events/icons_changed_event.dart
+++ b/mobile/apps/auth/lib/events/icons_changed_event.dart
@@ -1,3 +1,3 @@
-import 'package:ente_auth/events/event.dart';
+import 'package:ente_events/models/event.dart';
class IconsChangedEvent extends Event {}
diff --git a/mobile/apps/auth/lib/events/notification_event.dart b/mobile/apps/auth/lib/events/notification_event.dart
deleted file mode 100644
index 87fe1d9060..0000000000
--- a/mobile/apps/auth/lib/events/notification_event.dart
+++ /dev/null
@@ -1,5 +0,0 @@
-import 'package:ente_auth/events/event.dart';
-
-// NotificationEvent event is used to re-fresh the UI to show latest notification
-// (if any)
-class NotificationEvent extends Event {}
diff --git a/mobile/apps/auth/lib/events/signed_in_event.dart b/mobile/apps/auth/lib/events/signed_in_event.dart
deleted file mode 100644
index f0720fac9a..0000000000
--- a/mobile/apps/auth/lib/events/signed_in_event.dart
+++ /dev/null
@@ -1,3 +0,0 @@
-import 'package:ente_auth/events/event.dart';
-
-class SignedInEvent extends Event {}
diff --git a/mobile/apps/auth/lib/events/signed_out_event.dart b/mobile/apps/auth/lib/events/signed_out_event.dart
index abe4927706..613744d49d 100644
--- a/mobile/apps/auth/lib/events/signed_out_event.dart
+++ b/mobile/apps/auth/lib/events/signed_out_event.dart
@@ -1,3 +1 @@
-import 'package:ente_auth/events/event.dart';
-
-class SignedOutEvent extends Event {}
+// TODO Implement this library.
diff --git a/mobile/apps/auth/lib/events/trigger_logout_event.dart b/mobile/apps/auth/lib/events/trigger_logout_event.dart
index bfdc79e940..a6c9b724f5 100644
--- a/mobile/apps/auth/lib/events/trigger_logout_event.dart
+++ b/mobile/apps/auth/lib/events/trigger_logout_event.dart
@@ -1,3 +1,3 @@
-import 'package:ente_auth/events/event.dart';
+import 'package:ente_events/models/event.dart';
class TriggerLogoutEvent extends Event {}
diff --git a/mobile/apps/auth/lib/events/user_details_changed_event.dart b/mobile/apps/auth/lib/events/user_details_changed_event.dart
deleted file mode 100644
index 066999f473..0000000000
--- a/mobile/apps/auth/lib/events/user_details_changed_event.dart
+++ /dev/null
@@ -1,3 +0,0 @@
-import 'package:ente_auth/events/event.dart';
-
-class UserDetailsChangedEvent extends Event {}
diff --git a/mobile/apps/auth/lib/main.dart b/mobile/apps/auth/lib/main.dart
index 5da7d0a6f9..d67ae1463c 100644
--- a/mobile/apps/auth/lib/main.dart
+++ b/mobile/apps/auth/lib/main.dart
@@ -15,6 +15,7 @@ import 'package:ente_auth/services/preference_service.dart';
import 'package:ente_auth/services/update_service.dart';
import 'package:ente_auth/services/user_service.dart';
import 'package:ente_auth/services/window_listener_service.dart';
+import 'package:ente_auth/store/authenticator_db.dart';
import 'package:ente_auth/store/code_display_store.dart';
import 'package:ente_auth/store/code_store.dart';
import 'package:ente_auth/ui/tools/app_lock.dart';
@@ -151,7 +152,7 @@ Future<void> _init(bool bool, {String? via}) async {
await PreferenceService.instance.init();
await CodeStore.instance.init();
await CodeDisplayStore.instance.init();
- await Configuration.instance.init();
+ await Configuration.instance.init([AuthenticatorDB.instance]);
await Network.instance.init();
await UserService.instance.init();
await AuthenticatorService.instance.init();
diff --git a/mobile/apps/auth/lib/models/key_attributes.dart b/mobile/apps/auth/lib/models/key_attributes.dart
deleted file mode 100644
index 8b8ec3990f..0000000000
--- a/mobile/apps/auth/lib/models/key_attributes.dart
+++ /dev/null
@@ -1,102 +0,0 @@
-import 'dart:convert';
-
-class KeyAttributes {
- final String kekSalt;
- final String encryptedKey;
- final String keyDecryptionNonce;
- final String publicKey;
- final String encryptedSecretKey;
- final String secretKeyDecryptionNonce;
- final int memLimit;
- final int opsLimit;
- final String masterKeyEncryptedWithRecoveryKey;
- final String masterKeyDecryptionNonce;
- final String recoveryKeyEncryptedWithMasterKey;
- final String recoveryKeyDecryptionNonce;
-
- KeyAttributes(
- this.kekSalt,
- this.encryptedKey,
- this.keyDecryptionNonce,
- this.publicKey,
- this.encryptedSecretKey,
- this.secretKeyDecryptionNonce,
- this.memLimit,
- this.opsLimit,
- this.masterKeyEncryptedWithRecoveryKey,
- this.masterKeyDecryptionNonce,
- this.recoveryKeyEncryptedWithMasterKey,
- this.recoveryKeyDecryptionNonce,
- );
-
- Map<String, dynamic> toMap() {
- return {
- 'kekSalt': kekSalt,
- 'encryptedKey': encryptedKey,
- 'keyDecryptionNonce': keyDecryptionNonce,
- 'publicKey': publicKey,
- 'encryptedSecretKey': encryptedSecretKey,
- 'secretKeyDecryptionNonce': secretKeyDecryptionNonce,
- 'memLimit': memLimit,
- 'opsLimit': opsLimit,
- 'masterKeyEncryptedWithRecoveryKey': masterKeyEncryptedWithRecoveryKey,
- 'masterKeyDecryptionNonce': masterKeyDecryptionNonce,
- 'recoveryKeyEncryptedWithMasterKey': recoveryKeyEncryptedWithMasterKey,
- 'recoveryKeyDecryptionNonce': recoveryKeyDecryptionNonce,
- };
- }
-
- factory KeyAttributes.fromMap(Map<String, dynamic> map) {
- return KeyAttributes(
- map['kekSalt'],
- map['encryptedKey'],
- map['keyDecryptionNonce'],
- map['publicKey'],
- map['encryptedSecretKey'],
- map['secretKeyDecryptionNonce'],
- map['memLimit'],
- map['opsLimit'],
- map['masterKeyEncryptedWithRecoveryKey'],
- map['masterKeyDecryptionNonce'],
- map['recoveryKeyEncryptedWithMasterKey'],
- map['recoveryKeyDecryptionNonce'],
- );
- }
-
- String toJson() => json.encode(toMap());
-
- factory KeyAttributes.fromJson(String source) =>
- KeyAttributes.fromMap(json.decode(source));
-
- KeyAttributes copyWith({
- String? kekSalt,
- String? encryptedKey,
- String? keyDecryptionNonce,
- String? publicKey,
- String? encryptedSecretKey,
- String? secretKeyDecryptionNonce,
- int? memLimit,
- int? opsLimit,
- String? masterKeyEncryptedWithRecoveryKey,
- String? masterKeyDecryptionNonce,
- String? recoveryKeyEncryptedWithMasterKey,
- String? recoveryKeyDecryptionNonce,
- }) {
- return KeyAttributes(
- kekSalt ?? this.kekSalt,
- encryptedKey ?? this.encryptedKey,
- keyDecryptionNonce ?? this.keyDecryptionNonce,
- publicKey ?? this.publicKey,
- encryptedSecretKey ?? this.encryptedSecretKey,
- secretKeyDecryptionNonce ?? this.secretKeyDecryptionNonce,
- memLimit ?? this.memLimit,
- opsLimit ?? this.opsLimit,
- masterKeyEncryptedWithRecoveryKey ??
- this.masterKeyEncryptedWithRecoveryKey,
- masterKeyDecryptionNonce ?? this.masterKeyDecryptionNonce,
- recoveryKeyEncryptedWithMasterKey ??
- this.recoveryKeyEncryptedWithMasterKey,
- recoveryKeyDecryptionNonce ?? this.recoveryKeyDecryptionNonce,
- );
- }
-}
diff --git a/mobile/apps/auth/lib/models/key_gen_result.dart b/mobile/apps/auth/lib/models/key_gen_result.dart
deleted file mode 100644
index 5b581b0ab1..0000000000
--- a/mobile/apps/auth/lib/models/key_gen_result.dart
+++ /dev/null
@@ -1,12 +0,0 @@
-import 'dart:typed_data';
-
-import 'package:ente_auth/models/key_attributes.dart';
-import 'package:ente_auth/models/private_key_attributes.dart';
-
-class KeyGenResult {
- final KeyAttributes keyAttributes;
- final PrivateKeyAttributes privateKeyAttributes;
- final Uint8List loginKey;
-
- KeyGenResult(this.keyAttributes, this.privateKeyAttributes, this.loginKey);
-}
diff --git a/mobile/apps/auth/lib/models/private_key_attributes.dart b/mobile/apps/auth/lib/models/private_key_attributes.dart
deleted file mode 100644
index c92f017fc6..0000000000
--- a/mobile/apps/auth/lib/models/private_key_attributes.dart
+++ /dev/null
@@ -1,7 +0,0 @@
-class PrivateKeyAttributes {
- final String key;
- final String recoveryKey;
- final String secretKey;
-
- PrivateKeyAttributes(this.key, this.recoveryKey, this.secretKey);
-}
diff --git a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart
index ef5a297392..0ce09dd45c 100644
--- a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart
+++ b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart
@@ -3,7 +3,6 @@ import 'dart:io';
import 'package:ente_auth/app/view/app.dart';
import 'package:ente_auth/core/configuration.dart';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/ente_theme_data.dart';
import 'package:ente_auth/events/trigger_logout_event.dart';
import "package:ente_auth/l10n/l10n.dart";
@@ -24,6 +23,7 @@ import 'package:ente_auth/ui/settings/language_picker.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/navigation_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
+import 'package:ente_events/event_bus.dart';
import 'package:flutter/foundation.dart';
import "package:flutter/material.dart";
import 'package:local_auth/local_auth.dart';
diff --git a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
index 0bf16c7e62..3472426cbd 100644
--- a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
+++ b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
@@ -1,6 +1,5 @@
import 'dart:async';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/events/codes_updated_event.dart';
import "package:ente_auth/l10n/l10n.dart";
import 'package:ente_auth/models/all_icon_data.dart';
@@ -23,6 +22,7 @@ import 'package:ente_auth/ui/utils/icon_utils.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
import 'package:ente_auth/utils/totp_util.dart';
+import 'package:ente_events/event_bus.dart';
import "package:flutter/material.dart";
import 'package:logging/logging.dart';
diff --git a/mobile/apps/auth/lib/services/authenticator_service.dart b/mobile/apps/auth/lib/services/authenticator_service.dart
index 559e85f81a..77f814d828 100644
--- a/mobile/apps/auth/lib/services/authenticator_service.dart
+++ b/mobile/apps/auth/lib/services/authenticator_service.dart
@@ -4,9 +4,7 @@ import 'dart:math';
import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/core/errors.dart';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/events/codes_updated_event.dart';
-import 'package:ente_auth/events/signed_in_event.dart';
import 'package:ente_auth/events/trigger_logout_event.dart';
import 'package:ente_auth/gateway/authenticator.dart';
import 'package:ente_auth/models/authenticator/auth_entity.dart';
@@ -17,6 +15,8 @@ import 'package:ente_auth/services/preference_service.dart';
import 'package:ente_auth/store/authenticator_db.dart';
import 'package:ente_auth/store/offline_authenticator_db.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
+import 'package:ente_events/event_bus.dart';
+import 'package:ente_events/models/signed_in_event.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
import 'package:shared_preferences/shared_preferences.dart';
diff --git a/mobile/apps/auth/lib/services/preference_service.dart b/mobile/apps/auth/lib/services/preference_service.dart
index 773ee1b149..fd3b6d68c7 100644
--- a/mobile/apps/auth/lib/services/preference_service.dart
+++ b/mobile/apps/auth/lib/services/preference_service.dart
@@ -1,5 +1,5 @@
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/events/icons_changed_event.dart';
+import 'package:ente_events/event_bus.dart';
import 'package:shared_preferences/shared_preferences.dart';
enum CodeSortKey {
diff --git a/mobile/apps/auth/lib/services/user_service.dart b/mobile/apps/auth/lib/services/user_service.dart
index 0326023efa..b4dd7eb55a 100644
--- a/mobile/apps/auth/lib/services/user_service.dart
+++ b/mobile/apps/auth/lib/services/user_service.dart
@@ -7,15 +7,11 @@ import 'package:dio/dio.dart';
import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/core/constants.dart';
import 'package:ente_auth/core/errors.dart';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/core/network.dart';
-import 'package:ente_auth/events/user_details_changed_event.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/models/account/two_factor.dart';
import 'package:ente_auth/models/api/user/srp.dart';
import 'package:ente_auth/models/delete_account.dart';
-import 'package:ente_auth/models/key_attributes.dart';
-import 'package:ente_auth/models/key_gen_result.dart';
import 'package:ente_auth/models/sessions.dart';
import 'package:ente_auth/models/set_keys_request.dart';
import 'package:ente_auth/models/set_recovery_key_request.dart';
@@ -32,7 +28,11 @@ import 'package:ente_auth/ui/two_factor_authentication_page.dart';
import 'package:ente_auth/ui/two_factor_recovery_page.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
+import 'package:ente_base/models/key_attributes.dart';
+import 'package:ente_base/models/key_gen_result.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
+import 'package:ente_events/event_bus.dart';
+import 'package:ente_events/models/user_details_changed_event.dart';
import "package:flutter/foundation.dart";
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
diff --git a/mobile/apps/auth/lib/store/authenticator_db.dart b/mobile/apps/auth/lib/store/authenticator_db.dart
index cc47745d59..8e8ac11bb0 100644
--- a/mobile/apps/auth/lib/store/authenticator_db.dart
+++ b/mobile/apps/auth/lib/store/authenticator_db.dart
@@ -4,13 +4,14 @@ import 'dart:io';
import 'package:ente_auth/models/authenticator/auth_entity.dart';
import 'package:ente_auth/models/authenticator/local_auth_entity.dart';
import 'package:ente_auth/utils/directory_utils.dart';
+import 'package:ente_base/ente_base.dart';
import 'package:flutter/foundation.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
-class AuthenticatorDB {
+class AuthenticatorDB extends EnteBaseDatabase {
static const _databaseName = "ente.authenticator.db";
static const _databaseVersion = 1;
diff --git a/mobile/apps/auth/lib/store/code_store.dart b/mobile/apps/auth/lib/store/code_store.dart
index e6f984f3eb..8abb5657a4 100644
--- a/mobile/apps/auth/lib/store/code_store.dart
+++ b/mobile/apps/auth/lib/store/code_store.dart
@@ -3,12 +3,12 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:ente_auth/core/configuration.dart';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/events/codes_updated_event.dart';
import 'package:ente_auth/models/authenticator/entity_result.dart';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/services/authenticator_service.dart';
import 'package:ente_auth/store/offline_authenticator_db.dart';
+import 'package:ente_events/event_bus.dart';
import 'package:logging/logging.dart';
class CodeStore {
diff --git a/mobile/apps/auth/lib/ui/account/password_entry_page.dart b/mobile/apps/auth/lib/ui/account/password_entry_page.dart
index b7e3e14694..acaf051197 100644
--- a/mobile/apps/auth/lib/ui/account/password_entry_page.dart
+++ b/mobile/apps/auth/lib/ui/account/password_entry_page.dart
@@ -1,6 +1,5 @@
import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/l10n/l10n.dart';
-import 'package:ente_auth/models/key_gen_result.dart';
import 'package:ente_auth/services/user_service.dart';
import 'package:ente_auth/ui/account/recovery_key_page.dart';
import 'package:ente_auth/ui/common/dynamic_fab.dart';
@@ -451,7 +450,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
if (usingVolatilePassword) {
_logger.info('Using volatile password');
}
- final KeyGenResult result =
+ final result =
await Configuration.instance.generateKey(password);
Configuration.instance.resetVolatilePassword();
await dialog.hide();
diff --git a/mobile/apps/auth/lib/ui/home/coach_mark_widget.dart b/mobile/apps/auth/lib/ui/home/coach_mark_widget.dart
index 52d97bf26b..9583db2757 100644
--- a/mobile/apps/auth/lib/ui/home/coach_mark_widget.dart
+++ b/mobile/apps/auth/lib/ui/home/coach_mark_widget.dart
@@ -1,10 +1,10 @@
import 'dart:ui';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/events/codes_updated_event.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/services/preference_service.dart';
import 'package:ente_auth/utils/platform_util.dart';
+import 'package:ente_events/event_bus.dart';
import 'package:flutter/material.dart';
class CoachMarkWidget extends StatelessWidget {
diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dart
index 3a3d650259..e218e4fbda 100644
--- a/mobile/apps/auth/lib/ui/home_page.dart
+++ b/mobile/apps/auth/lib/ui/home_page.dart
@@ -4,7 +4,6 @@ import 'dart:io';
import 'package:app_links/app_links.dart';
import 'package:collection/collection.dart';
import 'package:ente_auth/core/configuration.dart';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/ente_theme_data.dart';
import 'package:ente_auth/events/codes_updated_event.dart';
import 'package:ente_auth/events/icons_changed_event.dart';
@@ -39,6 +38,7 @@ import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/lock_screen_settings.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_auth/utils/totp_util.dart';
+import 'package:ente_events/event_bus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
diff --git a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart b/mobile/apps/auth/lib/ui/settings/general_section_widget.dart
index aadb974b24..8475f45c3a 100644
--- a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart
+++ b/mobile/apps/auth/lib/ui/settings/general_section_widget.dart
@@ -1,7 +1,6 @@
import 'dart:io';
import 'package:ente_auth/app/view/app.dart';
-import 'package:ente_auth/core/event_bus.dart';
import 'package:ente_auth/events/icons_changed_event.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/locale.dart';
@@ -15,6 +14,7 @@ import 'package:ente_auth/ui/settings/common_settings.dart';
import 'package:ente_auth/ui/settings/language_picker.dart';
import 'package:ente_auth/utils/navigation_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
+import 'package:ente_events/event_bus.dart';
import 'package:ente_logging/logging.dart';
import 'package:flutter/material.dart';
diff --git a/mobile/apps/auth/lib/utils/lock_screen_settings.dart b/mobile/apps/auth/lib/utils/lock_screen_settings.dart
index 247f7ae4b2..4f2f81b11d 100644
--- a/mobile/apps/auth/lib/utils/lock_screen_settings.dart
+++ b/mobile/apps/auth/lib/utils/lock_screen_settings.dart
@@ -3,10 +3,10 @@ import "dart:io";
import "dart:typed_data";
import "package:ente_auth/core/configuration.dart";
-import "package:ente_auth/core/event_bus.dart";
-import "package:ente_auth/events/signed_out_event.dart";
import "package:ente_auth/utils/platform_util.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";
import "package:flutter/material.dart";
import "package:flutter_secure_storage/flutter_secure_storage.dart";
import "package:privacy_screen/privacy_screen.dart";
diff --git a/mobile/apps/auth/pubspec.lock b/mobile/apps/auth/pubspec.lock
index c8725a89b1..82838413d6 100644
--- a/mobile/apps/auth/pubspec.lock
+++ b/mobile/apps/auth/pubspec.lock
@@ -398,6 +398,20 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
+ ente_base:
+ dependency: "direct main"
+ description:
+ path: "../../packages/base"
+ relative: true
+ source: path
+ version: "1.0.0"
+ ente_configuration:
+ dependency: "direct main"
+ description:
+ path: "../../packages/configuration"
+ relative: true
+ source: path
+ version: "1.0.0"
ente_crypto_dart:
dependency: "direct main"
description:
@@ -407,6 +421,13 @@ packages:
url: "https://github.com/ente-io/ente_crypto_dart.git"
source: git
version: "1.0.0"
+ ente_events:
+ dependency: "direct main"
+ description:
+ path: "../../packages/events"
+ relative: true
+ source: path
+ version: "1.0.0"
ente_logging:
dependency: "direct main"
description:
diff --git a/mobile/apps/auth/pubspec.yaml b/mobile/apps/auth/pubspec.yaml
index ed015d040b..bc8695a26d 100644
--- a/mobile/apps/auth/pubspec.yaml
+++ b/mobile/apps/auth/pubspec.yaml
@@ -25,9 +25,15 @@ dependencies:
dotted_border: ^2.0.0+2
dropdown_button2: ^2.3.9
email_validator: ^3.0.0
+ ente_base:
+ path: ../../packages/base
+ ente_configuration:
+ path: ../../packages/configuration
ente_crypto_dart:
git:
url: https://github.com/ente-io/ente_crypto_dart.git
+ ente_events:
+ path: ../../packages/events
ente_logging:
path: ../../packages/logging
event_bus: ^2.0.0
diff --git a/mobile/packages/configuration/lib/base_configuration.dart b/mobile/packages/configuration/lib/base_configuration.dart
index 75acb8e687..5dfc722834 100644
--- a/mobile/packages/configuration/lib/base_configuration.dart
+++ b/mobile/packages/configuration/lib/base_configuration.dart
@@ -2,7 +2,6 @@ library configuration;
import 'dart:convert';
import 'dart:io' as io;
-import 'dart:typed_data';
import 'package:bip39/bip39.dart' as bip39;
import 'package:ente_configuration/constants.dart';
@@ -16,32 +15,26 @@ import 'package:ente_events/models/endpoint_updated_event.dart';
import 'package:ente_events/models/signed_in_event.dart';
import 'package:ente_events/models/signed_out_event.dart';
import 'package:ente_logging/logging.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tuple/tuple.dart';
class BaseConfiguration {
- BaseConfiguration._privateConstructor();
-
- static final BaseConfiguration instance =
- BaseConfiguration._privateConstructor();
static const endpoint = String.fromEnvironment(
"endpoint",
defaultValue: kDefaultProductionEndpoint,
);
static const emailKey = "email";
static const keyAttributesKey = "key_attributes";
-
- static const lastTempFolderClearTimeKey = "last_temp_folder_clear_time";
static const keyKey = "key";
static const secretKeyKey = "secret_key";
- static const authSecretKeyKey = "auth_secret_key";
- static const offlineAuthSecretKey = "offline_auth_secret_key";
static const tokenKey = "token";
static const encryptedTokenKey = "encrypted_token";
static const userIDKey = "user_id";
static const endPointKey = "endpoint";
+ static const lastTempFolderClearTimeKey = "last_temp_folder_clear_time";
final kTempFolderDeletionTimeBuffer = const Duration(days: 1).inMicroseconds;
@@ -69,27 +62,8 @@ class BaseConfiguration {
accessibility: KeychainAccessibility.first_unlock_this_device,
),
);
- final tempDirectory = io.Directory(_tempDocumentsDirPath);
- try {
- final currentTime = DateTime.now().microsecondsSinceEpoch;
- if (tempDirectory.existsSync() &&
- (_preferences.getInt(lastTempFolderClearTimeKey) ?? 0) <
- (currentTime - kTempFolderDeletionTimeBuffer)) {
- await tempDirectory.delete(recursive: true);
- await _preferences.setInt(lastTempFolderClearTimeKey, currentTime);
- _logger.info("Cleared temp folder");
- } else {
- _logger.info("Skipping temp folder clear");
- }
- } catch (e) {
- _logger.warning(e);
- }
- tempDirectory.createSync(recursive: true);
-
- _cacheDirectory = "$_documentsDirectory/cache/";
- if (!io.Directory(_cacheDirectory).existsSync()) {
- io.Directory(_cacheDirectory).createSync(recursive: true);
- }
+ _setupKeys();
+ _setupFolders();
}
Future<void> logout({bool autoLogout = false}) async {
@@ -404,4 +378,61 @@ class BaseConfiguration {
String? getVolatilePassword() {
return _volatilePassword;
}
+
+ Future<void> _setupKeys() async {
+ try {
+ if (!_preferences.containsKey(tokenKey)) {
+ await _secureStorage.deleteAll();
+ return;
+ }
+ _key = await _secureStorage.read(key: keyKey);
+ if (_key == null) {
+ _logger.warning("No key found in secure storage");
+ await logout(autoLogout: true);
+ }
+ _secretKey = await _secureStorage.read(key: secretKeyKey);
+ } catch (e, s) {
+ _logger.severe("Configuration init failed", e, s);
+ /*
+ Check if it's a known is related to reading secret from secure storage
+ on android https://github.com/mogol/flutter_secure_storage/issues/541
+ */
+ if (e is PlatformException) {
+ final PlatformException error = e;
+ final bool isBadPaddingError =
+ error.toString().contains('BadPaddingException') ||
+ (error.message ?? '').contains('BadPaddingException');
+ if (isBadPaddingError) {
+ await logout(autoLogout: true);
+ return;
+ }
+ } else {
+ rethrow;
+ }
+ }
+ }
+
+ Future<void> _setupFolders() async {
+ final tempDirectory = io.Directory(_tempDocumentsDirPath);
+ try {
+ final currentTime = DateTime.now().microsecondsSinceEpoch;
+ if (tempDirectory.existsSync() &&
+ (_preferences.getInt(lastTempFolderClearTimeKey) ?? 0) <
+ (currentTime - kTempFolderDeletionTimeBuffer)) {
+ await tempDirectory.delete(recursive: true);
+ await _preferences.setInt(lastTempFolderClearTimeKey, currentTime);
+ _logger.info("Cleared temp folder");
+ } else {
+ _logger.info("Skipping temp folder clear");
+ }
+ } catch (e) {
+ _logger.warning(e);
+ }
+ tempDirectory.createSync(recursive: true);
+
+ _cacheDirectory = "$_documentsDirectory/cache/";
+ if (!io.Directory(_cacheDirectory).existsSync()) {
+ io.Directory(_cacheDirectory).createSync(recursive: true);
+ }
+ }
}