From c6beaec102e47550855160da12fd37ac8fae4ca1 Mon Sep 17 00:00:00 2001 From: Andrew Haisting <142518658+ahaisting-livefront@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:15:21 -0600 Subject: [PATCH] BITAU-200 Log non-fatal authenticator bridge errors (#4228) Co-authored-by: Patrick Honkonen --- .../AuthenticatorBridgeProcessorImpl.kt | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/AuthenticatorBridgeProcessorImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/AuthenticatorBridgeProcessorImpl.kt index 29df0ed42..97e7c11f1 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/AuthenticatorBridgeProcessorImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/processor/AuthenticatorBridgeProcessorImpl.kt @@ -25,6 +25,7 @@ import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow import com.x8bit.bitwarden.ui.vault.util.getTotpDataOrNull import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch +import timber.log.Timber /** * Default implementation of [AuthenticatorBridgeProcessor]. @@ -93,7 +94,13 @@ class AuthenticatorBridgeProcessorImpl( } override fun syncAccounts() { - val symmetricEncryptionKey = symmetricEncryptionKeyData ?: return + val symmetricEncryptionKey = symmetricEncryptionKeyData ?: run { + Timber.e( + t = IllegalStateException(), + message = "Unable to sync accounts when symmetricEncryptionKeyData is null.", + ) + return + } scope.launch { // Encrypt the shared account data with the symmetric key: val encryptedSharedAccountData = authenticatorBridgeRepository @@ -110,14 +117,31 @@ class AuthenticatorBridgeProcessorImpl( } override fun startAddTotpLoginItemFlow(data: EncryptedAddTotpLoginItemData): Boolean { - val symmetricEncryptionKey = symmetricEncryptionKeyData ?: return false + val symmetricEncryptionKey = symmetricEncryptionKeyData ?: run { + Timber.e( + t = IllegalStateException(), + message = "Unable to start add TOTP item flow when " + + "symmetricEncryptionKeyData is null.", + ) + return false + } val intent = createAddTotpItemFromAuthenticatorIntent(context = applicationContext) val totpData = data.decrypt(symmetricEncryptionKey) + .onFailure { + Timber.e(t = it, message = "Unable to decrypt TOTP data.") + return false + } .getOrNull() ?.totpUri ?.toUri() ?.getTotpDataOrNull() - ?: return false + ?: run { + Timber.e( + t = IllegalStateException(), + message = "Unable to parse TOTP URI.", + ) + return false + } addTotpItemFromAuthenticatorManager.pendingAddTotpLoginItemData = totpData applicationContext.startActivity(intent) return true