diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/exception/OutOfMemoryKdfException.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/exception/OutOfMemoryKdfException.kt new file mode 100644 index 00000000..bdfadca7 --- /dev/null +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/exception/OutOfMemoryKdfException.kt @@ -0,0 +1,12 @@ +package com.artemchep.keyguard.common.exception + +import com.artemchep.keyguard.res.Res +import dev.icerock.moko.resources.StringResource + +open class OutOfMemoryKdfException( + m: String?, + e: Throwable?, +) : Exception(m, e), Readable { + override val title: StringResource + get() = Res.strings.error_failed_generate_kdf_hash_oom +} diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/api/login.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/api/login.kt index dca94a38..c3654aa0 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/api/login.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/api/login.kt @@ -1,5 +1,6 @@ package com.artemchep.keyguard.provider.bitwarden.api +import com.artemchep.keyguard.common.exception.OutOfMemoryKdfException import com.artemchep.keyguard.common.io.bind import com.artemchep.keyguard.common.model.Argon2Mode import com.artemchep.keyguard.common.service.crypto.CryptoGenerator @@ -234,11 +235,23 @@ private fun generateSecrets( .lowercase(Locale.ENGLISH) .toByteArray() - val masterKey = cryptoGenerator.masterKeyHash( - seed = passwordBytes, - salt = emailBytes, - config = hashConfig, - ) + val masterKey = runCatching { + cryptoGenerator.masterKeyHash( + seed = passwordBytes, + salt = emailBytes, + config = hashConfig, + ) + }.getOrElse { e -> + if (e is OutOfMemoryError) { + val newError = OutOfMemoryKdfException( + m = e.localizedMessage ?: e.message, + e = e, + ) + throw newError + } + + throw e + } val passwordKey = cryptoGenerator.pbkdf2( seed = masterKey, salt = passwordBytes, diff --git a/common/src/commonMain/resources/MR/base/strings.xml b/common/src/commonMain/resources/MR/base/strings.xml index 3acbfcac..1f9ddba9 100644 --- a/common/src/commonMain/resources/MR/base/strings.xml +++ b/common/src/commonMain/resources/MR/base/strings.xml @@ -399,6 +399,7 @@ Invalid URI Invalid card number Incorrect password + Failed to create a key, out of memory. Please check your KDF server settings. Failed to generate OTP code Failed to create a passkey Failed to authorize a request