Compare commits
88 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d389d3d163 | ||
|
|
60e34f780e | ||
|
|
16d57b8bad | ||
|
|
ddc14a031e | ||
|
|
bd7402fe38 | ||
|
|
ad3ae560bd | ||
|
|
1a15410f0d | ||
|
|
3d7a4b1d32 | ||
|
|
ba1c74b9b5 | ||
|
|
9d3a7efe29 | ||
|
|
95d7a9fe67 | ||
|
|
e4a549a55b | ||
|
|
9f0a53e733 | ||
|
|
c89bffb8ff | ||
|
|
7456b0a2e7 | ||
|
|
bffff57d28 | ||
|
|
442bab6bdd | ||
|
|
ef9530af24 | ||
|
|
cdb615b0ba | ||
|
|
fddf9169d3 | ||
|
|
91cd77ad8d | ||
|
|
1697547091 | ||
|
|
7fb3ab02f9 | ||
|
|
d855559bab | ||
|
|
c02a16a321 | ||
|
|
97bc2ba141 | ||
|
|
7f8673b65b | ||
|
|
a5caa06944 | ||
|
|
457c6ffd2f | ||
|
|
1d960fadce | ||
|
|
cba39f4ef5 | ||
|
|
9f270cf471 | ||
|
|
5b8ccea31a | ||
|
|
92201eb4ea | ||
|
|
9d519d90c7 | ||
|
|
4d34ab7a01 | ||
|
|
3c25216116 | ||
|
|
5d0007d749 | ||
|
|
1afd2ce27e | ||
|
|
438193ac39 | ||
|
|
286940a5d1 | ||
|
|
50ebcdd1f0 | ||
|
|
53c406f30c | ||
|
|
acbbd8d049 | ||
|
|
5c9e879628 | ||
|
|
4b633d1a02 | ||
|
|
b95ed5fbb5 | ||
|
|
ffcd4022ea | ||
|
|
aa525bfeb1 | ||
|
|
18d098b310 | ||
|
|
57930b2dd8 | ||
|
|
0d0c89900a | ||
|
|
4893753b19 | ||
|
|
a594d1c962 | ||
|
|
2e3b6b27de | ||
|
|
326653054d | ||
|
|
a7818fc6d4 | ||
|
|
5e327a7d65 | ||
|
|
9c0aea66ec | ||
|
|
523f216b61 | ||
|
|
fb0fa73c03 | ||
|
|
535109d08f | ||
|
|
a02cfef105 | ||
|
|
2ff8963c52 | ||
|
|
117d397d77 | ||
|
|
c5b3808dee | ||
|
|
7cd5b313de | ||
|
|
8cbba78bcb | ||
|
|
9d95bd16cd | ||
|
|
f9eb7c11fd | ||
|
|
e5c8e90889 | ||
|
|
a4941d9975 | ||
|
|
69f09c896c | ||
|
|
7f7954d4ea | ||
|
|
f736357b04 | ||
|
|
c413564a4b | ||
|
|
445f3f20f0 | ||
|
|
05a36b051d | ||
|
|
75843814bd | ||
|
|
d965a0239f | ||
|
|
a773f999fa | ||
|
|
3b710e9274 | ||
|
|
945d6d6728 | ||
|
|
7d8a85b861 | ||
|
|
54817cc100 | ||
|
|
34a39a2a86 | ||
|
|
52e9567a12 | ||
|
|
0a05fc917b |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Flutter CI
|
||||
name: release
|
||||
|
||||
# This workflow is triggered on pushes to the repository.
|
||||
on:
|
||||
|
||||
56
CONTRIBUTING.md
Normal file
56
CONTRIBUTING.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Contributing
|
||||
|
||||
Thank you for showing interest in contributing to ente Authenticator. There are a couple of ways to help
|
||||
out. This document contains some general guidelines for each type of
|
||||
contribution.
|
||||
|
||||
|
||||
## Translations
|
||||
[](https://crowdin.com/project/ente-authenticator-app)
|
||||
|
||||
We use [Crowdin](https://crowdin.com/project/ente-authenticator-app) to crowdsource
|
||||
translations of ente Authenticator.
|
||||
If your language is not listed for translation, feel free to [create a GitHub issue](https://github.com/ente-io/auth/issues/new?title=Request+for+New+Language+Translation&body=Language+name%3A) to have it added.
|
||||
|
||||
## Icons
|
||||
|
||||
ente Auth supports the icon pack provided by
|
||||
[simple-icons](https://github.com/simple-icons/simple-icons).
|
||||
|
||||
If you would like to add your own custom icon, please open a pull-request
|
||||
with the relevant SVG and color
|
||||
code ([example PR](https://github.com/ente-io/auth/pull/213/files)).
|
||||
|
||||
|
||||
## Development
|
||||
|
||||
If you're planning on adding a new feature or making other changes, please
|
||||
discuss it with us by creating [an
|
||||
issue](https://github.com/ente-io/auth/issues/new)
|
||||
on GitHub. Discussing your idea with us first ensures that everyone is on the
|
||||
same page before you start working on your change.
|
||||
|
||||
### 💻 Setup
|
||||
|
||||
1. [Install Flutter v3.10.6](https://flutter.dev/docs/get-started/install)
|
||||
2. Clone this repository with `git clone git@github.com:ente-io/auth.git`
|
||||
3. Pull in all submodules with `git submodule update --init --recursive`
|
||||
4. For Android, run
|
||||
```bash
|
||||
flutter run -t lib/main.dart --flavor independent
|
||||
```
|
||||
5. For iOS, run `flutter run`
|
||||
|
||||
|
||||
#### Localization
|
||||
If the feature requires adding new strings, you can do that by following these steps:
|
||||
|
||||
1. Add a new entry inside [app_en.arb](https://github.com/ente-io/auth/blob/main/lib/l10n/arb/app_en.arb) (Remember to save)
|
||||
2. In your dart file, add follwing import
|
||||
```dart
|
||||
import "package:ente_auth/l10n/l10n.dart";
|
||||
```
|
||||
3. Refer to the string using `context.l10n.<keyName>`. For example
|
||||
```dart
|
||||
context.l10n.account
|
||||
```
|
||||
57
README.md
57
README.md
@@ -1,5 +1,9 @@
|
||||
# ente Authenticator
|
||||
|
||||

|
||||
[](https://crowdin.com/project/ente-authenticator-app)
|
||||
[](https://matrix.to/#/#ente:matrix.org)
|
||||
|
||||
ente's Authenticator app helps you generate and store 2 step verification (2FA)
|
||||
tokens on your mobile devices.
|
||||
|
||||
@@ -25,22 +29,23 @@ your devices. Every new device you sign into will have access to these tokens.
|
||||
### Offline Mode
|
||||
|
||||
ente generates 2FA tokens offline, so your network connectivity will not get in
|
||||
the way of your workflow.
|
||||
the way of your workflow. If you wish to use the app without an account for e2ee
|
||||
backups, you can do that as well.
|
||||
|
||||
### Import and Export Tokens
|
||||
|
||||
You can add tokens to ente by one of the following methods:
|
||||
1. Scanning a QR code
|
||||
2. Manually entering (copy-pasting) a 2FA secret
|
||||
3. Bulk importing from a file that contains a list of codes in the following
|
||||
format:
|
||||
```
|
||||
otpauth://totp/provider.com:you@email.com?secret=YOUR_SECRET
|
||||
```
|
||||
The codes maybe separated by new lines or commas.
|
||||
3. Bulk importing from other popular 2FA apps and from a file that contains a list of codes in the following format:.
|
||||
```
|
||||
otpauth://totp/provider.com:you@email.com?secret=YOUR_SECRET
|
||||
```
|
||||
|
||||
You can also export the codes you have added to ente, to an **unencrypted** text
|
||||
file, that adheres to the above format.
|
||||
You can export the codes you have added to ente, to either an **encrypted** or
|
||||
plain text file. The encrypted backups can be accessed through the app, as well
|
||||
as a standalone CLI tool. [Read
|
||||
more](migration-guides/encrypted_export.md#how-to-use-the-exported-data).
|
||||
|
||||
|
||||
## 📲 Download
|
||||
@@ -71,16 +76,10 @@ src="https://ente.io/static/ed265c3abdcd3efa5e29f64b927bcb44/e230a/play-store-ba
|
||||
src="https://user-images.githubusercontent.com/1161789/154795157-c4468ff9-97fd-46f3-87fe-dca789d8733a.png">
|
||||
</a>
|
||||
|
||||
### Web
|
||||
### Web / Desktop
|
||||
|
||||
You can view your 2FA codes at [auth.ente.io](https://auth.ente.io). For adding or managing your secrets, please use our mobile app.
|
||||
|
||||
### Desktop
|
||||
|
||||
Support for desktop platforms (Linux, Windows and older Macs) is a [work in
|
||||
progress](https://github.com/ente-io/auth/tree/desktop).
|
||||
|
||||
Please ⭐ this repo to be notified of updates.
|
||||
|
||||
|
||||
## 🔩 Architecture
|
||||
@@ -89,7 +88,7 @@ The architecture that powers end-to-end encrypted storage and sync of your
|
||||
tokens has been documented [here](architecture/README.md).
|
||||
|
||||
|
||||
## 🧑💻 Building from source
|
||||
## 🧑💻 Build from source
|
||||
|
||||
1. [Install Flutter](https://flutter.dev/docs/get-started/install)
|
||||
2. Clone this repository with `git clone git@github.com:ente-io/auth.git`
|
||||
@@ -101,29 +100,27 @@ For maintainers, there is [additional documentation](RELEASES.md) on
|
||||
automatically publishing the main branch to App store, Play store and GitHub
|
||||
releases.
|
||||
|
||||
## 🙂 Icons
|
||||
|
||||
ente Auth supports the icon pack provided by
|
||||
[simple-icons](https://github.com/simple-icons/simple-icons).
|
||||
## 🧑🔧 Contribute
|
||||
|
||||
If you would like to add your own custom icon, please open a pull-request
|
||||
with the relevant SVG and color
|
||||
code ([example PR](https://github.com/ente-io/auth/pull/213/files)).
|
||||
Please refer to our [contribution guide](./CONTRIBUTING.md) if you wish to add
|
||||
an icon, assist with translation, or develop new features.
|
||||
|
||||
## 🙋♂️ Support
|
||||
You can also support us by giving this project a ⭐ star on GitHub or by leaving
|
||||
a review on
|
||||
[PlayStore](https://play.google.com/store/apps/details?id=io.ente.auth),
|
||||
[AppStore](https://apps.apple.com/us/app/ente-authenticator/id6444121398) or
|
||||
[AlternativeTo](https://alternativeto.net/software/ente-authenticator/).
|
||||
|
||||
|
||||
## 🙋♂️ Help
|
||||
|
||||
If you need help, please reach out to support@ente.io, and a human will get in
|
||||
touch with you.
|
||||
|
||||
If you have feature requests, please create a [GitHub issue](https://github.com/ente-io/auth/issues/).
|
||||
|
||||
If you wish to support us, please ⭐
|
||||
[star](https://github.com/ente-io/auth/stargazers) this project.
|
||||
|
||||
## 🙌 Translation
|
||||
[](https://crowdin.com/project/ente-authenticator-app)
|
||||
|
||||
If you're interested in helping out with translation, please visit our [Crowdin project](https://crowdin.com/project/ente-authenticator-app) to get started. Thank you for your support.
|
||||
|
||||
## 💜 Community
|
||||
|
||||
|
||||
@@ -24,6 +24,6 @@ subprojects {
|
||||
project.evaluationDependsOn(':app')
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
tasks.register("clean", Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
@@ -129,7 +128,8 @@ class _AppState extends State<App> {
|
||||
|
||||
Map<String, WidgetBuilder> get _getRoutes {
|
||||
return {
|
||||
"/": (context) => Configuration.instance.hasConfiguredAccount()
|
||||
"/": (context) => Configuration.instance.hasConfiguredAccount() ||
|
||||
Configuration.instance.hasOptedForOfflineMode()
|
||||
? const HomePage()
|
||||
: const OnboardingPage(),
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as io;
|
||||
import 'dart:typed_data';
|
||||
@@ -29,15 +30,23 @@ class Configuration {
|
||||
);
|
||||
static const emailKey = "email";
|
||||
static const keyAttributesKey = "key_attributes";
|
||||
static const keyKey = "key";
|
||||
|
||||
static const keyShouldShowLockScreen = "should_show_lock_screen";
|
||||
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";
|
||||
final List<String> onlineSecureKeys = [
|
||||
keyKey,
|
||||
secretKeyKey,
|
||||
authSecretKeyKey
|
||||
];
|
||||
|
||||
final kTempFolderDeletionTimeBuffer = const Duration(days: 1).inMicroseconds;
|
||||
|
||||
@@ -45,28 +54,20 @@ class Configuration {
|
||||
|
||||
String? _cachedToken;
|
||||
late String _documentsDirectory;
|
||||
String? _key;
|
||||
late SharedPreferences _preferences;
|
||||
String? _key;
|
||||
String? _secretKey;
|
||||
String? _authSecretKey;
|
||||
String? _offlineAuthKey;
|
||||
late FlutterSecureStorage _secureStorage;
|
||||
late String _tempDirectory;
|
||||
late String _thumbnailCacheDirectory;
|
||||
|
||||
// 6th July 22: Remove this after 3 months. Hopefully, active users
|
||||
// will migrate to newer version of the app, where shared media is stored
|
||||
// on appSupport directory which OS won't clean up automatically
|
||||
late String _sharedTempMediaDirectory;
|
||||
|
||||
late String _sharedDocumentsMediaDirectory;
|
||||
String? _volatilePassword;
|
||||
|
||||
final _secureStorageOptionsIOS = const IOSOptions(
|
||||
accessibility: KeychainAccessibility.first_unlock_this_device,
|
||||
);
|
||||
|
||||
// const IOSOptions(accessibility: IOSAccessibility.first_unlock);
|
||||
|
||||
Future<void> init() async {
|
||||
_preferences = await SharedPreferences.getInstance();
|
||||
_secureStorage = const FlutterSecureStorage();
|
||||
@@ -88,15 +89,27 @@ class Configuration {
|
||||
_logger.warning(e);
|
||||
}
|
||||
tempDirectory.createSync(recursive: true);
|
||||
final tempDirectoryPath = (await getTemporaryDirectory()).path;
|
||||
_thumbnailCacheDirectory = tempDirectoryPath + "/thumbnail-cache";
|
||||
io.Directory(_thumbnailCacheDirectory).createSync(recursive: true);
|
||||
_sharedTempMediaDirectory = tempDirectoryPath + "/ente-shared-media";
|
||||
io.Directory(_sharedTempMediaDirectory).createSync(recursive: true);
|
||||
_sharedDocumentsMediaDirectory = _documentsDirectory + "/ente-shared-media";
|
||||
io.Directory(_sharedDocumentsMediaDirectory).createSync(recursive: true);
|
||||
await _initOnlineAccount();
|
||||
await _initOfflineAccount();
|
||||
}
|
||||
|
||||
Future<void> _initOfflineAccount() async {
|
||||
_offlineAuthKey = await _secureStorage.read(
|
||||
key: offlineAuthSecretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _initOnlineAccount() async {
|
||||
if (!_preferences.containsKey(tokenKey)) {
|
||||
await _secureStorage.deleteAll(iOptions: _secureStorageOptionsIOS);
|
||||
for (final key in onlineSecureKeys) {
|
||||
unawaited(
|
||||
_secureStorage.delete(
|
||||
key: key,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
_key = await _secureStorage.read(
|
||||
key: keyKey,
|
||||
@@ -113,13 +126,17 @@ class Configuration {
|
||||
if (_key == null) {
|
||||
await logout(autoLogout: true);
|
||||
}
|
||||
await _migrateSecurityStorageToFirstUnlock();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> logout({bool autoLogout = false}) async {
|
||||
await _preferences.clear();
|
||||
await _secureStorage.deleteAll(iOptions: _secureStorageOptionsIOS);
|
||||
for (String key in onlineSecureKeys) {
|
||||
await _secureStorage.delete(
|
||||
key: key,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
await AuthenticatorDB.instance.clearTable();
|
||||
_key = null;
|
||||
_cachedToken = null;
|
||||
@@ -179,8 +196,9 @@ class Configuration {
|
||||
return KeyGenResult(attributes, privateAttributes, loginKey);
|
||||
}
|
||||
|
||||
|
||||
Future<Tuple2<KeyAttributes, Uint8List>> getAttributesForNewPassword(String password) async {
|
||||
Future<Tuple2<KeyAttributes, Uint8List>> getAttributesForNewPassword(
|
||||
String password,
|
||||
) async {
|
||||
// Get master key
|
||||
final masterKey = getKey();
|
||||
|
||||
@@ -215,18 +233,16 @@ class Configuration {
|
||||
// SRP setup for existing users.
|
||||
Future<Uint8List> decryptSecretsAndGetKeyEncKey(
|
||||
String password,
|
||||
KeyAttributes attributes,
|
||||
{
|
||||
KeyAttributes attributes, {
|
||||
Uint8List? keyEncryptionKey,
|
||||
}
|
||||
) async {
|
||||
}) async {
|
||||
_logger.info('Start decryptAndSaveSecrets');
|
||||
keyEncryptionKey ??= await CryptoUtil.deriveKey(
|
||||
utf8.encode(password) as Uint8List,
|
||||
Sodium.base642bin(attributes.kekSalt),
|
||||
attributes.memLimit,
|
||||
attributes.opsLimit,
|
||||
);
|
||||
utf8.encode(password) as Uint8List,
|
||||
Sodium.base642bin(attributes.kekSalt),
|
||||
attributes.memLimit,
|
||||
attributes.opsLimit,
|
||||
);
|
||||
|
||||
_logger.info('user-key done');
|
||||
Uint8List key;
|
||||
@@ -356,52 +372,31 @@ class Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setKey(String? key) async {
|
||||
Future<void> setKey(String key) async {
|
||||
_key = key;
|
||||
if (key == null) {
|
||||
await _secureStorage.delete(
|
||||
key: keyKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
} else {
|
||||
await _secureStorage.write(
|
||||
key: keyKey,
|
||||
value: key,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
await _secureStorage.write(
|
||||
key: keyKey,
|
||||
value: key,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setSecretKey(String? secretKey) async {
|
||||
_secretKey = secretKey;
|
||||
if (secretKey == null) {
|
||||
await _secureStorage.delete(
|
||||
key: secretKeyKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
} else {
|
||||
await _secureStorage.write(
|
||||
key: secretKeyKey,
|
||||
value: secretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
await _secureStorage.write(
|
||||
key: secretKeyKey,
|
||||
value: secretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setAuthSecretKey(String? authSecretKey) async {
|
||||
_authSecretKey = authSecretKey;
|
||||
if (authSecretKey == null) {
|
||||
await _secureStorage.delete(
|
||||
key: authSecretKeyKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
} else {
|
||||
await _secureStorage.write(
|
||||
key: authSecretKeyKey,
|
||||
value: authSecretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
await _secureStorage.write(
|
||||
key: authSecretKeyKey,
|
||||
value: authSecretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
|
||||
Uint8List? getKey() {
|
||||
@@ -416,6 +411,10 @@ class Configuration {
|
||||
return _authSecretKey == null ? null : Sodium.base642bin(_authSecretKey!);
|
||||
}
|
||||
|
||||
Uint8List? getOfflineSecretKey() {
|
||||
return _offlineAuthKey == null ? null : Sodium.base642bin(_offlineAuthKey!);
|
||||
}
|
||||
|
||||
Uint8List getRecoveryKey() {
|
||||
final keyAttributes = getKeyAttributes()!;
|
||||
return CryptoUtil.decryptSync(
|
||||
@@ -430,22 +429,34 @@ class Configuration {
|
||||
return _tempDirectory;
|
||||
}
|
||||
|
||||
String getThumbnailCacheDirectory() {
|
||||
return _thumbnailCacheDirectory;
|
||||
}
|
||||
|
||||
String getOldSharedMediaCacheDirectory() {
|
||||
return _sharedTempMediaDirectory;
|
||||
}
|
||||
|
||||
String getSharedMediaDirectory() {
|
||||
return _sharedDocumentsMediaDirectory;
|
||||
}
|
||||
|
||||
bool hasConfiguredAccount() {
|
||||
return getToken() != null && _key != null;
|
||||
}
|
||||
|
||||
bool hasOptedForOfflineMode() {
|
||||
return _preferences.getBool(hasOptedForOfflineModeKey) ?? false;
|
||||
}
|
||||
|
||||
Future<void> optForOfflineMode() async {
|
||||
if ((await _secureStorage.containsKey(
|
||||
key: offlineAuthSecretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
))) {
|
||||
_offlineAuthKey = await _secureStorage.read(
|
||||
key: offlineAuthSecretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
} else {
|
||||
_offlineAuthKey = Sodium.bin2base64(CryptoUtil.generateKey());
|
||||
await _secureStorage.write(
|
||||
key: offlineAuthSecretKey,
|
||||
value: _offlineAuthKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
}
|
||||
await _preferences.setBool(hasOptedForOfflineModeKey, true);
|
||||
}
|
||||
|
||||
bool shouldShowLockScreen() {
|
||||
if (_preferences.containsKey(keyShouldShowLockScreen)) {
|
||||
return _preferences.getBool(keyShouldShowLockScreen)!;
|
||||
@@ -465,27 +476,4 @@ class Configuration {
|
||||
String? getVolatilePassword() {
|
||||
return _volatilePassword;
|
||||
}
|
||||
|
||||
Future<void> _migrateSecurityStorageToFirstUnlock() async {
|
||||
final hasMigratedSecureStorageToFirstUnlock =
|
||||
_preferences.getBool(hasMigratedSecureStorageKey) ?? false;
|
||||
if (!hasMigratedSecureStorageToFirstUnlock &&
|
||||
_key != null &&
|
||||
_secretKey != null) {
|
||||
await _secureStorage.write(
|
||||
key: keyKey,
|
||||
value: _key,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
await _secureStorage.write(
|
||||
key: secretKeyKey,
|
||||
value: _secretKey,
|
||||
iOptions: _secureStorageOptionsIOS,
|
||||
);
|
||||
await _preferences.setBool(
|
||||
hasMigratedSecureStorageKey,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ class SuperLogging {
|
||||
if (_preferences.containsKey(keyShouldReportErrors)) {
|
||||
return _preferences.getBool(keyShouldReportErrors)!;
|
||||
} else {
|
||||
return false;
|
||||
return kDebugMode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ extension CustomColorScheme on ColorScheme {
|
||||
? const Color.fromRGBO(245, 245, 245, 1.0)
|
||||
: const Color.fromRGBO(30, 30, 30, 1.0);
|
||||
|
||||
Color get searchResultsCountTextColor => brightness == Brightness.light
|
||||
Color get mutedTextColor => brightness == Brightness.light
|
||||
? const Color.fromRGBO(80, 80, 80, 1)
|
||||
: const Color.fromRGBO(150, 150, 150, 1);
|
||||
|
||||
|
||||
3
lib/events/icons_changed_event.dart
Normal file
3
lib/events/icons_changed_event.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
import 'package:ente_auth/events/event.dart';
|
||||
|
||||
class IconsChangedEvent extends Event {}
|
||||
@@ -5,7 +5,7 @@
|
||||
"@counterAppBarTitle": {
|
||||
"description": "Text shown in the AppBar of the Counter Page"
|
||||
},
|
||||
"onBoardingBody": "Secure your 2FA codes",
|
||||
"onBoardingBody": "Securely backup your 2FA codes",
|
||||
"onBoardingGetStarted": "Get Started",
|
||||
"setupFirstAccount": "Setup your first account",
|
||||
"importScanQrCode": "Scan a QR Code",
|
||||
@@ -70,7 +70,7 @@
|
||||
"incorrectPasswordTitle": "Incorrect password",
|
||||
"welcomeBack": "Welcome back!",
|
||||
"madeWithLoveAtPrefix": "made with ❤️ at ",
|
||||
"supportDevs": "Subscribe to <bold-green>ente</bold-green> to support this project.",
|
||||
"supportDevs": "Subscribe to <bold-green>ente</bold-green> to support this project",
|
||||
"supportDiscount": "Use coupon code \"AUTH\" to get 10% off first year",
|
||||
"changeEmail": "Change email",
|
||||
"changePassword": "Change password",
|
||||
@@ -102,6 +102,7 @@
|
||||
"no": "No",
|
||||
"email": "Email",
|
||||
"support": "Support",
|
||||
"general": "General",
|
||||
"settings": "Settings",
|
||||
"copied": "Copied",
|
||||
"pleaseTryAgain": "Please try again",
|
||||
@@ -183,6 +184,7 @@
|
||||
"enterDetailsManually": "Enter details manually",
|
||||
"edit": "Edit",
|
||||
"copiedToClipboard": "Copied to clipboard",
|
||||
"copiedNextToClipboard": "Copied next code to clipboard",
|
||||
"error": "Error",
|
||||
"recoveryKeyCopiedToClipboard": "Recovery key copied to clipboard",
|
||||
"recoveryKeyOnForgotPassword": "If you forget your password, the only way you can recover your data is with this key.",
|
||||
@@ -253,6 +255,10 @@
|
||||
"privacy": "Privacy",
|
||||
"terms": "Terms",
|
||||
"checkForUpdates": "Check for updates",
|
||||
"downloadUpdate": "Download",
|
||||
"criticalUpdateAvailable": "Critical update available",
|
||||
"updateAvailable": "Update available",
|
||||
"update": "Update",
|
||||
"checking": "Checking...",
|
||||
"youAreOnTheLatestVersion": "You are on the latest version",
|
||||
"warning": "Warning",
|
||||
@@ -316,5 +322,12 @@
|
||||
"encrypted": "Encrypted",
|
||||
"plainText": "Plain text",
|
||||
"passwordToEncryptExport": "Password to encrypt export",
|
||||
"export": "Export"
|
||||
"export": "Export",
|
||||
"useOffline": "Use without backups",
|
||||
"signInToBackup": "Sign in to backup your codes",
|
||||
"singIn": "Sign in",
|
||||
"sigInBackupReminder": "Please export your codes to ensure that you have a backup you can restore from.",
|
||||
"offlineModeWarning": "You have chosen to proceed without backups. Please take manual backups to make sure your codes are safe.",
|
||||
"showLargeIcons": "Show large icons",
|
||||
"focusOnSearchBar": "Focus search on app start"
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@
|
||||
"importSelectJsonFile": "Selecteer JSON bestand",
|
||||
"importEnteEncGuide": "Selecteer het versleutelde JSON-bestand dat vanuit ente geëxporteerd is",
|
||||
"importRaivoGuide": "Gebruik de optie \"Export OTPs to Zip archive\" in Raivo's instellingen.\n\nPak het zip-bestand uit en importeer het JSON-bestand.",
|
||||
"importAegisGuide": "Gebruik de optie \"Exporteer de kluis\" in de instellingen van Aegis.\n\nAls uw kluis is versleuteld, moet u het wachtwoord invoeren om de kluis te ontsleutelen.",
|
||||
"exportCodes": "Codes exporteren",
|
||||
"importLabel": "Importeren",
|
||||
"importInstruction": "Selecteer een bestand dat een lijst van uw codes in de volgende indeling bevat",
|
||||
|
||||
@@ -7,17 +7,23 @@ import 'package:ente_auth/ente_theme_data.dart';
|
||||
import 'package:ente_auth/events/trigger_logout_event.dart';
|
||||
import "package:ente_auth/l10n/l10n.dart";
|
||||
import 'package:ente_auth/locale.dart';
|
||||
import 'package:ente_auth/theme/text_style.dart';
|
||||
import 'package:ente_auth/ui/account/email_entry_page.dart';
|
||||
import 'package:ente_auth/ui/account/login_page.dart';
|
||||
import 'package:ente_auth/ui/account/logout_dialog.dart';
|
||||
import 'package:ente_auth/ui/account/password_entry_page.dart';
|
||||
import 'package:ente_auth/ui/account/password_reentry_page.dart';
|
||||
import 'package:ente_auth/ui/common/gradient_button.dart';
|
||||
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
|
||||
import 'package:ente_auth/ui/components/models/button_result.dart';
|
||||
import 'package:ente_auth/ui/home_page.dart';
|
||||
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:flutter/foundation.dart';
|
||||
import "package:flutter/material.dart";
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
|
||||
class OnboardingPage extends StatefulWidget {
|
||||
const OnboardingPage({Key? key}) : super(key: key);
|
||||
@@ -112,6 +118,9 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
style:
|
||||
Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
color: Colors.white38,
|
||||
// color: Theme.of(context)
|
||||
// .colorScheme
|
||||
// .mutedTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -128,7 +137,7 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 28),
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
|
||||
child: Hero(
|
||||
tag: "log_in",
|
||||
child: ElevatedButton(
|
||||
@@ -145,6 +154,23 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.only(top: 20, bottom: 20),
|
||||
child: GestureDetector(
|
||||
onTap: _optForOfflineMode,
|
||||
child: Center(
|
||||
child: Text(
|
||||
l10n.useOffline,
|
||||
style: body.copyWith(
|
||||
color:
|
||||
Theme.of(context).colorScheme.mutedTextColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -155,6 +181,36 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _optForOfflineMode() async {
|
||||
bool canCheckBio = await LocalAuthentication().canCheckBiometrics;
|
||||
if(!canCheckBio) {
|
||||
showToast(context, "Sorry, biometric authentication is not supported on this device.");
|
||||
return;
|
||||
}
|
||||
final bool hasOptedBefore = Configuration.instance.hasOptedForOfflineMode();
|
||||
ButtonResult? result;
|
||||
if(!hasOptedBefore) {
|
||||
result = await showChoiceActionSheet(
|
||||
context,
|
||||
title: context.l10n.warning,
|
||||
body: context.l10n.offlineModeWarning,
|
||||
secondButtonLabel: context.l10n.cancel,
|
||||
firstButtonLabel: context.l10n.ok,
|
||||
);
|
||||
}
|
||||
if (hasOptedBefore || result?.action == ButtonAction.first) {
|
||||
await Configuration.instance.optForOfflineMode();
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const HomePage();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void _navigateToSignUpPage() {
|
||||
Widget page;
|
||||
if (Configuration.instance.getEncryptedToken() == null) {
|
||||
@@ -163,7 +219,9 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
// No key
|
||||
if (Configuration.instance.getKeyAttributes() == null) {
|
||||
// Never had a key
|
||||
page = const PasswordEntryPage(mode: PasswordEntryMode.set,);
|
||||
page = const PasswordEntryPage(
|
||||
mode: PasswordEntryMode.set,
|
||||
);
|
||||
} else if (Configuration.instance.getKey() == null) {
|
||||
// Yet to decrypt the key
|
||||
page = const PasswordReentryPage();
|
||||
@@ -189,7 +247,9 @@ class _OnboardingPageState extends State<OnboardingPage> {
|
||||
// No key
|
||||
if (Configuration.instance.getKeyAttributes() == null) {
|
||||
// Never had a key
|
||||
page = const PasswordEntryPage(mode: PasswordEntryMode.set,);
|
||||
page = const PasswordEntryPage(
|
||||
mode: PasswordEntryMode.set,
|
||||
);
|
||||
} else if (Configuration.instance.getKey() == null) {
|
||||
// Yet to decrypt the key
|
||||
page = const PasswordReentryPage();
|
||||
|
||||
@@ -15,18 +15,29 @@ import 'package:ente_auth/models/authenticator/auth_key.dart';
|
||||
import 'package:ente_auth/models/authenticator/entity_result.dart';
|
||||
import 'package:ente_auth/models/authenticator/local_auth_entity.dart';
|
||||
import 'package:ente_auth/store/authenticator_db.dart';
|
||||
import 'package:ente_auth/store/offline_authenticator_db.dart';
|
||||
import 'package:ente_auth/utils/crypto_util.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_sodium/flutter_sodium.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
enum AccountMode {
|
||||
online,
|
||||
offline,
|
||||
}
|
||||
extension on AccountMode {
|
||||
bool get isOnline => this == AccountMode.online;
|
||||
bool get isOffline => this == AccountMode.offline;
|
||||
}
|
||||
|
||||
class AuthenticatorService {
|
||||
final _logger = Logger((AuthenticatorService).toString());
|
||||
final _config = Configuration.instance;
|
||||
late SharedPreferences _prefs;
|
||||
late AuthenticatorGateway _gateway;
|
||||
late AuthenticatorDB _db;
|
||||
late OfflineAuthenticatorDB _offlineDb;
|
||||
final String _lastEntitySyncTime = "lastEntitySyncTime";
|
||||
|
||||
AuthenticatorService._privateConstructor();
|
||||
@@ -34,25 +45,34 @@ class AuthenticatorService {
|
||||
static final AuthenticatorService instance =
|
||||
AuthenticatorService._privateConstructor();
|
||||
|
||||
AccountMode getAccountMode() {
|
||||
return Configuration.instance.hasOptedForOfflineMode() &&
|
||||
!Configuration.instance.hasConfiguredAccount()
|
||||
? AccountMode.offline
|
||||
: AccountMode.online;
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
_db = AuthenticatorDB.instance;
|
||||
_offlineDb = OfflineAuthenticatorDB.instance;
|
||||
_gateway = AuthenticatorGateway(Network.instance.getDio(), _config);
|
||||
if (Configuration.instance.hasConfiguredAccount()) {
|
||||
unawaited(sync());
|
||||
unawaited(onlineSync());
|
||||
}
|
||||
Bus.instance.on<SignedInEvent>().listen((event) {
|
||||
unawaited(sync());
|
||||
unawaited(onlineSync());
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<EntityResult>> getEntities() async {
|
||||
final List<LocalAuthEntity> result = await _db.getAll();
|
||||
Future<List<EntityResult>> getEntities(AccountMode mode) async {
|
||||
final List<LocalAuthEntity> result =
|
||||
mode.isOnline ? await _db.getAll() : await _offlineDb.getAll();
|
||||
final List<EntityResult> entities = [];
|
||||
if (result.isEmpty) {
|
||||
return entities;
|
||||
}
|
||||
final key = await getOrCreateAuthDataKey();
|
||||
final key = await getOrCreateAuthDataKey(mode);
|
||||
for (LocalAuthEntity e in result) {
|
||||
try {
|
||||
final decryptedValue = await CryptoUtil.decryptChaCha(
|
||||
@@ -75,17 +95,23 @@ class AuthenticatorService {
|
||||
return entities;
|
||||
}
|
||||
|
||||
Future<int> addEntry(String plainText, bool shouldSync) async {
|
||||
var key = await getOrCreateAuthDataKey();
|
||||
Future<int> addEntry(
|
||||
String plainText,
|
||||
bool shouldSync,
|
||||
AccountMode accountMode,
|
||||
) async {
|
||||
var key = await getOrCreateAuthDataKey(accountMode);
|
||||
final encryptedKeyData = await CryptoUtil.encryptChaCha(
|
||||
utf8.encode(plainText) as Uint8List,
|
||||
key,
|
||||
);
|
||||
String encryptedData = Sodium.bin2base64(encryptedKeyData.encryptedData!);
|
||||
String header = Sodium.bin2base64(encryptedKeyData.header!);
|
||||
final insertedID = await _db.insert(encryptedData, header);
|
||||
final insertedID = accountMode.isOnline
|
||||
? await _db.insert(encryptedData, header)
|
||||
: await _offlineDb.insert(encryptedData, header);
|
||||
if (shouldSync) {
|
||||
unawaited(sync());
|
||||
unawaited(onlineSync());
|
||||
}
|
||||
return insertedID;
|
||||
}
|
||||
@@ -94,45 +120,60 @@ class AuthenticatorService {
|
||||
int generatedID,
|
||||
String plainText,
|
||||
bool shouldSync,
|
||||
AccountMode accountMode,
|
||||
) async {
|
||||
var key = await getOrCreateAuthDataKey();
|
||||
var key = await getOrCreateAuthDataKey(accountMode);
|
||||
final encryptedKeyData = await CryptoUtil.encryptChaCha(
|
||||
utf8.encode(plainText) as Uint8List,
|
||||
key,
|
||||
);
|
||||
String encryptedData = Sodium.bin2base64(encryptedKeyData.encryptedData!);
|
||||
String header = Sodium.bin2base64(encryptedKeyData.header!);
|
||||
final int affectedRows =
|
||||
await _db.updateEntry(generatedID, encryptedData, header);
|
||||
final int affectedRows = accountMode.isOnline
|
||||
? await _db.updateEntry(generatedID, encryptedData, header)
|
||||
: await _offlineDb.updateEntry(generatedID, encryptedData, header);
|
||||
assert(
|
||||
affectedRows == 1,
|
||||
"updateEntry should have updated exactly one row",
|
||||
);
|
||||
if (shouldSync) {
|
||||
unawaited(sync());
|
||||
unawaited(onlineSync());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteEntry(int genID) async {
|
||||
LocalAuthEntity? result = await _db.getEntryByID(genID);
|
||||
Future<void> deleteEntry(int genID, AccountMode accountMode) async {
|
||||
LocalAuthEntity? result = accountMode.isOnline
|
||||
? await _db.getEntryByID(genID)
|
||||
: await _offlineDb.getEntryByID(genID);
|
||||
if (result == null) {
|
||||
_logger.info("No entry found for given id");
|
||||
return;
|
||||
}
|
||||
if (result.id != null) {
|
||||
if (result.id != null && accountMode.isOnline) {
|
||||
await _gateway.deleteEntity(result.id!);
|
||||
} else {
|
||||
debugPrint("Skipping delete since account mode is offline");
|
||||
}
|
||||
if(accountMode.isOnline) {
|
||||
await _db.deleteByIDs(generatedIDs: [genID]);
|
||||
} else {
|
||||
await _offlineDb.deleteByIDs(generatedIDs: [genID]);
|
||||
}
|
||||
await _db.deleteByIDs(generatedIDs: [genID]);
|
||||
}
|
||||
|
||||
Future<void> sync() async {
|
||||
Future<bool> onlineSync() async {
|
||||
try {
|
||||
if(getAccountMode().isOffline) {
|
||||
debugPrint("Skipping sync since account mode is offline");
|
||||
return false;
|
||||
}
|
||||
_logger.info("Sync");
|
||||
await _remoteToLocalSync();
|
||||
_logger.info("remote fetch completed");
|
||||
await _localToRemoteSync();
|
||||
_logger.info("local push completed");
|
||||
Bus.instance.fire(CodesUpdatedEvent());
|
||||
return true;
|
||||
} on UnauthorizedError {
|
||||
if ((await _db.removeSyncedData()) > 0) {
|
||||
Bus.instance.fire(CodesUpdatedEvent());
|
||||
@@ -140,8 +181,10 @@ class AuthenticatorService {
|
||||
debugPrint("Firing logout event");
|
||||
|
||||
Bus.instance.fire(TriggerLogoutEvent());
|
||||
return false;
|
||||
} catch (e) {
|
||||
_logger.severe("Failed to sync with remote", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +252,10 @@ class AuthenticatorService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List> getOrCreateAuthDataKey() async {
|
||||
Future<Uint8List> getOrCreateAuthDataKey(AccountMode mode) async {
|
||||
if(mode.isOffline) {
|
||||
return _config.getOfflineSecretKey()!;
|
||||
}
|
||||
if (_config.getAuthSecretKey() != null) {
|
||||
return _config.getAuthSecretKey()!;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:ente_auth/core/event_bus.dart';
|
||||
import 'package:ente_auth/events/icons_changed_event.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class PreferenceService {
|
||||
@@ -8,6 +10,8 @@ class PreferenceService {
|
||||
late final SharedPreferences _prefs;
|
||||
|
||||
static const kHasShownCoachMarkKey = "has_shown_coach_mark";
|
||||
static const kShouldShowLargeIconsKey = "should_show_large_icons";
|
||||
static const kShouldAutoFocusOnSearchBar = "should_auto_focus_on_search_bar";
|
||||
|
||||
Future<void> init() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
@@ -24,4 +28,30 @@ class PreferenceService {
|
||||
Future<void> setHasShownCoachMark(bool value) {
|
||||
return _prefs.setBool(kHasShownCoachMarkKey, value);
|
||||
}
|
||||
|
||||
bool shouldShowLargeIcons() {
|
||||
if (_prefs.containsKey(kShouldShowLargeIconsKey)) {
|
||||
return _prefs.getBool(kShouldShowLargeIconsKey)!;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setShowLargeIcons(bool value) async {
|
||||
await _prefs.setBool(kShouldShowLargeIconsKey, value);
|
||||
Bus.instance.fire(IconsChangedEvent());
|
||||
}
|
||||
|
||||
bool shouldAutoFocusOnSearchBar() {
|
||||
if (_prefs.containsKey(kShouldAutoFocusOnSearchBar)) {
|
||||
return _prefs.getBool(kShouldAutoFocusOnSearchBar)!;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setAutoFocusOnSearchBar(bool value) async {
|
||||
await _prefs.setBool(kShouldAutoFocusOnSearchBar, value);
|
||||
Bus.instance.fire(IconsChangedEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
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:logging/logging.dart';
|
||||
|
||||
class CodeStore {
|
||||
@@ -20,9 +22,10 @@ class CodeStore {
|
||||
_authenticatorService = AuthenticatorService.instance;
|
||||
}
|
||||
|
||||
Future<List<Code>> getAllCodes() async {
|
||||
Future<List<Code>> getAllCodes({AccountMode? accountMode}) async {
|
||||
final mode = accountMode ?? _authenticatorService.getAccountMode();
|
||||
final List<EntityResult> entities =
|
||||
await _authenticatorService.getEntities();
|
||||
await _authenticatorService.getEntities(mode);
|
||||
final List<Code> codes = [];
|
||||
for (final entity in entities) {
|
||||
final decodeJson = jsonDecode(entity.rawData);
|
||||
@@ -43,38 +46,120 @@ class CodeStore {
|
||||
return codes;
|
||||
}
|
||||
|
||||
Future<void> addCode(
|
||||
Future<AddResult> addCode(
|
||||
Code code, {
|
||||
bool shouldSync = true,
|
||||
AccountMode? accountMode,
|
||||
}) async {
|
||||
final codes = await getAllCodes();
|
||||
final mode = accountMode ?? _authenticatorService.getAccountMode();
|
||||
final codes = await getAllCodes(accountMode: mode);
|
||||
bool isExistingCode = false;
|
||||
for (final existingCode in codes) {
|
||||
if (existingCode == code) {
|
||||
_logger.info("Found duplicate code, skipping add");
|
||||
return;
|
||||
return AddResult.duplicate;
|
||||
} else if (existingCode.generatedID == code.generatedID) {
|
||||
isExistingCode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
late AddResult result;
|
||||
if (isExistingCode) {
|
||||
result = AddResult.updateCode;
|
||||
await _authenticatorService.updateEntry(
|
||||
code.generatedID!,
|
||||
jsonEncode(code.rawData),
|
||||
shouldSync,
|
||||
mode,
|
||||
);
|
||||
} else {
|
||||
result = AddResult.newCode;
|
||||
code.generatedID = await _authenticatorService.addEntry(
|
||||
jsonEncode(code.rawData),
|
||||
shouldSync,
|
||||
mode,
|
||||
);
|
||||
}
|
||||
Bus.instance.fire(CodesUpdatedEvent());
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> removeCode(Code code) async {
|
||||
await _authenticatorService.deleteEntry(code.generatedID!);
|
||||
Future<void> removeCode(Code code, {AccountMode? accountMode}) async {
|
||||
final mode = accountMode ?? _authenticatorService.getAccountMode();
|
||||
await _authenticatorService.deleteEntry(code.generatedID!, mode);
|
||||
Bus.instance.fire(CodesUpdatedEvent());
|
||||
}
|
||||
|
||||
bool _isOfflineImportRunning = false;
|
||||
|
||||
Future<void> importOfflineCodes() async {
|
||||
if(_isOfflineImportRunning) {
|
||||
return;
|
||||
}
|
||||
_isOfflineImportRunning = true;
|
||||
Logger logger = Logger('importOfflineCodes');
|
||||
try {
|
||||
Configuration config = Configuration.instance;
|
||||
if (!config.hasConfiguredAccount() ||
|
||||
!config.hasOptedForOfflineMode() ||
|
||||
config.getOfflineSecretKey() == null) {
|
||||
return;
|
||||
}
|
||||
logger.info('start import');
|
||||
|
||||
List<Code> offlineCodes = await CodeStore.instance
|
||||
.getAllCodes(accountMode: AccountMode.offline);
|
||||
if (offlineCodes.isEmpty) {
|
||||
return;
|
||||
}
|
||||
bool isOnlineSyncDone = await AuthenticatorService.instance.onlineSync();
|
||||
if (!isOnlineSyncDone) {
|
||||
logger.info("skip as online sync is not done");
|
||||
return;
|
||||
}
|
||||
final List<Code> onlineCodes =
|
||||
await CodeStore.instance.getAllCodes(accountMode: AccountMode.online);
|
||||
logger.info(
|
||||
'importing ${offlineCodes.length} offline codes with ${onlineCodes.length} online codes',
|
||||
);
|
||||
for (Code eachCode in offlineCodes) {
|
||||
bool alreadyPresent = onlineCodes.any(
|
||||
(oc) =>
|
||||
oc.issuer == eachCode.issuer &&
|
||||
oc.account == eachCode.account &&
|
||||
oc.secret == eachCode.secret,
|
||||
);
|
||||
int? generatedID = eachCode.generatedID!;
|
||||
logger.info(
|
||||
'importingCode: genID ${eachCode.generatedID} & isAlreadyPresent $alreadyPresent',
|
||||
);
|
||||
if (!alreadyPresent) {
|
||||
// Avoid conflict with generatedID of online codes
|
||||
eachCode.generatedID = null;
|
||||
final AddResult result = await CodeStore.instance.addCode(
|
||||
eachCode,
|
||||
accountMode: AccountMode.online,
|
||||
shouldSync: false,
|
||||
);
|
||||
logger.info(
|
||||
'importedCode: genID ${eachCode.generatedID} result: ${result.name}',
|
||||
);
|
||||
}
|
||||
await OfflineAuthenticatorDB.instance.deleteByIDs(
|
||||
generatedIDs: [generatedID],
|
||||
);
|
||||
}
|
||||
AuthenticatorService.instance.onlineSync().ignore();
|
||||
} catch (e, s) {
|
||||
_logger.severe("error while importing offline codes", e, s);
|
||||
} finally {
|
||||
_isOfflineImportRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum AddResult {
|
||||
newCode,
|
||||
duplicate,
|
||||
updateCode,
|
||||
}
|
||||
|
||||
170
lib/store/offline_authenticator_db.dart
Normal file
170
lib/store/offline_authenticator_db.dart
Normal file
@@ -0,0 +1,170 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ente_auth/models/authenticator/auth_entity.dart';
|
||||
import 'package:ente_auth/models/authenticator/local_auth_entity.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
class OfflineAuthenticatorDB {
|
||||
static const _databaseName = "ente.offline_authenticator.db";
|
||||
static const _databaseVersion = 1;
|
||||
|
||||
static const entityTable = 'entities';
|
||||
|
||||
OfflineAuthenticatorDB._privateConstructor();
|
||||
static final OfflineAuthenticatorDB instance = OfflineAuthenticatorDB._privateConstructor();
|
||||
|
||||
static Future<Database>? _dbFuture;
|
||||
|
||||
Future<Database> get database async {
|
||||
_dbFuture ??= _initDatabase();
|
||||
return _dbFuture!;
|
||||
}
|
||||
|
||||
Future<Database> _initDatabase() async {
|
||||
final Directory documentsDirectory =
|
||||
await getApplicationDocumentsDirectory();
|
||||
final String path = join(documentsDirectory.path, _databaseName);
|
||||
debugPrint(path);
|
||||
return await openDatabase(
|
||||
path,
|
||||
version: _databaseVersion,
|
||||
onCreate: _onCreate,
|
||||
);
|
||||
}
|
||||
|
||||
Future _onCreate(Database db, int version) async {
|
||||
await db.execute(
|
||||
'''
|
||||
CREATE TABLE $entityTable (
|
||||
_generatedID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
id TEXT,
|
||||
encryptedData TEXT NOT NULL,
|
||||
header TEXT NOT NULL,
|
||||
createdAt INTEGER NOT NULL,
|
||||
updatedAt INTEGER NOT NULL,
|
||||
shouldSync INTEGER DEFAULT 0,
|
||||
UNIQUE(id)
|
||||
);
|
||||
''',
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> insert(String encData, String header) async {
|
||||
final db = await instance.database;
|
||||
final int timeInMicroSeconds = DateTime.now().microsecondsSinceEpoch;
|
||||
final insertedID = await db.insert(
|
||||
entityTable,
|
||||
{
|
||||
"encryptedData": encData,
|
||||
"header": header,
|
||||
"shouldSync": 1,
|
||||
"createdAt": timeInMicroSeconds,
|
||||
"updatedAt": timeInMicroSeconds,
|
||||
},
|
||||
);
|
||||
return insertedID;
|
||||
}
|
||||
|
||||
Future<int> updateEntry(
|
||||
int generatedID,
|
||||
String encData,
|
||||
String header,
|
||||
) async {
|
||||
final db = await instance.database;
|
||||
final int timeInMicroSeconds = DateTime.now().microsecondsSinceEpoch;
|
||||
int affectedRows = await db.update(
|
||||
entityTable,
|
||||
{
|
||||
"encryptedData": encData,
|
||||
"header": header,
|
||||
"shouldSync": 1,
|
||||
"updatedAt": timeInMicroSeconds,
|
||||
},
|
||||
where: '_generatedID = ?',
|
||||
whereArgs: [generatedID],
|
||||
);
|
||||
return affectedRows;
|
||||
}
|
||||
|
||||
Future<void> insertOrReplace(List<AuthEntity> authEntities) async {
|
||||
final db = await instance.database;
|
||||
final batch = db.batch();
|
||||
for (AuthEntity authEntity in authEntities) {
|
||||
final insertRow = authEntity.toMap();
|
||||
insertRow.remove('isDeleted');
|
||||
insertRow.putIfAbsent('shouldSync', () => 0);
|
||||
batch.insert(
|
||||
entityTable,
|
||||
insertRow,
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
}
|
||||
await batch.commit(noResult: true);
|
||||
}
|
||||
|
||||
Future<void> updateLocalEntity(LocalAuthEntity localAuthEntity) async {
|
||||
final db = await instance.database;
|
||||
await db.update(
|
||||
entityTable,
|
||||
localAuthEntity.toMap(),
|
||||
where: '_generatedID = ?',
|
||||
whereArgs: [localAuthEntity.generatedID],
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
}
|
||||
|
||||
Future<LocalAuthEntity?> getEntryByID(int genID) async {
|
||||
final db = await instance.database;
|
||||
final rows = await db
|
||||
.query(entityTable, where: '_generatedID = ?', whereArgs: [genID]);
|
||||
final listOfAuthEntities = _convertRows(rows);
|
||||
if (listOfAuthEntities.isEmpty) {
|
||||
return null;
|
||||
} else {
|
||||
return listOfAuthEntities.first;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<LocalAuthEntity>> getAll() async {
|
||||
final db = await instance.database;
|
||||
final rows = await db.rawQuery("SELECT * from $entityTable");
|
||||
return _convertRows(rows);
|
||||
}
|
||||
|
||||
// deleteByID will prefer generated id if both ids are passed during deletion
|
||||
Future<void> deleteByIDs({List<int>? generatedIDs, List<String>? ids}) async {
|
||||
final db = await instance.database;
|
||||
final batch = db.batch();
|
||||
const whereGenID = '_generatedID = ?';
|
||||
const whereID = 'id = ?';
|
||||
if (generatedIDs != null) {
|
||||
for (int genId in generatedIDs) {
|
||||
batch.delete(entityTable, where: whereGenID, whereArgs: [genId]);
|
||||
}
|
||||
}
|
||||
if (ids != null) {
|
||||
for (String id in ids) {
|
||||
batch.delete(entityTable, where: whereID, whereArgs: [id]);
|
||||
}
|
||||
}
|
||||
final result = await batch.commit();
|
||||
debugPrint("Done");
|
||||
}
|
||||
|
||||
Future<void> clearTable() async {
|
||||
final db = await instance.database;
|
||||
await db.delete(entityTable);
|
||||
}
|
||||
|
||||
List<LocalAuthEntity> _convertRows(List<Map<String, dynamic>> rows) {
|
||||
final keys = <LocalAuthEntity>[];
|
||||
for (final row in rows) {
|
||||
keys.add(LocalAuthEntity.fromMap(row));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:clipboard/clipboard.dart';
|
||||
import 'package:ente_auth/core/configuration.dart';
|
||||
import 'package:ente_auth/ente_theme_data.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/models/code.dart';
|
||||
import 'package:ente_auth/onboarding/view/setup_enter_secret_key_page.dart';
|
||||
import 'package:ente_auth/onboarding/view/view_qr_page.dart';
|
||||
import 'package:ente_auth/services/preference_service.dart';
|
||||
import 'package:ente_auth/store/code_store.dart';
|
||||
import 'package:ente_auth/ui/code_timer_progress.dart';
|
||||
import 'package:ente_auth/ui/utils/icon_utils.dart';
|
||||
@@ -31,6 +33,8 @@ class _CodeWidgetState extends State<CodeWidget> {
|
||||
final ValueNotifier<String> _nextCode = ValueNotifier<String>("");
|
||||
final Logger logger = Logger("_CodeWidgetState");
|
||||
bool _isInitialized = false;
|
||||
late bool hasConfiguredAccount;
|
||||
late bool _shouldShowLargeIcon;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -46,6 +50,7 @@ class _CodeWidgetState extends State<CodeWidget> {
|
||||
}
|
||||
}
|
||||
});
|
||||
hasConfiguredAccount = Configuration.instance.hasConfiguredAccount();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -58,6 +63,7 @@ class _CodeWidgetState extends State<CodeWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_shouldShowLargeIcon = PreferenceService.instance.shouldShowLargeIcons();
|
||||
if (!_isInitialized) {
|
||||
_currentCode.value = _getCurrentOTP();
|
||||
if (widget.code.type == Type.totp) {
|
||||
@@ -133,132 +139,7 @@ class _CodeWidgetState extends State<CodeWidget> {
|
||||
onLongPress: () {
|
||||
_copyToClipboard();
|
||||
},
|
||||
child: SizedBox(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (widget.code.type == Type.totp)
|
||||
CodeTimerProgress(
|
||||
period: widget.code.period,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
safeDecode(widget.code.issuer).trim(),
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
safeDecode(widget.code.account).trim(),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
widget.code.hasSynced != null &&
|
||||
widget.code.hasSynced!
|
||||
? Container()
|
||||
: const Icon(
|
||||
Icons.sync_disabled,
|
||||
size: 20,
|
||||
color: Colors.amber,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
IconUtils.instance.getIcon(
|
||||
safeDecode(widget.code.issuer).trim(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ValueListenableBuilder<String>(
|
||||
valueListenable: _currentCode,
|
||||
builder: (context, value, child) {
|
||||
return Text(
|
||||
value,
|
||||
style: const TextStyle(fontSize: 24),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
widget.code.type == Type.totp
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
l10n.nextTotpTitle,
|
||||
style:
|
||||
Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
ValueListenableBuilder<String>(
|
||||
valueListenable: _nextCode,
|
||||
builder: (context, value, child) {
|
||||
return Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.grey,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
l10n.nextTotpTitle,
|
||||
style:
|
||||
Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
InkWell(
|
||||
onTap: _onNextHotpTapped,
|
||||
child: const Icon(
|
||||
Icons.forward_outlined,
|
||||
size: 32,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: _getCardContents(l10n),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -267,11 +148,181 @@ class _CodeWidgetState extends State<CodeWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getCardContents(AppLocalizations l10n) {
|
||||
return SizedBox(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (widget.code.type == Type.totp)
|
||||
CodeTimerProgress(
|
||||
period: widget.code.period,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
_shouldShowLargeIcon ? _getIcon() : const SizedBox.shrink(),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
_getTopRow(),
|
||||
const SizedBox(height: 4),
|
||||
_getBottomRow(l10n),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getBottomRow(AppLocalizations l10n) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ValueListenableBuilder<String>(
|
||||
valueListenable: _currentCode,
|
||||
builder: (context, value, child) {
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Text(
|
||||
_getFormattedCode(value),
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
widget.code.type == Type.totp
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
_copyNextToClipboard();
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
l10n.nextTotpTitle,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
ValueListenableBuilder<String>(
|
||||
valueListenable: _nextCode,
|
||||
builder: (context, value, child) {
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Text(
|
||||
_getFormattedCode(value),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
l10n.nextTotpTitle,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
InkWell(
|
||||
onTap: _onNextHotpTapped,
|
||||
child: const Icon(
|
||||
Icons.forward_outlined,
|
||||
size: 32,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getTopRow() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
safeDecode(widget.code.issuer).trim(),
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
safeDecode(widget.code.account).trim(),
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
(widget.code.hasSynced != null && widget.code.hasSynced!) ||
|
||||
!hasConfiguredAccount
|
||||
? const SizedBox.shrink()
|
||||
: const Icon(
|
||||
Icons.sync_disabled,
|
||||
size: 20,
|
||||
color: Colors.amber,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_shouldShowLargeIcon ? const SizedBox.shrink() : _getIcon(),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getIcon() {
|
||||
return Padding(
|
||||
padding: _shouldShowLargeIcon
|
||||
? const EdgeInsets.only(left: 16)
|
||||
: const EdgeInsets.all(0),
|
||||
child: IconUtils.instance.getIcon(
|
||||
safeDecode(widget.code.issuer).trim(),
|
||||
width: _shouldShowLargeIcon ? 42 : 24,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _copyToClipboard() {
|
||||
FlutterClipboard.copy(_getCurrentOTP())
|
||||
.then((value) => showToast(context, context.l10n.copiedToClipboard));
|
||||
}
|
||||
|
||||
void _copyNextToClipboard() {
|
||||
FlutterClipboard.copy(_getNextTotp()).then(
|
||||
(value) => showToast(context, context.l10n.copiedNextToClipboard),
|
||||
);
|
||||
}
|
||||
|
||||
void _onNextHotpTapped() {
|
||||
if (widget.code.type == Type.hotp) {
|
||||
CodeStore.instance
|
||||
@@ -297,6 +348,7 @@ class _CodeWidgetState extends State<CodeWidget> {
|
||||
}
|
||||
|
||||
Future<void> _onShowQrPressed(_) async {
|
||||
// ignore: unused_local_variable
|
||||
final Code? code = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
@@ -336,4 +388,11 @@ class _CodeWidgetState extends State<CodeWidget> {
|
||||
return context.l10n.error;
|
||||
}
|
||||
}
|
||||
|
||||
String _getFormattedCode(String code) {
|
||||
if (code.length == 6) {
|
||||
return code.substring(0, 3) + " " + code.substring(3, 6);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +1,120 @@
|
||||
import 'package:ente_auth/ente_theme_data.dart';
|
||||
import "package:ente_auth/ente_theme_data.dart";
|
||||
import 'package:ente_auth/theme/colors.dart';
|
||||
import "package:ente_auth/theme/ente_theme.dart";
|
||||
import 'package:ente_auth/theme/text_style.dart';
|
||||
import 'package:ente_auth/ui/components/buttons/icon_button_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class NotificationWarningWidget extends StatelessWidget {
|
||||
final IconData warningIcon;
|
||||
// CreateNotificationType enum
|
||||
enum NotificationType {
|
||||
warning,
|
||||
banner,
|
||||
notice,
|
||||
}
|
||||
|
||||
class NotificationWidget extends StatelessWidget {
|
||||
final IconData startIcon;
|
||||
final IconData actionIcon;
|
||||
final String text;
|
||||
final String? subText;
|
||||
final GestureTapCallback onTap;
|
||||
final NotificationType type;
|
||||
|
||||
const NotificationWarningWidget({
|
||||
const NotificationWidget({
|
||||
Key? key,
|
||||
required this.warningIcon,
|
||||
required this.startIcon,
|
||||
required this.actionIcon,
|
||||
required this.text,
|
||||
required this.onTap,
|
||||
this.subText,
|
||||
this.type = NotificationType.warning,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
EnteColorScheme colorScheme = getEnteColorScheme(context);
|
||||
EnteTextTheme textTheme = getEnteTextTheme(context);
|
||||
TextStyle mainTextStyle = darkTextTheme.bodyBold;
|
||||
TextStyle subTextStyle = darkTextTheme.miniMuted;
|
||||
LinearGradient? backgroundGradient;
|
||||
Color? backgroundColor;
|
||||
EnteColorScheme strokeColorScheme = darkScheme;
|
||||
List<BoxShadow>? boxShadow;
|
||||
switch (type) {
|
||||
case NotificationType.warning:
|
||||
backgroundColor = warning500;
|
||||
break;
|
||||
case NotificationType.banner:
|
||||
colorScheme = getEnteColorScheme(context);
|
||||
textTheme = getEnteTextTheme(context);
|
||||
backgroundColor = colorScheme.backgroundElevated2;
|
||||
mainTextStyle = textTheme.bodyBold;
|
||||
subTextStyle = textTheme.miniMuted;
|
||||
strokeColorScheme = colorScheme;
|
||||
boxShadow = [
|
||||
BoxShadow(color: Colors.black.withOpacity(0.25), blurRadius: 1),
|
||||
];
|
||||
break;
|
||||
|
||||
case NotificationType.notice:
|
||||
backgroundColor = colorScheme.backgroundElevated2;
|
||||
mainTextStyle = textTheme.bodyBold;
|
||||
subTextStyle = textTheme.miniMuted;
|
||||
strokeColorScheme = colorScheme;
|
||||
boxShadow = Theme.of(context).colorScheme.enteTheme.shadowMenu;
|
||||
break;
|
||||
}
|
||||
return Center(
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
boxShadow: Theme.of(context).colorScheme.enteTheme.shadowMenu,
|
||||
color: warning500,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Icon(
|
||||
warningIcon,
|
||||
size: 36,
|
||||
color: Colors.white,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Flexible(
|
||||
child: Text(
|
||||
text,
|
||||
style: darkTextTheme.bodyBold,
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ClipOval(
|
||||
child: Material(
|
||||
color: fillFaintDark,
|
||||
child: InkWell(
|
||||
splashColor: Colors.red, // Splash color
|
||||
onTap: onTap,
|
||||
child: SizedBox(
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: Icon(
|
||||
actionIcon,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
boxShadow: boxShadow,
|
||||
color: backgroundColor,
|
||||
gradient: backgroundGradient,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Icon(
|
||||
startIcon,
|
||||
size: 36,
|
||||
color: strokeColorScheme.strokeBase,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
text,
|
||||
style: mainTextStyle,
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
),
|
||||
subText != null
|
||||
? Text(
|
||||
subText!,
|
||||
style: subTextStyle,
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
IconButtonWidget(
|
||||
icon: actionIcon,
|
||||
iconButtonType: IconButtonType.rounded,
|
||||
iconColor: strokeColorScheme.strokeBase,
|
||||
defaultColor: strokeColorScheme.fillFaint,
|
||||
pressedColor: strokeColorScheme.fillMuted,
|
||||
onTap: onTap,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -53,6 +53,7 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
|
||||
fit: BoxFit.contain,
|
||||
child: Switch.adaptive(
|
||||
activeColor: enteColorScheme.primary400,
|
||||
activeTrackColor: enteColorScheme.primary300,
|
||||
inactiveTrackColor: enteColorScheme.fillMuted,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
value: toggleValue ?? false,
|
||||
|
||||
@@ -5,6 +5,7 @@ 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';
|
||||
import 'package:ente_auth/events/trigger_logout_event.dart';
|
||||
import "package:ente_auth/l10n/l10n.dart";
|
||||
import 'package:ente_auth/models/code.dart';
|
||||
@@ -51,6 +52,7 @@ class _HomePageState extends State<HomePage> {
|
||||
List<Code> _filteredCodes = [];
|
||||
StreamSubscription<CodesUpdatedEvent>? _streamSubscription;
|
||||
StreamSubscription<TriggerLogoutEvent>? _triggerLogoutEvent;
|
||||
StreamSubscription<IconsChangedEvent>? _iconsChangedEvent;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -65,7 +67,14 @@ class _HomePageState extends State<HomePage> {
|
||||
await autoLogoutAlert(context);
|
||||
});
|
||||
_initDeepLinks();
|
||||
|
||||
Future.delayed(
|
||||
const Duration(seconds: 1),
|
||||
() async => await CodeStore.instance.importOfflineCodes(),
|
||||
);
|
||||
_iconsChangedEvent = Bus.instance.on<IconsChangedEvent>().listen((event) {
|
||||
setState(() {});
|
||||
});
|
||||
_showSearchBox = PreferenceService.instance.shouldAutoFocusOnSearchBar();
|
||||
}
|
||||
|
||||
void _loadCodes() {
|
||||
@@ -97,6 +106,7 @@ class _HomePageState extends State<HomePage> {
|
||||
void dispose() {
|
||||
_streamSubscription?.cancel();
|
||||
_triggerLogoutEvent?.cancel();
|
||||
_iconsChangedEvent?.cancel();
|
||||
_textController.removeListener(_applyFilteringAndRefresh);
|
||||
super.dispose();
|
||||
}
|
||||
@@ -168,7 +178,7 @@ class _HomePageState extends State<HomePage> {
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
title: !_showSearchBox
|
||||
? const Text('ente Authenticator')
|
||||
? const Text('ente Auth')
|
||||
: TextField(
|
||||
autofocus: _searchText.isEmpty,
|
||||
controller: _textController,
|
||||
@@ -179,6 +189,7 @@ class _HomePageState extends State<HomePage> {
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.searchHint,
|
||||
border: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
@@ -225,7 +236,7 @@ class _HomePageState extends State<HomePage> {
|
||||
itemBuilder: ((context, index) {
|
||||
try {
|
||||
return CodeWidget(_filteredCodes[index]);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return const Text("Failed");
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
|
||||
import 'package:ente_auth/app/view/app.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/locale.dart';
|
||||
import 'package:ente_auth/services/local_authentication_service.dart';
|
||||
import 'package:ente_auth/services/user_service.dart';
|
||||
import 'package:ente_auth/theme/ente_theme.dart';
|
||||
@@ -13,7 +11,6 @@ import 'package:ente_auth/ui/components/captioned_text_widget.dart';
|
||||
import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';
|
||||
import 'package:ente_auth/ui/components/menu_item_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/common_settings.dart';
|
||||
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:flutter/material.dart';
|
||||
@@ -89,29 +86,6 @@ class AccountSectionWidget extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.language,
|
||||
),
|
||||
pressedColor: getEnteColorScheme(context).fillFaint,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
final locale = await getLocale();
|
||||
routeToPage(
|
||||
context,
|
||||
LanguageSelectorPage(
|
||||
appSupportedLocales,
|
||||
(locale) async {
|
||||
await setLocale(locale);
|
||||
App.setLocale(context, locale);
|
||||
},
|
||||
locale,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: context.l10n.logout,
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ente_auth/core/configuration.dart';
|
||||
import 'package:ente_auth/core/network.dart';
|
||||
import 'package:ente_auth/ente_theme_data.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/services/update_service.dart';
|
||||
import 'package:ente_auth/theme/ente_theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:open_filex/open_filex.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class AppUpdateDialog extends StatefulWidget {
|
||||
final LatestVersionInfo? latestVersionInfo;
|
||||
@@ -20,6 +23,7 @@ class AppUpdateDialog extends StatefulWidget {
|
||||
class _AppUpdateDialogState extends State<AppUpdateDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final enteTextTheme = getEnteTextTheme(context);
|
||||
final List<Widget> changelog = [];
|
||||
for (final log in widget.latestVersionInfo!.changelog) {
|
||||
changelog.add(
|
||||
@@ -41,18 +45,19 @@ class _AppUpdateDialogState extends State<AppUpdateDialog> {
|
||||
Text(
|
||||
widget.latestVersionInfo!.name!,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const Padding(padding: EdgeInsets.all(8)),
|
||||
const Text(
|
||||
"Changelog",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
if (changelog.isNotEmpty)
|
||||
const Text(
|
||||
"Changelog",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Padding(padding: EdgeInsets.all(4)),
|
||||
if (changelog.isNotEmpty) const Padding(padding: EdgeInsets.all(4)),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: changelog,
|
||||
@@ -69,18 +74,12 @@ class _AppUpdateDialogState extends State<AppUpdateDialog> {
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ApkDownloaderDialog(widget.latestVersionInfo);
|
||||
},
|
||||
barrierDismissible: false,
|
||||
);
|
||||
},
|
||||
child: const Text(
|
||||
"Update",
|
||||
onPressed: () => launchUrlString(
|
||||
widget.latestVersionInfo!.url!,
|
||||
mode: LaunchMode.externalApplication,
|
||||
),
|
||||
child: Text(
|
||||
context.l10n.downloadUpdate,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -91,8 +90,24 @@ class _AppUpdateDialogState extends State<AppUpdateDialog> {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => !shouldForceUpdate,
|
||||
child: AlertDialog(
|
||||
title: Text(
|
||||
shouldForceUpdate ? "Critical update available" : "Update available",
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.auto_awesome_outlined,
|
||||
size: 24,
|
||||
color: getEnteColorScheme(context).strokeMuted,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Text(
|
||||
shouldForceUpdate
|
||||
? context.l10n.criticalUpdateAvailable
|
||||
: context.l10n.updateAvailable,
|
||||
style: enteTextTheme.h3Bold,
|
||||
),
|
||||
],
|
||||
),
|
||||
content: content,
|
||||
),
|
||||
@@ -147,15 +162,17 @@ class _ApkDownloaderDialogState extends State<ApkDownloaderDialog> {
|
||||
|
||||
Future<void> _downloadApk() async {
|
||||
try {
|
||||
await Network.instance.getDio().download(
|
||||
widget.versionInfo!.url!,
|
||||
_saveUrl,
|
||||
onReceiveProgress: (count, _) {
|
||||
setState(() {
|
||||
_downloadProgress = count / widget.versionInfo!.size!;
|
||||
});
|
||||
},
|
||||
);
|
||||
if (!File(_saveUrl!).existsSync()) {
|
||||
await Network.instance.getDio().download(
|
||||
widget.versionInfo!.url!,
|
||||
_saveUrl,
|
||||
onReceiveProgress: (count, _) {
|
||||
setState(() {
|
||||
_downloadProgress = count / widget.versionInfo!.size!;
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
||||
OpenFilex.open(_saveUrl);
|
||||
} catch (e) {
|
||||
|
||||
@@ -51,7 +51,7 @@ class DataSectionWidget extends StatelessWidget {
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
handleExportClick(context);
|
||||
await handleExportClick(context);
|
||||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
|
||||
@@ -156,7 +156,7 @@ Future<int?> _processAegisExportFile(
|
||||
for (final code in parsedCodes) {
|
||||
await CodeStore.instance.addCode(code, shouldSync: false);
|
||||
}
|
||||
unawaited(AuthenticatorService.instance.sync());
|
||||
unawaited(AuthenticatorService.instance.onlineSync());
|
||||
int count = parsedCodes.length;
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,8 @@ Future<void> _decryptExportData(
|
||||
derivedKey,
|
||||
Sodium.base642bin(enteAuthExport.encryptionNonce),
|
||||
);
|
||||
} catch (e) {
|
||||
} catch (e,s) {
|
||||
Logger("encryptedImport").warning('failed to decrypt',e,s);
|
||||
showToast(context, l10n.incorrectPasswordTitle);
|
||||
isPasswordIncorrect = true;
|
||||
}
|
||||
@@ -118,7 +119,7 @@ Future<void> _decryptExportData(
|
||||
for (final code in parsedCodes) {
|
||||
await CodeStore.instance.addCode(code, shouldSync: false);
|
||||
}
|
||||
unawaited(AuthenticatorService.instance.sync());
|
||||
unawaited(AuthenticatorService.instance.onlineSync());
|
||||
importedCodeCount = parsedCodes.length;
|
||||
await progressDialog.hide();
|
||||
} catch (e, s) {
|
||||
|
||||
@@ -55,7 +55,7 @@ Future<void> showGoogleAuthInstruction(BuildContext context) async {
|
||||
for (final code in codes) {
|
||||
await CodeStore.instance.addCode(code, shouldSync: false);
|
||||
}
|
||||
unawaited(AuthenticatorService.instance.sync());
|
||||
unawaited(AuthenticatorService.instance.onlineSync());
|
||||
importSuccessDialog(context, codes.length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ Future<void> _pickImportFile(BuildContext context) async {
|
||||
for (final code in parsedCodes) {
|
||||
await CodeStore.instance.addCode(code, shouldSync: false);
|
||||
}
|
||||
unawaited(AuthenticatorService.instance.sync());
|
||||
unawaited(AuthenticatorService.instance.onlineSync());
|
||||
await progressDialog.hide();
|
||||
await importSuccessDialog(context, parsedCodes.length);
|
||||
} catch (e) {
|
||||
|
||||
@@ -111,7 +111,7 @@ Future<int?> _processRaivoExportFile(BuildContext context,String path) async {
|
||||
for (final code in parsedCodes) {
|
||||
await CodeStore.instance.addCode(code, shouldSync: false);
|
||||
}
|
||||
unawaited(AuthenticatorService.instance.sync());
|
||||
unawaited(AuthenticatorService.instance.onlineSync());
|
||||
int count = parsedCodes.length;
|
||||
return count;
|
||||
}
|
||||
|
||||
111
lib/ui/settings/general_section_widget.dart
Normal file
111
lib/ui/settings/general_section_widget.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'package:ente_auth/app/view/app.dart';
|
||||
import 'package:ente_auth/core/logging/super_logging.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/locale.dart';
|
||||
import 'package:ente_auth/services/preference_service.dart';
|
||||
import 'package:ente_auth/theme/ente_theme.dart';
|
||||
import 'package:ente_auth/ui/components/captioned_text_widget.dart';
|
||||
import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';
|
||||
import 'package:ente_auth/ui/components/menu_item_widget.dart';
|
||||
import 'package:ente_auth/ui/components/toggle_switch_widget.dart';
|
||||
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:flutter/material.dart';
|
||||
|
||||
class AdvancedSectionWidget extends StatefulWidget {
|
||||
const AdvancedSectionWidget({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AdvancedSectionWidget> createState() => _AdvancedSectionWidgetState();
|
||||
}
|
||||
|
||||
class _AdvancedSectionWidgetState extends State<AdvancedSectionWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return ExpandableMenuItemWidget(
|
||||
title: l10n.general,
|
||||
selectionOptionsWidget: _getSectionOptions(context),
|
||||
leadingIcon: Icons.graphic_eq,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getSectionOptions(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return Column(
|
||||
children: [
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.language,
|
||||
),
|
||||
pressedColor: getEnteColorScheme(context).fillFaint,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
final locale = await getLocale();
|
||||
routeToPage(
|
||||
context,
|
||||
LanguageSelectorPage(
|
||||
appSupportedLocales,
|
||||
(locale) async {
|
||||
await setLocale(locale);
|
||||
App.setLocale(context, locale);
|
||||
},
|
||||
locale,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.showLargeIcons,
|
||||
),
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () => PreferenceService.instance.shouldShowLargeIcons(),
|
||||
onChanged: () async {
|
||||
await PreferenceService.instance.setShowLargeIcons(
|
||||
!PreferenceService.instance.shouldShowLargeIcons(),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.focusOnSearchBar,
|
||||
),
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () =>
|
||||
PreferenceService.instance.shouldAutoFocusOnSearchBar(),
|
||||
onChanged: () async {
|
||||
await PreferenceService.instance.setAutoFocusOnSearchBar(
|
||||
!PreferenceService.instance.shouldAutoFocusOnSearchBar(),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.crashAndErrorReporting,
|
||||
),
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () => SuperLogging.shouldReportErrors(),
|
||||
onChanged: () async {
|
||||
await SuperLogging.setShouldReportErrors(
|
||||
!SuperLogging.shouldReportErrors(),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,11 @@ class SecuritySectionWidget extends StatefulWidget {
|
||||
|
||||
class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
|
||||
final _config = Configuration.instance;
|
||||
late bool _hasLoggedIn;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_hasLoggedIn = _config.hasConfiguredAccount();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -53,49 +55,103 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
|
||||
}
|
||||
|
||||
Widget _getSectionOptions(BuildContext context) {
|
||||
final bool? canDisableMFA = UserService.instance.canDisableEmailMFA();
|
||||
if (canDisableMFA == null) {
|
||||
// We don't know if the user can disable MFA yet, so we fetch the info
|
||||
UserService.instance.getUserDetailsV2().ignore();
|
||||
}
|
||||
final l10n = context.l10n;
|
||||
final List<Widget> children = [];
|
||||
children.addAll([
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.recoveryKey,
|
||||
),
|
||||
pressedColor: getEnteColorScheme(context).fillFaint,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
final hasAuthenticated = await LocalAuthenticationService.instance
|
||||
.requestLocalAuthentication(
|
||||
context,
|
||||
l10n.authToViewYourRecoveryKey,
|
||||
);
|
||||
if (hasAuthenticated) {
|
||||
String recoveryKey;
|
||||
try {
|
||||
recoveryKey =
|
||||
Sodium.bin2hex(Configuration.instance.getRecoveryKey());
|
||||
} catch (e) {
|
||||
showGenericErrorDialog(context: context);
|
||||
return;
|
||||
}
|
||||
routeToPage(
|
||||
if (_hasLoggedIn) {
|
||||
final bool? canDisableMFA = UserService.instance.canDisableEmailMFA();
|
||||
if (canDisableMFA == null) {
|
||||
// We don't know if the user can disable MFA yet, so we fetch the info
|
||||
UserService.instance.getUserDetailsV2().ignore();
|
||||
}
|
||||
children.addAll([
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.recoveryKey,
|
||||
),
|
||||
pressedColor: getEnteColorScheme(context).fillFaint,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
final hasAuthenticated = await LocalAuthenticationService.instance
|
||||
.requestLocalAuthentication(
|
||||
context,
|
||||
RecoveryKeyPage(
|
||||
recoveryKey,
|
||||
l10n.ok,
|
||||
showAppBar: true,
|
||||
onDone: () {},
|
||||
),
|
||||
l10n.authToViewYourRecoveryKey,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (hasAuthenticated) {
|
||||
String recoveryKey;
|
||||
try {
|
||||
recoveryKey =
|
||||
Sodium.bin2hex(Configuration.instance.getRecoveryKey());
|
||||
} catch (e) {
|
||||
showGenericErrorDialog(context: context);
|
||||
return;
|
||||
}
|
||||
routeToPage(
|
||||
context,
|
||||
RecoveryKeyPage(
|
||||
recoveryKey,
|
||||
l10n.ok,
|
||||
showAppBar: true,
|
||||
onDone: () {},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.emailVerificationToggle,
|
||||
),
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () => UserService.instance.hasEmailMFAEnabled(),
|
||||
onChanged: () async {
|
||||
final hasAuthenticated = await LocalAuthenticationService.instance
|
||||
.requestLocalAuthentication(
|
||||
context,
|
||||
l10n.authToChangeEmailVerificationSetting,
|
||||
);
|
||||
final isEmailMFAEnabled =
|
||||
UserService.instance.hasEmailMFAEnabled();
|
||||
if (hasAuthenticated) {
|
||||
await updateEmailMFA(!isEmailMFAEnabled);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: context.l10n.viewActiveSessions,
|
||||
),
|
||||
pressedColor: getEnteColorScheme(context).fillFaint,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
final hasAuthenticated = await LocalAuthenticationService.instance
|
||||
.requestLocalAuthentication(
|
||||
context,
|
||||
context.l10n.authToViewYourActiveSessions,
|
||||
);
|
||||
if (hasAuthenticated) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const SessionsPage();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
]);
|
||||
} else {
|
||||
children.add(sectionOptionSpacing);
|
||||
}
|
||||
children.addAll([
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.lockscreen,
|
||||
@@ -117,54 +173,6 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.emailVerificationToggle,
|
||||
),
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () => UserService.instance.hasEmailMFAEnabled(),
|
||||
onChanged: () async {
|
||||
final hasAuthenticated = await LocalAuthenticationService.instance
|
||||
.requestLocalAuthentication(
|
||||
context,
|
||||
l10n.authToChangeEmailVerificationSetting,
|
||||
);
|
||||
final isEmailMFAEnabled = UserService.instance.hasEmailMFAEnabled();
|
||||
if (hasAuthenticated) {
|
||||
await updateEmailMFA(!isEmailMFAEnabled);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: context.l10n.viewActiveSessions,
|
||||
),
|
||||
pressedColor: getEnteColorScheme(context).fillFaint,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
final hasAuthenticated = await LocalAuthenticationService.instance
|
||||
.requestLocalAuthentication(
|
||||
context,
|
||||
context.l10n.authToViewYourActiveSessions,
|
||||
);
|
||||
if (hasAuthenticated) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const SessionsPage();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
]);
|
||||
return Column(
|
||||
children: children,
|
||||
@@ -173,12 +181,19 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
|
||||
|
||||
Future<void> updateEmailMFA(bool isEnabled) async {
|
||||
try {
|
||||
final UserDetails details = await UserService.instance.getUserDetailsV2(memoryCount: false);
|
||||
if(details.profileData?.canDisableEmailMFA == false) {
|
||||
await routeToPage(context, RequestPasswordVerificationPage(onPasswordVerified: (Uint8List keyEncryptionKey) async {
|
||||
final Uint8List loginKey = await CryptoUtil.deriveLoginKey(keyEncryptionKey);
|
||||
await UserService.instance.registerOrUpdateSrp(loginKey);
|
||||
},),);
|
||||
final UserDetails details =
|
||||
await UserService.instance.getUserDetailsV2(memoryCount: false);
|
||||
if (details.profileData?.canDisableEmailMFA == false) {
|
||||
await routeToPage(
|
||||
context,
|
||||
RequestPasswordVerificationPage(
|
||||
onPasswordVerified: (Uint8List keyEncryptionKey) async {
|
||||
final Uint8List loginKey =
|
||||
await CryptoUtil.deriveLoginKey(keyEncryptionKey);
|
||||
await UserService.instance.registerOrUpdateSrp(loginKey);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
await UserService.instance.updateEmailMFA(isEnabled);
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ente_auth/core/configuration.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/models/subscription.dart';
|
||||
import 'package:ente_auth/services/billing_service.dart';
|
||||
@@ -18,50 +19,56 @@ class SupportDevWidget extends StatelessWidget {
|
||||
final l10n = context.l10n;
|
||||
|
||||
// fetch
|
||||
return FutureBuilder<Subscription>(
|
||||
future: BillingService.instance.getSubscription(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final subscription = snapshot.data;
|
||||
if (subscription != null && subscription.productID == "free") {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
launchUrl(Uri.parse("https://ente.io"));
|
||||
},
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 12.0, horizontal: 6),
|
||||
child: Column(
|
||||
children: [
|
||||
StyledText(
|
||||
text: l10n.supportDevs,
|
||||
tags: {
|
||||
'bold-green': StyledTextTag(
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getEnteColorScheme(context).primaryGreen,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
const Padding(padding: EdgeInsets.all(6)),
|
||||
Platform.isAndroid
|
||||
? Text(
|
||||
l10n.supportDiscount,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (Configuration.instance.hasConfiguredAccount()) {
|
||||
return FutureBuilder<Subscription>(
|
||||
future: BillingService.instance.getSubscription(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final subscription = snapshot.data;
|
||||
if (subscription != null && subscription.productID == "free") {
|
||||
return buildWidget(l10n, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return buildWidget(l10n, context);
|
||||
}
|
||||
}
|
||||
|
||||
GestureDetector buildWidget(AppLocalizations l10n, BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
launchUrl(Uri.parse("https://ente.io"));
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 6),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
StyledText(
|
||||
text: l10n.supportDevs,
|
||||
style: getEnteTextTheme(context).large,
|
||||
tags: {
|
||||
'bold-green': StyledTextTag(
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getEnteColorScheme(context).primaryGreen,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
const Padding(padding: EdgeInsets.all(6)),
|
||||
Text(
|
||||
l10n.supportDiscount,
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import 'package:ente_auth/core/constants.dart';
|
||||
import 'package:ente_auth/core/logging/super_logging.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/theme/ente_theme.dart';
|
||||
import 'package:ente_auth/ui/components/captioned_text_widget.dart';
|
||||
import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';
|
||||
import 'package:ente_auth/ui/components/menu_item_widget.dart';
|
||||
import 'package:ente_auth/ui/components/toggle_switch_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/common_settings.dart';
|
||||
import 'package:ente_auth/ui/settings/faq.dart';
|
||||
import 'package:ente_auth/utils/email_util.dart';
|
||||
@@ -35,7 +33,6 @@ class _SupportSectionWidgetState extends State<SupportSectionWidget> {
|
||||
return Column(
|
||||
children: [
|
||||
sectionOptionSpacing,
|
||||
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.faq,
|
||||
@@ -98,21 +95,6 @@ class _SupportSectionWidgetState extends State<SupportSectionWidget> {
|
||||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: l10n.crashAndErrorReporting,
|
||||
),
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () => SuperLogging.shouldReportErrors(),
|
||||
onChanged: () async {
|
||||
await SuperLogging.setShouldReportErrors(
|
||||
!SuperLogging.shouldReportErrors(),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,42 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ente_auth/core/configuration.dart';
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/onboarding/view/onboarding_page.dart';
|
||||
import 'package:ente_auth/services/user_service.dart';
|
||||
import 'package:ente_auth/theme/colors.dart';
|
||||
import 'package:ente_auth/theme/ente_theme.dart';
|
||||
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
|
||||
import 'package:ente_auth/ui/components/models/button_result.dart';
|
||||
import 'package:ente_auth/ui/components/notification_warning_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/about_section_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/account_section_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/app_version_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/data/data_section_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/data/export_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/general_section_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/security_section_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/social_section_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/support_dev_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/support_section_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/theme_switch_widget.dart';
|
||||
import 'package:ente_auth/ui/settings/title_bar_widget.dart';
|
||||
import 'package:ente_auth/utils/dialog_util.dart';
|
||||
import 'package:ente_auth/utils/navigation_util.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
final ValueNotifier<String?> emailNotifier;
|
||||
const SettingsPage({Key? key, required this.emailNotifier}) : super(key: key);
|
||||
|
||||
SettingsPage({Key? key, required this.emailNotifier}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
UserService.instance.getUserDetailsV2().ignore();
|
||||
final _hasLoggedIn = Configuration.instance.hasConfiguredAccount();
|
||||
if (_hasLoggedIn) {
|
||||
UserService.instance.getUserDetailsV2().ignore();
|
||||
}
|
||||
final enteColorScheme = getEnteColorScheme(context);
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
@@ -34,34 +47,71 @@ class SettingsPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _getBody(BuildContext context, EnteColorScheme colorScheme) {
|
||||
final _hasLoggedIn = Configuration.instance.hasConfiguredAccount();
|
||||
final enteTextTheme = getEnteTextTheme(context);
|
||||
const sectionSpacing = SizedBox(height: 8);
|
||||
final List<Widget> contents = [];
|
||||
contents.add(
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: AnimatedBuilder(
|
||||
// [AnimatedBuilder] accepts any [Listenable] subtype.
|
||||
animation: emailNotifier,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Text(
|
||||
emailNotifier.value!,
|
||||
style: enteTextTheme.body.copyWith(
|
||||
color: colorScheme.textMuted,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
},
|
||||
if (_hasLoggedIn) {
|
||||
contents.add(
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: AnimatedBuilder(
|
||||
// [AnimatedBuilder] accepts any [Listenable] subtype.
|
||||
animation: emailNotifier,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Text(
|
||||
emailNotifier.value!,
|
||||
style: enteTextTheme.body.copyWith(
|
||||
color: colorScheme.textMuted,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
const sectionSpacing = SizedBox(height: 8);
|
||||
contents.add(const SizedBox(height: 12));
|
||||
);
|
||||
contents.addAll([
|
||||
const SizedBox(height: 12),
|
||||
AccountSectionWidget(),
|
||||
sectionSpacing,
|
||||
]);
|
||||
} else {
|
||||
contents.addAll([
|
||||
NotificationWidget(
|
||||
startIcon: Icons.account_circle_sharp,
|
||||
actionIcon: Icons.arrow_forward,
|
||||
text: context.l10n.signInToBackup,
|
||||
type: NotificationType.notice,
|
||||
onTap: () async {
|
||||
ButtonResult? result = await showChoiceActionSheet(
|
||||
context,
|
||||
title: context.l10n.warning,
|
||||
body: context.l10n.sigInBackupReminder,
|
||||
secondButtonLabel: context.l10n.singIn,
|
||||
secondButtonAction: ButtonAction.second,
|
||||
firstButtonLabel: context.l10n.exportCodes,
|
||||
);
|
||||
if (result == null) return;
|
||||
if (result.action == ButtonAction.first) {
|
||||
await handleExportClick(context);
|
||||
} else {
|
||||
if (result.action == ButtonAction.second) {
|
||||
await routeToPage(
|
||||
context,
|
||||
const OnboardingPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
sectionSpacing,
|
||||
sectionSpacing,
|
||||
]);
|
||||
}
|
||||
contents.addAll([
|
||||
AccountSectionWidget(),
|
||||
sectionSpacing,
|
||||
DataSectionWidget(),
|
||||
sectionSpacing,
|
||||
const SecuritySectionWidget(),
|
||||
@@ -76,6 +126,8 @@ class SettingsPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
contents.addAll([
|
||||
const AdvancedSectionWidget(),
|
||||
sectionSpacing,
|
||||
const SupportSectionWidget(),
|
||||
sectionSpacing,
|
||||
const SocialSectionWidget(),
|
||||
|
||||
@@ -18,29 +18,39 @@ class IconUtils {
|
||||
await _loadJson();
|
||||
}
|
||||
|
||||
Widget getIcon(String provider) {
|
||||
Widget getIcon(
|
||||
String provider, {
|
||||
double width = 24,
|
||||
}) {
|
||||
final title = _getProviderTitle(provider);
|
||||
if (_customIcons.containsKey(title)) {
|
||||
return _getSVGIcon(
|
||||
"assets/custom-icons/icons/$title.svg",
|
||||
title,
|
||||
_customIcons[title]!,
|
||||
width,
|
||||
);
|
||||
} else if (_simpleIcons.containsKey(title)) {
|
||||
return _getSVGIcon(
|
||||
"assets/simple-icons/icons/$title.svg",
|
||||
title,
|
||||
_simpleIcons[title]!,
|
||||
width,
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
Widget _getSVGIcon(String path, String title, String color) {
|
||||
Widget _getSVGIcon(
|
||||
String path,
|
||||
String title,
|
||||
String color,
|
||||
double width,
|
||||
) {
|
||||
return SvgPicture.asset(
|
||||
path,
|
||||
width: 24,
|
||||
width: width,
|
||||
semanticsLabel: title,
|
||||
colorFilter: ColorFilter.mode(
|
||||
Color(int.parse("0xFF" + color)),
|
||||
|
||||
@@ -224,7 +224,7 @@ ProgressDialog createProgressDialog(
|
||||
);
|
||||
dialog.style(
|
||||
message: message,
|
||||
messageTextStyle: Theme.of(context).textTheme.bodySmall,
|
||||
messageTextStyle: Theme.of(context).textTheme.labelMedium,
|
||||
backgroundColor: Theme.of(context).dialogTheme.backgroundColor,
|
||||
progressWidget: const EnteLoadingWidget(),
|
||||
borderRadius: 10,
|
||||
|
||||
@@ -88,14 +88,14 @@ SPEC CHECKSUMS:
|
||||
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
||||
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
|
||||
package_info_plus_macos: f010621b07802a241d96d01876d6705f15e77c1c
|
||||
path_provider_foundation: 37748e03f12783f9de2cb2c4eadfaa25fe6d4852
|
||||
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
|
||||
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
|
||||
Sentry: 4c9babff9034785067c896fd580b1f7de44da020
|
||||
sentry_flutter: b10ae7a5ddcbc7f04648eeb2672b5747230172f1
|
||||
sentry_flutter: 1346a880b24c0240807b53b10cf50ddad40f504e
|
||||
share_plus_macos: 853ee48e7dce06b633998ca0735d482dd671ade4
|
||||
shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca
|
||||
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
|
||||
sqflite: a5789cceda41d54d23f31d6de539d65bb14100ea
|
||||
url_launcher_macos: c04e4fa86382d4f94f6b38f14625708be3ae52e2
|
||||
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95
|
||||
|
||||
PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7
|
||||
|
||||
|
||||
70
migration-guides/decrypt/crypt.go
Normal file
70
migration-guides/decrypt/crypt.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"github.com/jamesruan/sodium"
|
||||
"golang.org/x/crypto/argon2"
|
||||
)
|
||||
|
||||
// deriveArgonKey generates a 32-bit cryptographic key using the Argon2id algorithm.
|
||||
// Parameters:
|
||||
// - password: The plaintext password to be hashed.
|
||||
// - salt: The salt as a base64 encoded string.
|
||||
// - memLimit: The memory limit in bytes.
|
||||
// - opsLimit: The number of iterations.
|
||||
//
|
||||
// Returns:
|
||||
// - A byte slice representing the derived key.
|
||||
// - An error object, which is nil if no error occurs.
|
||||
func deriveArgonKey(password, salt string, memLimit, opsLimit int) ([]byte, error) {
|
||||
if memLimit < 1024 || opsLimit < 1 {
|
||||
return nil, fmt.Errorf("invalid memory or operation limits")
|
||||
}
|
||||
|
||||
// Decode salt from base64
|
||||
saltBytes, err := base64.StdEncoding.DecodeString(salt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid salt: %v", err)
|
||||
}
|
||||
|
||||
// Generate key using Argon2id
|
||||
// Note: We're assuming a fixed key length of 32 bytes and changing the threads
|
||||
key := argon2.IDKey([]byte(password), saltBytes, uint32(opsLimit), uint32(memLimit/1024), 1, 32)
|
||||
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// decryptChaCha20poly1305 decrypts the given data using the ChaCha20-Poly1305 algorithm.
|
||||
// Parameters:
|
||||
// - data: The encrypted data as a byte slice.
|
||||
// - key: The key for decryption as a byte slice.
|
||||
// - nonce: The nonce for decryption as a byte slice.
|
||||
//
|
||||
// Returns:
|
||||
// - A byte slice representing the decrypted data.
|
||||
// - An error object, which is nil if no error occurs.
|
||||
func decryptChaCha20poly1305(data []byte, key []byte, nonce []byte) ([]byte, error) {
|
||||
reader := bytes.NewReader(data)
|
||||
header := sodium.SecretStreamXCPHeader{Bytes: nonce}
|
||||
decoder, err := sodium.MakeSecretStreamXCPDecoder(
|
||||
sodium.SecretStreamXCPKey{Bytes: key},
|
||||
reader,
|
||||
header)
|
||||
if err != nil {
|
||||
log.Println("Failed to make secret stream decoder", err)
|
||||
return nil, err
|
||||
}
|
||||
// Buffer to store the decrypted data
|
||||
decryptedData := make([]byte, len(data))
|
||||
n, err := decoder.Read(decryptedData)
|
||||
if err != nil && err != io.EOF {
|
||||
log.Println("Failed to read from decoder", err)
|
||||
return nil, err
|
||||
}
|
||||
return decryptedData[:n], nil
|
||||
}
|
||||
53
migration-guides/decrypt/crypt_test.go
Normal file
53
migration-guides/decrypt/crypt_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
password = "test_password"
|
||||
kdfSalt = "vd0dcYMGNLKn/gpT6uTFTw=="
|
||||
memLimit = 64 * 1024 * 1024 // 64MB
|
||||
opsLimit = 2
|
||||
cipherText = "kBXQ2PuX6y/aje5r22H0AehRPh6sQ0ULoeAO"
|
||||
cipherNonce = "v7wsI+BFZsRMIjDm3rTxPhmi/CaUdkdJ"
|
||||
expectedPlainText = "plain_text"
|
||||
expectedDerivedKey = "vp8d8Nee0BbIML4ab8Cp34uYnyrN77cRwTl920flyT0="
|
||||
)
|
||||
|
||||
func TestDeriveArgonKey(t *testing.T) {
|
||||
derivedKey, err := deriveArgonKey(password, kdfSalt, memLimit, opsLimit)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to derive key: %v", err)
|
||||
}
|
||||
|
||||
if base64.StdEncoding.EncodeToString(derivedKey) != expectedDerivedKey {
|
||||
t.Fatalf("Derived key does not match expected key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecryptChaCha20poly1305(t *testing.T) {
|
||||
derivedKey, err := deriveArgonKey(password, kdfSalt, memLimit, opsLimit)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to derive key: %v", err)
|
||||
}
|
||||
|
||||
decodedCipherText, err := base64.StdEncoding.DecodeString(cipherText)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to decode cipher text: %v", err)
|
||||
}
|
||||
|
||||
decodedCipherNonce, err := base64.StdEncoding.DecodeString(cipherNonce)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to decode cipher nonce: %v", err)
|
||||
}
|
||||
|
||||
decryptedText, err := decryptChaCha20poly1305(decodedCipherText, derivedKey, decodedCipherNonce)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to decrypt: %v", err)
|
||||
}
|
||||
if string(decryptedText) != expectedPlainText {
|
||||
t.Fatalf("Decrypted text : %s does not match the expected text: %s", string(decryptedText), expectedPlainText)
|
||||
}
|
||||
}
|
||||
BIN
migration-guides/decrypt/decrypt
Executable file
BIN
migration-guides/decrypt/decrypt
Executable file
Binary file not shown.
105
migration-guides/decrypt/decrypt.go
Normal file
105
migration-guides/decrypt/decrypt.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Export struct {
|
||||
Version int `json:"version"`
|
||||
KDFParams KDF `json:"kdfParams"`
|
||||
EncryptedData string `json:"encryptedData"`
|
||||
EncryptionNonce string `json:"encryptionNonce"`
|
||||
}
|
||||
|
||||
type KDF struct {
|
||||
MemLimit int `json:"memLimit"`
|
||||
OpsLimit int `json:"opsLimit"`
|
||||
Salt string `json:"salt"`
|
||||
}
|
||||
|
||||
func resolvePath(path string) (string, error) {
|
||||
if path[:2] != "~/" {
|
||||
return path, nil
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return home + path[1:], nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if len(os.Args) != 4 {
|
||||
fmt.Println("Usage: ./decrypt <export_file> <password> <output_file>")
|
||||
return
|
||||
}
|
||||
|
||||
exportFile, err := resolvePath(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Println("Error resolving exportFile path:", err)
|
||||
return
|
||||
}
|
||||
password := os.Args[2]
|
||||
outputFile, err := resolvePath(os.Args[3])
|
||||
if err != nil {
|
||||
fmt.Println("Error resolving outputFile path:", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(exportFile)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading file:", err)
|
||||
return
|
||||
}
|
||||
|
||||
var export Export
|
||||
if err := json.Unmarshal(data, &export); err != nil {
|
||||
fmt.Println("Error parsing JSON:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if export.Version != 1 {
|
||||
fmt.Println("Unsupported version")
|
||||
return
|
||||
}
|
||||
|
||||
encryptedData, err := base64.StdEncoding.DecodeString(export.EncryptedData)
|
||||
if err != nil {
|
||||
fmt.Println("Error decoding encrypted data:", err)
|
||||
return
|
||||
}
|
||||
|
||||
nonce, err := base64.StdEncoding.DecodeString(export.EncryptionNonce)
|
||||
if err != nil {
|
||||
fmt.Println("Error decoding nonce:", err)
|
||||
return
|
||||
}
|
||||
|
||||
key, err := deriveArgonKey(password, export.KDFParams.Salt, export.KDFParams.MemLimit, export.KDFParams.OpsLimit)
|
||||
if err != nil {
|
||||
fmt.Println("Error deriving key:", err)
|
||||
return
|
||||
}
|
||||
|
||||
decryptedData, err := decryptChaCha20poly1305(encryptedData, key, nonce)
|
||||
if err != nil {
|
||||
fmt.Println("Error decrypting data:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := os.WriteFile(outputFile, decryptedData, 0644); err != nil {
|
||||
fmt.Println("Error writing decrypted data to file:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Decrypted data written to %s\n", outputFile)
|
||||
}
|
||||
10
migration-guides/decrypt/go.mod
Normal file
10
migration-guides/decrypt/go.mod
Normal file
@@ -0,0 +1,10 @@
|
||||
module decrypt
|
||||
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/jamesruan/sodium v1.0.14
|
||||
golang.org/x/crypto v0.11.0
|
||||
)
|
||||
|
||||
require golang.org/x/sys v0.10.0 // indirect
|
||||
6
migration-guides/decrypt/go.sum
Normal file
6
migration-guides/decrypt/go.sum
Normal file
@@ -0,0 +1,6 @@
|
||||
github.com/jamesruan/sodium v1.0.14 h1:JfOHobip/lUWouxHV3PwYwu3gsLewPrDrZXO3HuBzUU=
|
||||
github.com/jamesruan/sodium v1.0.14/go.mod h1:GK2+LACf7kuVQ9k7Irk0MB2B65j5rVqkz+9ylGIggZk=
|
||||
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
## Overview
|
||||
|
||||
When we export the auth codes, the data is encrypted using a key derived from the user's password.
|
||||
This document describes the JSON structure used to organize exported data, including versioning and key derivation parameters.
|
||||
When we export the auth codes, the data is encrypted using a key derived from the user's password.
|
||||
This document describes the JSON structure used to organize exported data, including versioning and key derivation
|
||||
parameters.
|
||||
|
||||
## Export JSON Sample
|
||||
|
||||
@@ -27,10 +28,12 @@ The main object used to represent the export data. It contains the following key
|
||||
- `encryptedData"`: The encrypted authentication data.
|
||||
- `encryptionNonce`: The nonce used for encryption.
|
||||
|
||||
### Version
|
||||
### Version
|
||||
|
||||
Export version is used to identify the format of the export data.
|
||||
|
||||
Export version is used to identify the format of the export data.
|
||||
#### Ver: 1
|
||||
|
||||
* KDF Algorithm: `ARGON2ID`
|
||||
* Decrypted data format: `otpauth://totp/...`, separated by a new line.
|
||||
* Encryption Algo: `XChaCha20-Poly1305`
|
||||
@@ -44,9 +47,17 @@ This section contains the parameters that were using during KDF operation:
|
||||
- `salt`: The salt used in the derivation process.
|
||||
|
||||
#### Encrypted Data
|
||||
As mentioned above, the auth data is encrypted using a key that's derived by using user provided password & kdf params.
|
||||
For encryption, we are using `XChaCha20-Poly1305` algorithm.
|
||||
|
||||
## How to use the export data
|
||||
* **ente Authenticator app**: You can directly import the codes in the ente Authenticator app.
|
||||
>Settings -> Data -> Import Codes -> ente Encrypted export.
|
||||
As mentioned above, the auth data is encrypted using a key that's derived by using user provided password & kdf params.
|
||||
For encryption, we are using `XChaCha20-Poly1305` algorithm.
|
||||
|
||||
## How to use the exported data
|
||||
|
||||
* **ente Authenticator app**: You can directly import the codes in the ente Authenticator app.
|
||||
> Settings -> Data -> Import Codes -> ente Encrypted export.
|
||||
|
||||
* **Decryption Tool** : You can download the prebuilt [decryption tool](decrypt/decrypt) (or build it from [source](decrypt)) and run the following command.
|
||||
|
||||
```
|
||||
./decrypt <export_file> <password> <output_file>
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: ente_auth
|
||||
description: ente two-factor authenticator
|
||||
version: 1.0.56+56
|
||||
version: 2.0.4+204
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
|
||||
Reference in New Issue
Block a user