From c3473b918d8e7c503b85c730a6ca8d0ad9895ec0 Mon Sep 17 00:00:00 2001 From: Nailik <13292441+Nailik@users.noreply.github.com> Date: Sat, 19 Oct 2024 19:17:35 +0200 Subject: [PATCH] add SpecialCircumstance to handle PasswordCredential intents --- .../java/com/x8bit/bitwarden/MainViewModel.kt | 38 +++++++++++++++++++ .../manager/model/SpecialCircumstance.kt | 30 +++++++++++++++ .../feature/rootnav/RootNavViewModel.kt | 4 ++ 3 files changed, 72 insertions(+) diff --git a/app/src/main/java/com/x8bit/bitwarden/MainViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/MainViewModel.kt index 25145b40eb7..2e2d1b6c5dd 100644 --- a/app/src/main/java/com/x8bit/bitwarden/MainViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/MainViewModel.kt @@ -15,6 +15,9 @@ import com.x8bit.bitwarden.data.autofill.fido2.util.getFido2AssertionRequestOrNu import com.x8bit.bitwarden.data.autofill.fido2.util.getFido2CredentialRequestOrNull import com.x8bit.bitwarden.data.autofill.fido2.util.getFido2GetCredentialsRequestOrNull import com.x8bit.bitwarden.data.autofill.manager.AutofillSelectionManager +import com.x8bit.bitwarden.data.autofill.password.util.getPasswordAssertionRequestOrNull +import com.x8bit.bitwarden.data.autofill.password.util.getPasswordCredentialRequestOrNull +import com.x8bit.bitwarden.data.autofill.password.util.getPasswordGetCredentialsRequestOrNull import com.x8bit.bitwarden.data.autofill.util.getAutofillSaveItemOrNull import com.x8bit.bitwarden.data.autofill.util.getAutofillSelectionDataOrNull import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager @@ -242,6 +245,9 @@ class MainViewModel @Inject constructor( val completeRegistrationData = intent.getCompleteRegistrationDataIntentOrNull() val fido2CredentialAssertionRequest = intent.getFido2AssertionRequestOrNull() val fido2GetCredentialsRequest = intent.getFido2GetCredentialsRequestOrNull() + val passwordCredentialRequestData = intent.getPasswordCredentialRequestOrNull() + val passwordCredentialAssertionRequest = intent.getPasswordAssertionRequestOrNull() + val passwordGetCredentialsRequest = intent.getPasswordGetCredentialsRequestOrNull() when { passwordlessRequestData != null -> { if (authRepository.activeUserId != passwordlessRequestData.userId) { @@ -324,6 +330,38 @@ class MainViewModel @Inject constructor( ) } + passwordCredentialRequestData != null -> { + // Set the user's verification status when a new FIDO 2 request is received to force + // explicit verification if the user's vault is unlocked when the request is + // received. + fido2CredentialManager.isUserVerified = false + specialCircumstanceManager.specialCircumstance = + SpecialCircumstance.PasswordSave( + passwordCredentialRequest = passwordCredentialRequestData, + ) + + // Switch accounts if the selected user is not the active user. + if (authRepository.activeUserId != null && + authRepository.activeUserId != passwordCredentialRequestData.userId + ) { + authRepository.switchAccount(passwordCredentialRequestData.userId) + } + } + + passwordCredentialAssertionRequest != null -> { + specialCircumstanceManager.specialCircumstance = + SpecialCircumstance.PasswordAssertion( + passwordAssertionRequest = passwordCredentialAssertionRequest, + ) + } + + passwordGetCredentialsRequest != null -> { + specialCircumstanceManager.specialCircumstance = + SpecialCircumstance.PasswordGetCredentials( + passwordGetCredentialsRequest = passwordGetCredentialsRequest, + ) + } + hasGeneratorShortcut -> { specialCircumstanceManager.specialCircumstance = SpecialCircumstance.GeneratorShortcut diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/manager/model/SpecialCircumstance.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/manager/model/SpecialCircumstance.kt index 969115a43a4..fcc08885fc3 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/manager/model/SpecialCircumstance.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/manager/model/SpecialCircumstance.kt @@ -6,6 +6,9 @@ import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2GetCredentialsRequest import com.x8bit.bitwarden.data.autofill.model.AutofillSaveItem import com.x8bit.bitwarden.data.autofill.model.AutofillSelectionData +import com.x8bit.bitwarden.data.autofill.password.model.PasswordCredentialAssertionRequest +import com.x8bit.bitwarden.data.autofill.password.model.PasswordCredentialRequest +import com.x8bit.bitwarden.data.autofill.password.model.PasswordGetCredentialsRequest import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager import com.x8bit.bitwarden.ui.vault.model.TotpData import kotlinx.parcelize.Parcelize @@ -86,6 +89,33 @@ sealed class SpecialCircumstance : Parcelable { val fido2GetCredentialsRequest: Fido2GetCredentialsRequest, ) : SpecialCircumstance() + /** + * The app was launched via the credential manager framework in order to allow the user to + * manually save a password to their vault. + */ + @Parcelize + data class PasswordSave( + val passwordCredentialRequest: PasswordCredentialRequest, + ) : SpecialCircumstance() + + /** + * The app was launched via the credential manager framework in order to authenticate a Password + * credential saved to the user's vault. + */ + @Parcelize + data class PasswordAssertion( + val passwordAssertionRequest: PasswordCredentialAssertionRequest, + ) : SpecialCircumstance() + + /** + * The app was launched via the credential manager framework request to retrieve passwords + * associated with the requesting entity. + */ + @Parcelize + data class PasswordGetCredentials( + val passwordGetCredentialsRequest: PasswordGetCredentialsRequest, + ) : SpecialCircumstance() + /** * The app was launched via deeplink to the generator. */ diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavViewModel.kt index 74716bcafe1..a58306fa4e9 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavViewModel.kt @@ -151,6 +151,10 @@ class RootNavViewModel @Inject constructor( ) } + is SpecialCircumstance.PasswordAssertion -> TODO() + is SpecialCircumstance.PasswordGetCredentials -> TODO() + is SpecialCircumstance.PasswordSave -> TODO() + SpecialCircumstance.AccountSecurityShortcut, SpecialCircumstance.GeneratorShortcut, SpecialCircumstance.VaultShortcut,