Skip to content

Commit

Permalink
add SpecialCircumstance to handle PasswordCredential intents
Browse files Browse the repository at this point in the history
  • Loading branch information
Nailik committed Oct 19, 2024
1 parent c2aaf28 commit ce65b7a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/src/main/java/com/x8bit/bitwarden/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ce65b7a

Please sign in to comment.