Skip to content

Commit

Permalink
fix(e2ei): set correct user handle in the downloaded certificate name
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed May 3, 2024
1 parent a6846f1 commit f2a63e9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 21 deletions.
11 changes: 10 additions & 1 deletion app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import com.wire.android.ui.legalhold.dialog.deactivated.LegalHoldDeactivatedView
import com.wire.android.ui.legalhold.dialog.requested.LegalHoldRequestedDialog
import com.wire.android.ui.legalhold.dialog.requested.LegalHoldRequestedState
import com.wire.android.ui.legalhold.dialog.requested.LegalHoldRequestedViewModel
import com.wire.android.ui.settings.devices.e2ei.E2EICertificateDetails
import com.wire.android.ui.theme.ThemeOption
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.userprofile.self.dialog.LogoutOptionsDialog
Expand Down Expand Up @@ -388,7 +389,15 @@ class WireActivity : AppCompatActivity() {
result = e2EIResult,
updateCertificate = featureFlagNotificationViewModel::enrollE2EICertificate,
snoozeDialog = featureFlagNotificationViewModel::snoozeE2EIdRequiredDialog,
openCertificateDetails = { navigate(NavigationCommand(E2eiCertificateDetailsScreenDestination(it))) },
openCertificateDetails = {
navigate(
NavigationCommand(
E2eiCertificateDetailsScreenDestination(
E2EICertificateDetails.DuringLoginCertificateDetails(it)
)
)
)
},
dismissSuccessDialog = featureFlagNotificationViewModel::dismissSuccessE2EIdDialog,
isE2EILoading = isE2EILoading
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import com.wire.android.ui.destinations.InitialSyncScreenDestination
import com.wire.android.ui.home.E2EIEnrollmentErrorWithDismissDialog
import com.wire.android.ui.home.E2EISuccessDialog
import com.wire.android.ui.markdown.MarkdownConstants
import com.wire.android.ui.settings.devices.e2ei.E2EICertificateDetails
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
Expand Down Expand Up @@ -89,7 +90,15 @@ fun E2EIEnrollmentScreen(
enrollE2EICertificate = viewModel::enrollE2EICertificate,
handleE2EIEnrollmentResult = viewModel::handleE2EIEnrollmentResult,
openCertificateDetails = {
navigator.navigate(NavigationCommand(E2eiCertificateDetailsScreenDestination(state.certificate)))
navigator.navigate(
NavigationCommand(
E2eiCertificateDetailsScreenDestination(
E2EICertificateDetails.DuringLoginCertificateDetails(
state.certificate
)
)
)
)
},
onBackButtonClicked = viewModel::onBackButtonClicked,
onCancelEnrollmentClicked = { viewModel.onCancelEnrollmentClicked(NavigationSwitchAccountActions(navigator::navigate)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import com.wire.android.ui.e2eiEnrollment.GetE2EICertificateUI
import com.wire.android.ui.home.E2EISuccessDialog
import com.wire.android.ui.home.E2EIUpdateErrorWithDismissDialog
import com.wire.android.ui.home.conversationslist.common.FolderHeader
import com.wire.android.ui.settings.devices.e2ei.E2EICertificateDetails
import com.wire.android.ui.settings.devices.model.DeviceDetailsState
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions
Expand All @@ -90,6 +91,7 @@ import com.wire.android.util.deviceDateTimeFormat
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.feature.e2ei.E2eiCertificate
import com.wire.kalium.logic.feature.e2ei.usecase.E2EIEnrollmentResult
import com.wire.kalium.logic.functional.Either

Expand Down Expand Up @@ -117,7 +119,7 @@ fun DeviceDetailsScreen(
handleE2EIEnrollmentResult = viewModel::handleE2EIEnrollmentResult,
onNavigateToE2eiCertificateDetailsScreen = {
navigator.navigate(
NavigationCommand(E2eiCertificateDetailsScreenDestination(it))
NavigationCommand(E2eiCertificateDetailsScreenDestination(E2EICertificateDetails.AfterLoginCertificateDetails(it)))
)
},
onEnrollE2EIErrorDismiss = viewModel::hideEnrollE2EICertificateError,
Expand All @@ -131,7 +133,7 @@ fun DeviceDetailsContent(
state: DeviceDetailsState,
onDeleteDevice: () -> Unit = {},
onNavigateBack: () -> Unit = {},
onNavigateToE2eiCertificateDetailsScreen: (String) -> Unit = {},
onNavigateToE2eiCertificateDetailsScreen: (E2eiCertificate) -> Unit = {},
onPasswordChange: (TextFieldValue) -> Unit = {},
onRemoveConfirm: () -> Unit = {},
onDialogDismiss: () -> Unit = {},
Expand Down Expand Up @@ -192,7 +194,7 @@ fun DeviceDetailsContent(
}
}

if (state.isE2EIEnabled) {
if (state.isE2EIEnabled && state.e2eiCertificate !=null) {
item {
EndToEndIdentityCertificateItem(
isE2eiCertificateActivated = state.isE2eiCertificateActivated,
Expand Down Expand Up @@ -286,9 +288,9 @@ fun DeviceDetailsContent(
)
}

if (state.isE2EICertificateEnrollSuccess) {
if (state.isE2EICertificateEnrollSuccess && state.e2eiCertificate !=null) {
E2EISuccessDialog(
openCertificateDetails = { onNavigateToE2eiCertificateDetailsScreen(state.e2eiCertificate.certificateDetail) },
openCertificateDetails = { onNavigateToE2eiCertificateDetailsScreen(state.e2eiCertificate) },
dismissDialog = onEnrollE2EISuccessDismiss
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun EndToEndIdentityCertificateItem(
isCurrentDevice: Boolean,
isLoadingCertificate: Boolean,
enrollE2eiCertificate: () -> Unit,
showCertificate: (String) -> Unit
showCertificate: (E2eiCertificate) -> Unit
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -124,7 +124,7 @@ fun EndToEndIdentityCertificateItem(
enabled = true,
isLoading = false,
onShowCertificateClicked = {
showCertificate(certificate.certificateDetail)
showCertificate(certificate)
}
)
} else {
Expand Down Expand Up @@ -199,9 +199,11 @@ fun PreviewEndToEndIdentityCertificateItem() {
isE2eiCertificateActivated = true,
isCurrentDevice = false,
certificate = E2eiCertificate(
userHandle = "userHandle",
status = CertificateStatus.VALID,
serialNumber = "e5:d5:e6:75:7e:04:86:07:14:3c:a0:ed:9a:8d:e4:fd",
certificateDetail = "",
thumbprint = "thumbprint",
endAt = Instant.DISTANT_FUTURE
),
isLoadingCertificate = false,
Expand All @@ -217,9 +219,11 @@ fun PreviewEndToEndIdentityCertificateSelfItem() {
isE2eiCertificateActivated = true,
isCurrentDevice = true,
certificate = E2eiCertificate(
userHandle = "userHandle",
status = CertificateStatus.VALID,
serialNumber = "e5:d5:e6:75:7e:04:86:07:14:3c:a0:ed:9a:8d:e4:fd",
certificateDetail = "",
thumbprint = "thumbprint",
endAt = Instant.DISTANT_FUTURE
),
isLoadingCertificate = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
package com.wire.android.ui.settings.devices.e2ei

data class E2eiCertificateDetailsScreenNavArgs(
val certificateString: String
)
import com.wire.kalium.logic.feature.e2ei.E2eiCertificate
import kotlinx.serialization.Serializable

data class E2eiCertificateDetailsScreenNavArgs(val certificateDetails: E2EICertificateDetails)

@Serializable
sealed class E2EICertificateDetails() {
data class AfterLoginCertificateDetails(val certificate: E2eiCertificate) : E2EICertificateDetails()
data class DuringLoginCertificateDetails(val certificate: String) : E2EICertificateDetails()
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class E2eiCertificateDetailsViewModel @Inject constructor(
var state: E2eiCertificateDetailsState by mutableStateOf(E2eiCertificateDetailsState())
private set

private val e2eiCertificateDetailsScreenNavArgs: E2eiCertificateDetailsScreenNavArgs =
private val navArgs: E2eiCertificateDetailsScreenNavArgs =
savedStateHandle.navArgs()

private var selfUserHandle: String? = null
Expand All @@ -57,11 +57,27 @@ class E2eiCertificateDetailsViewModel @Inject constructor(
}
}

fun getCertificate() = e2eiCertificateDetailsScreenNavArgs.certificateString
fun getCertificate() =
when (navArgs.certificateDetails) {
is E2EICertificateDetails.DuringLoginCertificateDetails ->
navArgs.certificateDetails.certificate

is E2EICertificateDetails.AfterLoginCertificateDetails ->
navArgs.certificateDetails.certificate.certificateDetail
}

fun userHandle() =
when (navArgs.certificateDetails) {
is E2EICertificateDetails.DuringLoginCertificateDetails ->
selfUserHandle

is E2EICertificateDetails.AfterLoginCertificateDetails ->
navArgs.certificateDetails.certificate.userHandle
}

fun getCertificateName(): String {
val date = DateTimeUtil.currentInstant().fileDateTime()
return "wire-certificate-$selfUserHandle-$date.txt"
return "wire-certificate-${userHandle()}-$date.txt"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ data class DeviceDetailsState(
val isSelfClient: Boolean = false,
val userName: String? = null,
val isE2eiCertificateActivated: Boolean = false,
val e2eiCertificate: E2eiCertificate = E2eiCertificate(
status = CertificateStatus.EXPIRED,
serialNumber = "",
certificateDetail = "",
endAt = Instant.DISTANT_FUTURE
),
val e2eiCertificate: E2eiCertificate? = null,
val canBeRemoved: Boolean = false,
val isLoadingCertificate: Boolean = false,
val isE2EICertificateEnrollSuccess: Boolean = false,
Expand Down

0 comments on commit f2a63e9

Please sign in to comment.