Skip to content

Commit

Permalink
BITAU-200 Log non-fatal authenticator bridge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaisting-livefront committed Nov 4, 2024
1 parent 8f9585e commit 74f7c49
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
import com.x8bit.bitwarden.data.platform.manager.model.FlagKey
import com.x8bit.bitwarden.data.platform.repository.AuthenticatorBridgeRepository
import com.x8bit.bitwarden.data.platform.util.AuthenticatorBridgeException
import com.x8bit.bitwarden.data.platform.util.createAddTotpItemFromAuthenticatorIntent
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].
Expand Down Expand Up @@ -93,7 +95,13 @@ class AuthenticatorBridgeProcessorImpl(
}

override fun syncAccounts() {
val symmetricEncryptionKey = symmetricEncryptionKeyData ?: return
val symmetricEncryptionKey = symmetricEncryptionKeyData ?: run {
Timber.e(
t = AuthenticatorBridgeException(),
message = "Unable to sync accounts when symmetricEncryptionKeyData is null.",
)
return
}
scope.launch {
// Encrypt the shared account data with the symmetric key:
val encryptedSharedAccountData = authenticatorBridgeRepository
Expand All @@ -110,14 +118,33 @@ class AuthenticatorBridgeProcessorImpl(
}

override fun startAddTotpLoginItemFlow(data: EncryptedAddTotpLoginItemData): Boolean {
val symmetricEncryptionKey = symmetricEncryptionKeyData ?: return false
val symmetricEncryptionKey = symmetricEncryptionKeyData ?: run {
Timber.e(
t = AuthenticatorBridgeException(),
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 = AuthenticatorBridgeException(),
message = "Unable to decrypt TOTP data.",
)
}
.getOrNull()
?.totpUri
?.toUri()
?.getTotpDataOrNull()
?: return false
?: run {
Timber.e(
t = AuthenticatorBridgeException(),
message = "Unable to parse TOTP URI.",
)
return false
}
addTotpItemFromAuthenticatorManager.pendingAddTotpLoginItemData = totpData
applicationContext.startActivity(intent)
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.x8bit.bitwarden.data.platform.util

/**
* Represents a non-fatal authenticator bridge exception.
*/
class AuthenticatorBridgeException : Exception()

0 comments on commit 74f7c49

Please sign in to comment.