Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(e2ei): download certificate name (WPB-8606) #2961

Merged
merged 7 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,18 +78,20 @@ 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
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.deviceDateTimeFormat
import com.wire.android.util.dialogErrorStrings
import com.wire.android.util.extension.formatAsFingerPrint
import com.wire.android.util.extension.formatAsString
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,21 +119,21 @@ fun DeviceDetailsScreen(
handleE2EIEnrollmentResult = viewModel::handleE2EIEnrollmentResult,
onNavigateToE2eiCertificateDetailsScreen = {
navigator.navigate(
NavigationCommand(E2eiCertificateDetailsScreenDestination(it))
NavigationCommand(E2eiCertificateDetailsScreenDestination(E2EICertificateDetails.AfterLoginCertificateDetails(it)))
)
},
onEnrollE2EIErrorDismiss = viewModel::hideEnrollE2EICertificateError,
onEnrollE2EISuccessDismiss = viewModel::hideEnrollE2EICertificateSuccess
)
}
}

@Suppress("ComplexMethod")
@Composable
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 @@ -20,9 +20,7 @@ package com.wire.android.ui.settings.devices.model
import com.wire.android.ui.authentication.devices.model.Device
import com.wire.android.ui.authentication.devices.remove.RemoveDeviceDialogState
import com.wire.android.ui.authentication.devices.remove.RemoveDeviceError
import com.wire.kalium.logic.feature.e2ei.CertificateStatus
import com.wire.kalium.logic.feature.e2ei.E2eiCertificate
import kotlinx.datetime.Instant

data class DeviceDetailsState(
val device: Device = Device(),
Expand All @@ -33,12 +31,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
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 25 files
+4 −4 cryptography/src/androidInstrumentedTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt
+4 −4 cryptography/src/androidUnitTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt
+8 −4 cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt
+4 −4 cryptography/src/appleTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt
+4 −3 cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/CoreCryptoCentral.kt
+1 −1 cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentral.kt
+2 −2 cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt
+6 −4 cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt
+3 −2 cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/MLSClientTest.kt
+1 −1 cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/CoreCryptoCentralImpl.kt
+2 −2 cryptography/src/jsTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt
+4 −4 cryptography/src/jvmTest/kotlin/com/wire/kalium/cryptography/BaseMLSClientTest.kt
+3 −2 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallRepository.kt
+1 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/MLSClientProvider.kt
+1 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ProteusClientProvider.kt
+3 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/di/MapperProvider.kt
+8 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/E2eiCertificate.kt
+2 −4 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetE2EICertificateUseCase.kt
+4 −6 ...rc/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetMembersE2EICertificateStatusesUseCase.kt
+1 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetUserE2EIAllCertificatesUseCase.kt
+1 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetUserE2EICertificateUseCase.kt
+2 −4 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UserScope.kt
+2 −0 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/client/ObserveE2EIRequiredUseCaseTest.kt
+2 −7 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/GetE2eiCertificateUseCaseTest.kt
+1 −2 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/GetMembersE2EICertificateStatusesUseCaseTest.kt
Loading