Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][locker] Add email verification and passkey to security settings

Claudeeae799f48dc7
diff --git a/mobile/apps/locker/lib/l10n/app_en.arb b/mobile/apps/locker/lib/l10n/app_en.arb
index 254412fe74..b96da60cef 100644
--- a/mobile/apps/locker/lib/l10n/app_en.arb
+++ b/mobile/apps/locker/lib/l10n/app_en.arb
@@ -1023,5 +1023,9 @@
"usageFamily": "Family",
"searchSettings": "Search settings",
"suggestions": "Suggestions",
- "noResultsFound": "No results found"
+ "noResultsFound": "No results found",
+ "viewActiveSessions": "View active sessions",
+ "authToViewYourActiveSessions": "Please authenticate to view your active sessions",
+ "emailVerificationEnableWarning": "To avoid getting locked out of your account, be sure to store a copy of your email 2FA outside of Ente Locker before enabling email verification.",
+ "iUnderStand": "I understand"
}
diff --git a/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dart b/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dart
index bc5009858c..50f19ea05e 100644
--- a/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dart
+++ b/mobile/apps/locker/lib/ui/settings/pages/security_settings_page.dart
@@ -1,16 +1,43 @@
-import "package:ente_lock_screen/auth_util.dart";
+import "dart:typed_data";
+
+import "package:ente_accounts/models/user_details.dart";
+import "package:ente_accounts/pages/request_pwd_verification_page.dart";
+import "package:ente_accounts/pages/sessions_page.dart";
+import "package:ente_accounts/services/passkey_service.dart";
+import "package:ente_accounts/services/user_service.dart";
+import "package:ente_crypto_api/ente_crypto_api.dart";
+import "package:ente_lock_screen/local_authentication_service.dart";
import "package:ente_lock_screen/lock_screen_settings.dart";
import "package:ente_lock_screen/ui/lock_screen_options.dart";
import "package:ente_ui/components/title_bar_title_widget.dart";
+import "package:ente_ui/components/toggle_switch_widget.dart";
import "package:ente_ui/theme/ente_theme.dart";
import "package:ente_ui/utils/dialog_util.dart";
+import "package:ente_ui/utils/toast_util.dart";
import "package:flutter/material.dart";
import "package:locker/l10n/l10n.dart";
+import "package:locker/services/configuration.dart";
import "package:locker/ui/settings/widgets/settings_widget.dart";
+import "package:logging/logging.dart";
-class SecuritySettingsPage extends StatelessWidget {
+class SecuritySettingsPage extends StatefulWidget {
const SecuritySettingsPage({super.key});
+ @override
+ State<SecuritySettingsPage> createState() => _SecuritySettingsPageState();
+}
+
+class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
+ final _config = Configuration.instance;
+ final Logger _logger = Logger('SecuritySettingsPage');
+ late bool _hasLoggedIn;
+
+ @override
+ void initState() {
+ _hasLoggedIn = _config.hasConfiguredAccount();
+ super.initState();
+ }
+
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
@@ -36,10 +63,15 @@ class SecuritySettingsPage extends StatelessWidget {
children: [
TitleBarTitleWidget(title: l10n.security),
const SizedBox(height: 24),
- SettingsItem(
- title: l10n.appLock,
- onTap: () => _onAppLockTapped(context),
- ),
+ if (_hasLoggedIn) ...[
+ _buildEmailVerificationItem(context),
+ const SizedBox(height: 12),
+ _buildPasskeyItem(context),
+ const SizedBox(height: 12),
+ _buildActiveSessionsItem(context),
+ const SizedBox(height: 12),
+ ],
+ _buildAppLockItem(context),
],
),
),
@@ -47,14 +79,86 @@ class SecuritySettingsPage extends StatelessWidget {
);
}
+ Widget _buildEmailVerificationItem(BuildContext context) {
+ final l10n = context.l10n;
+ 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();
+ }
+
+ return SettingsItem(
+ title: l10n.emailVerificationToggle,
+ showChevron: false,
+ trailing: 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(() {});
+ }
+ }
+ },
+ ),
+ );
+ }
+
+ Widget _buildPasskeyItem(BuildContext context) {
+ final l10n = context.l10n;
+ return SettingsItem(
+ title: l10n.passkey,
+ onTap: () => _onPasskeyClick(context),
+ );
+ }
+
+ Widget _buildActiveSessionsItem(BuildContext context) {
+ final l10n = context.l10n;
+ return SettingsItem(
+ title: l10n.viewActiveSessions,
+ onTap: () async {
+ final hasAuthenticated =
+ await LocalAuthenticationService.instance.requestLocalAuthentication(
+ context,
+ l10n.authToViewYourActiveSessions,
+ );
+ if (hasAuthenticated) {
+ // ignore: unawaited_futures
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return SessionsPage(Configuration.instance);
+ },
+ ),
+ );
+ }
+ },
+ );
+ }
+
+ Widget _buildAppLockItem(BuildContext context) {
+ final l10n = context.l10n;
+ return SettingsItem(
+ title: l10n.appLock,
+ onTap: () => _onAppLockTapped(context),
+ );
+ }
+
Future<void> _onAppLockTapped(BuildContext context) async {
final l10n = context.l10n;
if (await LockScreenSettings.instance.isDeviceSupported()) {
- final bool result = await requestAuthentication(
+ final hasAuthenticated =
+ await LocalAuthenticationService.instance.requestLocalAuthentication(
context,
l10n.authToChangeLockscreenSetting,
);
- if (result) {
+ if (hasAuthenticated) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
@@ -71,4 +175,81 @@ class SecuritySettingsPage extends StatelessWidget {
);
}
}
+
+ Future<void> _onPasskeyClick(BuildContext buildContext) async {
+ try {
+ final hasAuthenticated =
+ await LocalAuthenticationService.instance.requestLocalAuthentication(
+ context,
+ context.l10n.authToViewPasskey,
+ refocusWindows: false,
+ );
+ if (!hasAuthenticated) {
+ return;
+ }
+ final isPassKeyResetEnabled =
+ await PasskeyService.instance.isPasskeyRecoveryEnabled();
+ if (!isPassKeyResetEnabled) {
+ final Uint8List recoveryKey = Configuration.instance.getRecoveryKey();
+ final resetKey = CryptoUtil.generateKey();
+ final resetKeyBase64 = CryptoUtil.bin2base64(resetKey);
+ final encryptionResult = CryptoUtil.encryptSync(
+ resetKey,
+ recoveryKey,
+ );
+ await PasskeyService.instance.configurePasskeyRecovery(
+ resetKeyBase64,
+ CryptoUtil.bin2base64(encryptionResult.encryptedData!),
+ CryptoUtil.bin2base64(encryptionResult.nonce!),
+ );
+ }
+ await PasskeyService.instance.openPasskeyPage(buildContext);
+ } catch (e, s) {
+ _logger.severe("failed to open passkey page", e, s);
+ await showGenericErrorDialog(
+ context: context,
+ error: e,
+ );
+ }
+ }
+
+ Future<void> _updateEmailMFA(bool enableEmailMFA) async {
+ try {
+ final UserDetails details =
+ await UserService.instance.getUserDetailsV2(memoryCount: false);
+ if (details.profileData?.canDisableEmailMFA == false) {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return RequestPasswordVerificationPage(
+ Configuration.instance,
+ onPasswordVerified: (Uint8List keyEncryptionKey) async {
+ final Uint8List loginKey =
+ await CryptoUtil.deriveLoginKey(keyEncryptionKey);
+ await UserService.instance.registerOrUpdateSrp(loginKey);
+ },
+ );
+ },
+ ),
+ );
+ }
+ if (enableEmailMFA) {
+ await showChoiceActionSheet(
+ context,
+ title: context.l10n.warning,
+ body: context.l10n.emailVerificationEnableWarning,
+ isCritical: true,
+ firstButtonOnTap: () async {
+ await UserService.instance.updateEmailMFA(enableEmailMFA);
+ },
+ secondButtonLabel: context.l10n.cancel,
+ firstButtonLabel: context.l10n.iUnderStand,
+ );
+ } else {
+ await UserService.instance.updateEmailMFA(enableEmailMFA);
+ }
+ } catch (e) {
+ showToast(context, context.l10n.somethingWentWrong);
+ }
+ }
}