瀏覽代碼

Improve UX for login via password

Neeraj Gupta 1 年之前
父節點
當前提交
0c4e5b7da6
共有 2 個文件被更改,包括 19 次插入10 次删除
  1. 9 6
      lib/core/configuration.dart
  2. 10 4
      lib/services/user_service.dart

+ 9 - 6
lib/core/configuration.dart

@@ -216,14 +216,17 @@ class Configuration {
   Future<Uint8List> decryptSecretsAndGetKeyEncKey(
     String password,
     KeyAttributes attributes,
+  {
+    Uint8List? keyEncryptionKey,
+  }
   ) async {
     _logger.info('Start decryptAndSaveSecrets');
-    final keyEncryptionKey = await CryptoUtil.deriveKey(
-      utf8.encode(password) as Uint8List,
-      Sodium.base642bin(attributes.kekSalt),
-      attributes.memLimit,
-      attributes.opsLimit,
-    );
+    keyEncryptionKey ??= await CryptoUtil.deriveKey(
+        utf8.encode(password) as Uint8List,
+        Sodium.base642bin(attributes.kekSalt),
+        attributes.memLimit,
+        attributes.opsLimit,
+      );
 
     _logger.info('user-key done');
     Uint8List key;

+ 10 - 4
lib/services/user_service.dart

@@ -25,6 +25,7 @@ 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/account/recovery_page.dart';
 import 'package:ente_auth/ui/components/buttons/button_widget.dart';
+import 'package:ente_auth/ui/home_page.dart';
 import 'package:ente_auth/ui/two_factor_authentication_page.dart';
 import 'package:ente_auth/ui/two_factor_recovery_page.dart';
 import 'package:ente_auth/utils/crypto_util.dart';
@@ -521,14 +522,15 @@ class UserService {
       isDismissible: true,
     );
     await dialog.show();
+    late Uint8List keyEncryptionKey;
     try {
-      final kek = await CryptoUtil.deriveKey(
+      keyEncryptionKey = await CryptoUtil.deriveKey(
         utf8.encode(userPassword) as Uint8List,
         CryptoUtil.base642bin(srpAttributes.kekSalt),
         srpAttributes.memLimit,
         srpAttributes.opsLimit,
       );
-      final loginKey = await CryptoUtil.deriveLoginKey(kek);
+      final loginKey = await CryptoUtil.deriveLoginKey(keyEncryptionKey);
       final Uint8List identity = Uint8List.fromList(
         utf8.encode(srpAttributes.srpUserID),
       );
@@ -571,12 +573,16 @@ class UserService {
         final String twoFASessionID = response.data["twoFactorSessionID"];
         Configuration.instance.setVolatilePassword(userPassword);
         if (twoFASessionID.isNotEmpty) {
-
           page = TwoFactorAuthenticationPage(twoFASessionID);
         } else {
           await _saveConfiguration(response);
           if (Configuration.instance.getEncryptedToken() != null) {
-            page = const PasswordReentryPage();
+            await Configuration.instance.decryptSecretsAndGetKeyEncKey(
+              userPassword,
+              Configuration.instance.getKeyAttributes()!,
+              keyEncryptionKey: keyEncryptionKey,
+            );
+            page = const HomePage();
           } else {
             throw Exception("unexpected response during email verification");
           }