Skip to content

Commit

Permalink
[PM-15057] Rename Fido2CredentialRequest to Fido2CreateCredentialRequ…
Browse files Browse the repository at this point in the history
…est (#4362)
  • Loading branch information
SaintPatrck authored Nov 22, 2024
1 parent dbb006d commit 249dbda
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 170 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/x8bit/bitwarden/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class MainViewModel @Inject constructor(
fido2CredentialManager.isUserVerified = false
specialCircumstanceManager.specialCircumstance =
SpecialCircumstance.Fido2Save(
fido2CredentialRequest = fido2CredentialRequestData,
fido2CreateCredentialRequest = fido2CredentialRequestData,
)

// Switch accounts if the selected user is not the active user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.credentials.provider.CallingAppInfo
import com.bitwarden.vault.CipherView
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionResult
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2RegisterCredentialResult
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2ValidateOriginResult
import com.x8bit.bitwarden.data.autofill.fido2.model.PasskeyAssertionOptions
Expand Down Expand Up @@ -53,7 +53,7 @@ interface Fido2CredentialManager {
*/
suspend fun registerFido2Credential(
userId: String,
fido2CredentialRequest: Fido2CredentialRequest,
fido2CreateCredentialRequest: Fido2CreateCredentialRequest,
selectedCipherView: CipherView,
): Fido2RegisterCredentialResult

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.x8bit.bitwarden.data.autofill.fido2.datasource.network.model.DigitalA
import com.x8bit.bitwarden.data.autofill.fido2.datasource.network.service.DigitalAssetLinkService
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionResult
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2RegisterCredentialResult
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2ValidateOriginResult
import com.x8bit.bitwarden.data.autofill.fido2.model.PasskeyAssertionOptions
Expand Down Expand Up @@ -53,31 +53,31 @@ class Fido2CredentialManagerImpl(

override suspend fun registerFido2Credential(
userId: String,
fido2CredentialRequest: Fido2CredentialRequest,
fido2CreateCredentialRequest: Fido2CreateCredentialRequest,
selectedCipherView: CipherView,
): Fido2RegisterCredentialResult {
val clientData = if (fido2CredentialRequest.callingAppInfo.isOriginPopulated()) {
fido2CredentialRequest
val clientData = if (fido2CreateCredentialRequest.callingAppInfo.isOriginPopulated()) {
fido2CreateCredentialRequest
.callingAppInfo
.getAppSigningSignatureFingerprint()
?.let { ClientData.DefaultWithCustomHash(hash = it) }
?: return Fido2RegisterCredentialResult.Error
} else {
ClientData.DefaultWithExtraData(
androidPackageName = fido2CredentialRequest
androidPackageName = fido2CreateCredentialRequest
.callingAppInfo
.packageName,
)
}
val assetLinkUrl = fido2CredentialRequest
val assetLinkUrl = fido2CreateCredentialRequest
.origin
?: getOriginUrlFromAttestationOptionsOrNull(fido2CredentialRequest.requestJson)
?: getOriginUrlFromAttestationOptionsOrNull(fido2CreateCredentialRequest.requestJson)
?: return Fido2RegisterCredentialResult.Error

val origin = Origin.Android(
UnverifiedAssetLink(
packageName = fido2CredentialRequest.packageName,
sha256CertFingerprint = fido2CredentialRequest
packageName = fido2CreateCredentialRequest.packageName,
sha256CertFingerprint = fido2CreateCredentialRequest
.callingAppInfo
.getSignatureFingerprintAsHexString()
?: return Fido2RegisterCredentialResult.Error,
Expand All @@ -91,7 +91,7 @@ class Fido2CredentialManagerImpl(
request = RegisterFido2CredentialRequest(
userId = userId,
origin = origin,
requestJson = """{"publicKey": ${fido2CredentialRequest.requestJson}}""",
requestJson = """{"publicKey": ${fido2CreateCredentialRequest.requestJson}}""",
clientData = clientData,
selectedCipherView = selectedCipherView,
// User verification is handled prior to engaging the SDK. We always respond
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.parcelize.Parcelize
* @property callingAppInfo Information about the application that initiated the request.
*/
@Parcelize
data class Fido2CredentialRequest(
data class Fido2CreateCredentialRequest(
val userId: String,
val requestJson: String,
val packageName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import androidx.credentials.GetPublicKeyCredentialOption
import androidx.credentials.provider.BeginGetPublicKeyCredentialOption
import androidx.credentials.provider.PendingIntentHandler
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2GetCredentialsRequest
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
import com.x8bit.bitwarden.ui.platform.manager.intent.EXTRA_KEY_CIPHER_ID
import com.x8bit.bitwarden.ui.platform.manager.intent.EXTRA_KEY_CREDENTIAL_ID
import com.x8bit.bitwarden.ui.platform.manager.intent.EXTRA_KEY_USER_ID

/**
* Checks if this [Intent] contains a [Fido2CredentialRequest] related to an ongoing FIDO 2
* Checks if this [Intent] contains a [Fido2CreateCredentialRequest] related to an ongoing FIDO 2
* credential creation process.
*/
fun Intent.getFido2CredentialRequestOrNull(): Fido2CredentialRequest? {
fun Intent.getFido2CredentialRequestOrNull(): Fido2CreateCredentialRequest? {
if (isBuildVersionBelow(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)) return null

val systemRequest = PendingIntentHandler
Expand All @@ -33,7 +33,7 @@ fun Intent.getFido2CredentialRequestOrNull(): Fido2CredentialRequest? {
val userId = getStringExtra(EXTRA_KEY_USER_ID)
?: return null

return Fido2CredentialRequest(
return Fido2CreateCredentialRequest(
userId = userId,
requestJson = createPublicKeyRequest.requestJson,
packageName = systemRequest.callingAppInfo.packageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.x8bit.bitwarden.data.platform.manager.model

import android.os.Parcelable
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
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
Expand Down Expand Up @@ -65,7 +65,7 @@ sealed class SpecialCircumstance : Parcelable {
*/
@Parcelize
data class Fido2Save(
val fido2CredentialRequest: Fido2CredentialRequest,
val fido2CreateCredentialRequest: Fido2CreateCredentialRequest,
) : SpecialCircumstance()

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.x8bit.bitwarden.data.platform.manager.util

import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
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
Expand All @@ -27,11 +27,11 @@ fun SpecialCircumstance.toAutofillSelectionDataOrNull(): AutofillSelectionData?
}

/**
* Returns [Fido2CredentialRequest] when contained in the given [SpecialCircumstance].
* Returns [Fido2CreateCredentialRequest] when contained in the given [SpecialCircumstance].
*/
fun SpecialCircumstance.toFido2RequestOrNull(): Fido2CredentialRequest? =
fun SpecialCircumstance.toFido2RequestOrNull(): Fido2CreateCredentialRequest? =
when (this) {
is SpecialCircumstance.Fido2Save -> this.fido2CredentialRequest
is SpecialCircumstance.Fido2Save -> this.fido2CreateCredentialRequest
else -> null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.x8bit.bitwarden.data.auth.repository.model.AuthState
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.auth.repository.util.parseJwtTokenDataOrNull
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
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
Expand Down Expand Up @@ -133,7 +133,7 @@ class RootNavViewModel @Inject constructor(
is SpecialCircumstance.Fido2Save -> {
RootNavState.VaultUnlockedForFido2Save(
activeUserId = userState.activeUserId,
fido2CredentialRequest = specialCircumstance.fido2CredentialRequest,
fido2CreateCredentialRequest = specialCircumstance.fido2CreateCredentialRequest,
)
}

Expand Down Expand Up @@ -286,12 +286,12 @@ sealed class RootNavState : Parcelable {
*
* @param activeUserId ID of the active user. Indirectly used to notify [RootNavViewModel] the
* active user has changed.
* @param fido2CredentialRequest System request containing FIDO credential data.
* @param fido2CreateCredentialRequest System request containing FIDO credential data.
*/
@Parcelize
data class VaultUnlockedForFido2Save(
val activeUserId: String,
val fido2CredentialRequest: Fido2CredentialRequest,
val fido2CreateCredentialRequest: Fido2CreateCredentialRequest,
) : RootNavState()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.x8bit.bitwarden.data.auth.repository.model.ValidatePasswordResult
import com.x8bit.bitwarden.data.auth.repository.model.ValidatePinResult
import com.x8bit.bitwarden.data.auth.repository.model.VaultUnlockType
import com.x8bit.bitwarden.data.autofill.fido2.manager.Fido2CredentialManager
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2RegisterCredentialResult
import com.x8bit.bitwarden.data.autofill.fido2.model.UserVerificationRequirement
import com.x8bit.bitwarden.data.autofill.util.isActiveWithFido2Credentials
Expand Down Expand Up @@ -449,7 +449,7 @@ class VaultAddEditViewModel @Inject constructor(
}

private fun handleFido2RequestSpecialCircumstance(
request: Fido2CredentialRequest,
request: Fido2CreateCredentialRequest,
cipherView: CipherView,
) {
if (cipherView.isActiveWithFido2Credentials) {
Expand All @@ -462,7 +462,7 @@ class VaultAddEditViewModel @Inject constructor(
}

private fun registerFido2Credential(
request: Fido2CredentialRequest,
request: Fido2CreateCredentialRequest,
cipherView: CipherView,
) {

Expand Down Expand Up @@ -494,7 +494,7 @@ class VaultAddEditViewModel @Inject constructor(
}

private fun registerFido2CredentialToCipher(
request: Fido2CredentialRequest,
request: Fido2CreateCredentialRequest,
cipherView: CipherView,
) {
viewModelScope.launch {
Expand All @@ -506,7 +506,7 @@ class VaultAddEditViewModel @Inject constructor(
val result: Fido2RegisterCredentialResult =
fido2CredentialManager.registerFido2Credential(
userId = userId,
fido2CredentialRequest = request,
fido2CreateCredentialRequest = request,
selectedCipherView = cipherView,
)
sendAction(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.x8bit.bitwarden.ui.vault.feature.addedit.util

import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.PasskeyAttestationOptions
import com.x8bit.bitwarden.data.platform.util.toUriOrNull
import com.x8bit.bitwarden.ui.platform.base.util.toAndroidAppUriString
Expand All @@ -12,7 +12,7 @@ import java.util.UUID
* Returns pre-filled content that may be used for an "add" type
* [VaultAddEditState.ViewState.Content] during FIDO 2 credential creation.
*/
fun Fido2CredentialRequest.toDefaultAddTypeContent(
fun Fido2CreateCredentialRequest.toDefaultAddTypeContent(
attestationOptions: PasskeyAttestationOptions?,
isIndividualVaultDisabled: Boolean,
): VaultAddEditState.ViewState.Content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilitySele
import com.x8bit.bitwarden.data.autofill.fido2.manager.Fido2CredentialManager
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialAssertionResult
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2CreateCredentialRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2GetCredentialsRequest
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2GetCredentialsResult
import com.x8bit.bitwarden.data.autofill.fido2.model.Fido2RegisterCredentialResult
Expand Down Expand Up @@ -133,7 +133,7 @@ class VaultItemListingViewModel @Inject constructor(
autofillSelectionData = specialCircumstance?.toAutofillSelectionDataOrNull(),
hasMasterPassword = userState.activeAccount.hasMasterPassword,
totpData = specialCircumstance?.toTotpDataOrNull(),
fido2CredentialRequest = fido2CredentialRequest,
fido2CreateCredentialRequest = fido2CredentialRequest,
fido2CredentialAssertionRequest = specialCircumstance?.toFido2AssertionRequestOrNull(),
fido2GetCredentialsRequest = specialCircumstance?.toFido2GetCredentialsRequestOrNull(),
isPremium = userState.activeAccount.isPremium,
Expand All @@ -156,7 +156,7 @@ class VaultItemListingViewModel @Inject constructor(

viewModelScope.launch {
state
.fido2CredentialRequest
.fido2CreateCredentialRequest
?.let { request ->
sendAction(
VaultItemListingsAction.Internal.Fido2RegisterCredentialRequestReceive(
Expand Down Expand Up @@ -625,7 +625,7 @@ class VaultItemListingViewModel @Inject constructor(

private fun registerFido2Credential(cipherView: CipherView) {
val credentialRequest = state
.fido2CredentialRequest
.fido2CreateCredentialRequest
?: run {
// This scenario should not occur because `isFido2Creation` is false when
// `fido2CredentialRequest` is null. We show the FIDO 2 error dialog to inform
Expand Down Expand Up @@ -653,7 +653,7 @@ class VaultItemListingViewModel @Inject constructor(
}

private fun performUserVerificationIfRequired(
credentialRequest: Fido2CredentialRequest,
credentialRequest: Fido2CreateCredentialRequest,
cipherView: CipherView,
) {
val attestationOptions = fido2CredentialManager
Expand Down Expand Up @@ -691,7 +691,7 @@ class VaultItemListingViewModel @Inject constructor(
}

private fun registerFido2CredentialToCipher(
request: Fido2CredentialRequest,
request: Fido2CreateCredentialRequest,
cipherView: CipherView,
) {
val activeUserId = authRepository.activeUserId
Expand All @@ -703,7 +703,7 @@ class VaultItemListingViewModel @Inject constructor(
val result: Fido2RegisterCredentialResult =
fido2CredentialManager.registerFido2Credential(
userId = activeUserId,
fido2CredentialRequest = request,
fido2CreateCredentialRequest = request,
selectedCipherView = cipherView,
)
sendAction(
Expand Down Expand Up @@ -826,7 +826,7 @@ class VaultItemListingViewModel @Inject constructor(
private fun handleDismissFido2ErrorDialogClick() {
clearDialogState()
when {
state.fido2CredentialRequest != null -> {
state.fido2CreateCredentialRequest != null -> {
sendEvent(
VaultItemListingEvent.CompleteFido2Registration(
result = Fido2RegisterCredentialResult.Error,
Expand Down Expand Up @@ -1575,7 +1575,7 @@ class VaultItemListingViewModel @Inject constructor(
baseIconUrl = state.baseIconUrl,
isIconLoadingDisabled = state.isIconLoadingDisabled,
autofillSelectionData = state.autofillSelectionData,
fido2CreationData = state.fido2CredentialRequest,
fido2CreationData = state.fido2CreateCredentialRequest,
fido2CredentialAutofillViews = vaultData
.fido2CredentialAutofillViewList,
totpData = state.totpData,
Expand Down Expand Up @@ -1636,7 +1636,7 @@ class VaultItemListingViewModel @Inject constructor(
*/
@Suppress("MaxLineLength")
private suspend fun DataState<VaultData>.filterForFido2CreationIfNecessary(): DataState<VaultData> {
val request = state.fido2CredentialRequest ?: return this
val request = state.fido2CreateCredentialRequest ?: return this
return this.map { vaultData ->
val matchUri = request.origin
?: request.packageName
Expand Down Expand Up @@ -1739,7 +1739,7 @@ data class VaultItemListingState(
private val isPullToRefreshSettingEnabled: Boolean,
val totpData: TotpData? = null,
val autofillSelectionData: AutofillSelectionData? = null,
val fido2CredentialRequest: Fido2CredentialRequest? = null,
val fido2CreateCredentialRequest: Fido2CreateCredentialRequest? = null,
val fido2CredentialAssertionRequest: Fido2CredentialAssertionRequest? = null,
val fido2GetCredentialsRequest: Fido2GetCredentialsRequest? = null,
val hasMasterPassword: Boolean,
Expand All @@ -1763,7 +1763,7 @@ data class VaultItemListingState(
* Whether or not this represents a listing screen for FIDO2 creation.
*/
val isFido2Creation: Boolean
get() = fido2CredentialRequest != null
get() = fido2CreateCredentialRequest != null

/**
* Whether or not this represents a listing screen for totp.
Expand All @@ -1778,7 +1778,7 @@ data class VaultItemListingState(
?.uri
?.toHostOrPathOrNull()
?.let { R.string.items_for_uri.asText(it) }
?: fido2CredentialRequest
?: fido2CreateCredentialRequest
?.callingAppInfo
?.getFido2RpIdOrNull()
?.let { R.string.items_for_uri.asText(it) }
Expand Down Expand Up @@ -2549,7 +2549,7 @@ sealed class VaultItemListingsAction {
* Indicates that a FIDO 2 credential registration has been received.
*/
data class Fido2RegisterCredentialRequestReceive(
val request: Fido2CredentialRequest,
val request: Fido2CreateCredentialRequest,
) : Internal()

/**
Expand Down
Loading

0 comments on commit 249dbda

Please sign in to comment.