diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index b6b2d0487..9857e0b44 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -216,14 +216,17 @@ class Configuration { Future 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; diff --git a/lib/services/user_service.dart b/lib/services/user_service.dart index 2900e7cae..d93223d67 100644 --- a/lib/services/user_service.dart +++ b/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"); }