Skip to content

Commit

Permalink
Merge branch 'release/candidate' into periodically_check_revocation_list
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine authored Jan 25, 2024
2 parents 2e06132 + a4a5d14 commit c033b70
Show file tree
Hide file tree
Showing 28 changed files with 791 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ interface UserConfigRepository {
suspend fun setCRLExpirationTime(url: String, timestamp: ULong)
suspend fun getCRLExpirationTime(url: String): ULong?
suspend fun observeCertificateExpirationTime(url: String): Flow<Either<StorageFailure, ULong>>
suspend fun setShouldNotifyForRevokedCertificate(shouldNotify: Boolean)
suspend fun observeShouldNotifyForRevokedCertificate(): Flow<Either<StorageFailure, Boolean>>
}

@Suppress("TooManyFunctions")
Expand Down Expand Up @@ -447,4 +449,10 @@ internal class UserConfigDataSource internal constructor(

override suspend fun observeCertificateExpirationTime(url: String): Flow<Either<StorageFailure, ULong>> =
userConfigDAO.observeCertificateExpirationTime(url).wrapStorageRequest()
override suspend fun setShouldNotifyForRevokedCertificate(shouldNotify: Boolean) {
userConfigDAO.setShouldNotifyForRevokedCertificate(shouldNotify)
}

override suspend fun observeShouldNotifyForRevokedCertificate(): Flow<Either<StorageFailure, Boolean>> =
userConfigDAO.observeShouldNotifyForRevokedCertificate().wrapStorageRequest()
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,21 @@ internal interface MessageRepository {
): Either<CoreFailure, Unit>

suspend fun getEphemeralMessagesMarkedForDeletion(): Either<CoreFailure, List<Message>>

suspend fun getEphemeralMessagesMarkedForEndDeletion(): Either<CoreFailure, List<Message>>

suspend fun markSelfDeletionStartDate(
conversationId: ConversationId,
messageUuid: String,
deletionStartDate: Instant
): Either<CoreFailure, Unit>

suspend fun markSelfDeletionEndDate(
conversationId: ConversationId,
messageUuid: String,
deletionEndDate: Instant
): Either<CoreFailure, Unit>

suspend fun observeMessageVisibility(
messageUuid: String,
conversationId: ConversationId
Expand Down Expand Up @@ -614,6 +623,13 @@ internal class MessageDataSource internal constructor (
messageDAO.getEphemeralMessagesMarkedForDeletion().map(messageMapper::fromEntityToMessage)
}

override suspend fun getEphemeralMessagesMarkedForEndDeletion(): Either<CoreFailure, List<Message>> =
wrapStorageRequest {
messageDAO
.getEphemeralMessagedMarkedForEndDeletion()
.map(messageMapper::fromEntityToMessage)
}

override suspend fun markSelfDeletionStartDate(
conversationId: ConversationId,
messageUuid: String,
Expand All @@ -624,6 +640,16 @@ internal class MessageDataSource internal constructor (
}
}

override suspend fun markSelfDeletionEndDate(
conversationId: ConversationId,
messageUuid: String,
deletionEndDate: Instant
): Either<CoreFailure, Unit> {
return wrapStorageRequest {
messageDAO.updateSelfDeletionEndDate(conversationId.toDao(), messageUuid, deletionEndDate)
}
}

override suspend fun observeMessageVisibility(
messageUuid: String,
conversationId: ConversationId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ import com.wire.kalium.logic.feature.user.ObserveE2EIRequiredUseCase
import com.wire.kalium.logic.feature.user.ObserveE2EIRequiredUseCaseImpl
import com.wire.kalium.logic.feature.user.ObserveFileSharingStatusUseCase
import com.wire.kalium.logic.feature.user.ObserveFileSharingStatusUseCaseImpl
import com.wire.kalium.logic.feature.user.e2ei.ObserveShouldNotifyForRevokedCertificateUseCase
import com.wire.kalium.logic.feature.user.e2ei.ObserveShouldNotifyForRevokedCertificateUseCaseImpl
import com.wire.kalium.logic.feature.user.SyncContactsUseCase
import com.wire.kalium.logic.feature.user.SyncContactsUseCaseImpl
import com.wire.kalium.logic.feature.user.SyncSelfUserUseCase
Expand All @@ -310,6 +312,8 @@ import com.wire.kalium.logic.feature.user.UpdateSupportedProtocolsAndResolveOneO
import com.wire.kalium.logic.feature.user.UpdateSupportedProtocolsUseCase
import com.wire.kalium.logic.feature.user.UpdateSupportedProtocolsUseCaseImpl
import com.wire.kalium.logic.feature.user.UserScope
import com.wire.kalium.logic.feature.user.e2ei.MarkNotifyForRevokedCertificateAsNotifiedUseCase
import com.wire.kalium.logic.feature.user.e2ei.MarkNotifyForRevokedCertificateAsNotifiedUseCaseImpl
import com.wire.kalium.logic.feature.user.guestroomlink.MarkGuestLinkFeatureFlagAsNotChangedUseCase
import com.wire.kalium.logic.feature.user.guestroomlink.MarkGuestLinkFeatureFlagAsNotChangedUseCaseImpl
import com.wire.kalium.logic.feature.user.guestroomlink.ObserveGuestRoomLinkFeatureFlagUseCase
Expand Down Expand Up @@ -1630,6 +1634,7 @@ class UserSessionScope internal constructor(
globalScope.serverConfigRepository,
userStorage,
userPropertyRepository,
messages.deleteEphemeralMessageEndDate,
oneOnOneResolver,
this,
userScopedLogger
Expand Down Expand Up @@ -1693,6 +1698,7 @@ class UserSessionScope internal constructor(
val users: UserScope
get() = UserScope(
userRepository,
userConfigRepository,
accountRepository,
searchUserRepository,
syncManager,
Expand Down Expand Up @@ -1756,6 +1762,12 @@ class UserSessionScope internal constructor(
val observeFileSharingStatus: ObserveFileSharingStatusUseCase
get() = ObserveFileSharingStatusUseCaseImpl(userConfigRepository)

val observeShouldNotifyForRevokedCertificate: ObserveShouldNotifyForRevokedCertificateUseCase
by lazy { ObserveShouldNotifyForRevokedCertificateUseCaseImpl(userConfigRepository) }

val markNotifyForRevokedCertificateAsNotified: MarkNotifyForRevokedCertificateAsNotifiedUseCase
by lazy { MarkNotifyForRevokedCertificateAsNotifiedUseCaseImpl(userConfigRepository) }

val markGuestLinkFeatureFlagAsNotChanged: MarkGuestLinkFeatureFlagAsNotChangedUseCase
get() = MarkGuestLinkFeatureFlagAsNotChangedUseCaseImpl(userConfigRepository)

Expand Down Expand Up @@ -1953,6 +1965,9 @@ class UserSessionScope internal constructor(
launch {
updateSelfClientCapabilityToLegalHoldConsent()
}
launch {
users.observeCertificateRevocationForSelfClient()
}
}

fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.wire.kalium.logic.feature.conversation.messagetimer.UpdateMessageTime
import com.wire.kalium.logic.feature.conversation.mls.OneOnOneResolver
import com.wire.kalium.logic.feature.message.MessageSender
import com.wire.kalium.logic.feature.message.SendConfirmationUseCase
import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessagesAfterEndDateUseCase
import com.wire.kalium.logic.feature.team.DeleteTeamConversationUseCase
import com.wire.kalium.logic.feature.team.DeleteTeamConversationUseCaseImpl
import com.wire.kalium.logic.sync.SyncManager
Expand Down Expand Up @@ -90,6 +91,7 @@ class ConversationScope internal constructor(
private val serverConfigRepository: ServerConfigRepository,
private val userStorage: UserStorage,
userPropertyRepository: UserPropertyRepository,
private val deleteEphemeralMessageEndDate: DeleteEphemeralMessagesAfterEndDateUseCase,
private val oneOnOneResolver: OneOnOneResolver,
private val scope: CoroutineScope,
private val kaliumLogger: KaliumLogger
Expand Down Expand Up @@ -123,6 +125,7 @@ class ConversationScope internal constructor(
get() = NotifyConversationIsOpenUseCaseImpl(
oneOnOneResolver,
conversationRepository,
deleteEphemeralMessageEndDate,
kaliumLogger
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.feature.conversation.mls.OneOnOneResolver
import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessagesAfterEndDateUseCase
import com.wire.kalium.logic.functional.Either
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
Expand All @@ -43,6 +44,7 @@ interface NotifyConversationIsOpenUseCase {
internal class NotifyConversationIsOpenUseCaseImpl(
private val oneOnOneResolver: OneOnOneResolver,
private val conversationRepository: ConversationRepository,
private val deleteEphemeralMessageEndDate: DeleteEphemeralMessagesAfterEndDateUseCase,
private val kaliumLogger: KaliumLogger
) : NotifyConversationIsOpenUseCase {

Expand All @@ -61,5 +63,8 @@ internal class NotifyConversationIsOpenUseCaseImpl(
)
oneOnOneResolver.resolveOneOnOneConversationWithUser(conversation.otherUser)
}

// Delete Ephemeral Messages that has passed the end date
deleteEphemeralMessageEndDate()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.feature.e2ei.usecase

import com.wire.kalium.logic.configuration.UserConfigRepository
import com.wire.kalium.logic.data.id.CurrentClientIdProvider
import com.wire.kalium.logic.feature.e2ei.CertificateStatus
import com.wire.kalium.logic.functional.map

/**
* Use case to observe certificate revocation for self client.
*/
interface ObserveCertificateRevocationForSelfClientUseCase {
suspend operator fun invoke()
}

@Suppress("LongParameterList")
internal class ObserveCertificateRevocationForSelfClientUseCaseImpl(
private val userConfigRepository: UserConfigRepository,
private val currentClientIdProvider: CurrentClientIdProvider,
private val getE2eiCertificate: GetE2eiCertificateUseCase
) : ObserveCertificateRevocationForSelfClientUseCase {
override suspend fun invoke() {
currentClientIdProvider().map { clientId ->
getE2eiCertificate(clientId).run {
if (this is GetE2EICertificateUseCaseResult.Success && certificate.status == CertificateStatus.REVOKED) {
userConfigRepository.setShouldNotifyForRevokedCertificate(true)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import com.wire.kalium.logic.feature.message.composite.SendButtonActionMessageUs
import com.wire.kalium.logic.feature.message.composite.SendButtonMessageUseCase
import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessageForSelfUserAsReceiverUseCaseImpl
import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessageForSelfUserAsSenderUseCaseImpl
import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessagesAfterEndDateUseCase
import com.wire.kalium.logic.feature.message.ephemeral.DeleteEphemeralMessagesAfterEndDateUseCaseImpl
import com.wire.kalium.logic.feature.message.ephemeral.EnqueueMessageSelfDeletionUseCase
import com.wire.kalium.logic.feature.message.ephemeral.EnqueueMessageSelfDeletionUseCaseImpl
import com.wire.kalium.logic.feature.message.ephemeral.EphemeralMessageDeletionHandler
Expand Down Expand Up @@ -157,6 +159,10 @@ class MessageScope internal constructor(
ephemeralMessageDeletionHandler = ephemeralMessageDeletionHandler
)

val deleteEphemeralMessageEndDate: DeleteEphemeralMessagesAfterEndDateUseCase = DeleteEphemeralMessagesAfterEndDateUseCaseImpl(
ephemeralMessageDeletionHandler = ephemeralMessageDeletionHandler
)

internal val messageSender: MessageSender
get() = MessageSenderImpl(
messageRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.feature.message.ephemeral

/**
* This use case deletes ephemeral [Message] that have an end date set and it has passed current time
*/
interface DeleteEphemeralMessagesAfterEndDateUseCase {
suspend operator fun invoke()
}

internal class DeleteEphemeralMessagesAfterEndDateUseCaseImpl(
private val ephemeralMessageDeletionHandler: EphemeralMessageDeletionHandler
) : DeleteEphemeralMessagesAfterEndDateUseCase {

override suspend fun invoke() {
ephemeralMessageDeletionHandler.deleteSelfDeletionMessagesFromEndDate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ internal interface EphemeralMessageDeletionHandler {
fun startSelfDeletion(conversationId: ConversationId, messageId: String)
fun enqueueSelfDeletion(message: Message, expirationData: Message.ExpirationData)
suspend fun enqueuePendingSelfDeletionMessages()

suspend fun deleteSelfDeletionMessagesFromEndDate()
}

internal class EphemeralMessageDeletionHandlerImpl(
Expand Down Expand Up @@ -195,6 +197,13 @@ internal class EphemeralMessageDeletionHandlerImpl(
deletionStartDate = deletionStartMark
)

val deletionEndDate = deletionStartMark + expireAfter
messageRepository.markSelfDeletionEndDate(
conversationId = message.conversationId,
messageUuid = message.id,
deletionEndDate = deletionEndDate
)

SelfDeletionEventLogger.log(
LoggingSelfDeletionEvent.MarkingSelfSelfDeletionStartDate(
message,
Expand Down Expand Up @@ -235,4 +244,19 @@ internal class EphemeralMessageDeletionHandlerImpl(
}
}
}

override suspend fun deleteSelfDeletionMessagesFromEndDate() {
messageRepository.getEphemeralMessagesMarkedForEndDeletion()
.onSuccess { ephemeralMessages ->
ephemeralMessages.forEach { ephemeralMessage ->
ephemeralMessage.expirationData?.let { expirationData ->
deleteMessage(
message = ephemeralMessage,
expirationData = expirationData
)
}
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.wire.kalium.logic.feature.user

import com.wire.kalium.logic.configuration.UserConfigRepository
import com.wire.kalium.logic.configuration.server.ServerConfigRepository
import com.wire.kalium.logic.data.asset.AssetRepository
import com.wire.kalium.logic.data.connection.ConnectionRepository
Expand Down Expand Up @@ -54,6 +55,8 @@ import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusUs
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusUseCaseImpl
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCaseImpl
import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCaseImpl
import com.wire.kalium.logic.feature.message.MessageSender
import com.wire.kalium.logic.feature.publicuser.GetAllContactsUseCase
import com.wire.kalium.logic.feature.publicuser.GetAllContactsUseCaseImpl
Expand All @@ -75,6 +78,7 @@ import com.wire.kalium.persistence.dao.MetadataDAO
@Suppress("LongParameterList")
class UserScope internal constructor(
private val userRepository: UserRepository,
private val userConfigRepository: UserConfigRepository,
private val accountRepository: AccountRepository,
private val searchUserRepository: SearchUserRepository,
private val syncManager: SyncManager,
Expand Down Expand Up @@ -176,4 +180,11 @@ class UserScope internal constructor(
val deleteAccount: DeleteAccountUseCase get() = DeleteAccountUseCase(accountRepository)

val updateSupportedProtocols: UpdateSupportedProtocolsUseCase get() = updateSupportedProtocolsUseCase

val observeCertificateRevocationForSelfClient: ObserveCertificateRevocationForSelfClientUseCase
get() = ObserveCertificateRevocationForSelfClientUseCaseImpl(
userConfigRepository = userConfigRepository,
currentClientIdProvider = clientIdProvider,
getE2eiCertificate = getE2EICertificate
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.feature.user.e2ei

import com.wire.kalium.logic.configuration.UserConfigRepository

/**
* Use case that marks that the user should not be notified about revoked E2Ei certificate.
*/
interface MarkNotifyForRevokedCertificateAsNotifiedUseCase {
suspend operator fun invoke()
}

internal class MarkNotifyForRevokedCertificateAsNotifiedUseCaseImpl(
private val userConfigRepository: UserConfigRepository
) : MarkNotifyForRevokedCertificateAsNotifiedUseCase {
override suspend operator fun invoke() {
userConfigRepository.setShouldNotifyForRevokedCertificate(false)
}
}
Loading

0 comments on commit c033b70

Please sign in to comment.