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

feat: Observe self client certificate revocation (WPB-6145) #2406

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ interface UserConfigRepository {
suspend fun observeLegalHoldChangeNotified(): Flow<Either<StorageFailure, Boolean>>
suspend fun setShouldUpdateClientLegalHoldCapability(shouldUpdate: Boolean): Either<StorageFailure, Unit>
suspend fun shouldUpdateClientLegalHoldCapability(): Boolean
<<<<<<< HEAD
=======
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>>
>>>>>>> 35d3229ed7 (feat: Observe self client certificate revocation (WPB-6145) (#2384))
}

@Suppress("TooManyFunctions")
Expand Down Expand Up @@ -434,4 +442,23 @@ internal class UserConfigDataSource internal constructor(

override suspend fun shouldUpdateClientLegalHoldCapability(): Boolean =
userConfigDAO.shouldUpdateClientLegalHoldCapability()
<<<<<<< HEAD
=======

override suspend fun setCRLExpirationTime(url: String, timestamp: ULong) {
userConfigDAO.setCRLExpirationTime(url, timestamp)
}

override suspend fun getCRLExpirationTime(url: String): ULong? =
userConfigDAO.getCRLsPerDomain(url)

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()
>>>>>>> 35d3229ed7 (feat: Observe self client certificate revocation (WPB-6145) (#2384))
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,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 @@ -304,6 +306,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 @@ -1674,6 +1678,7 @@ class UserSessionScope internal constructor(
val users: UserScope
get() = UserScope(
userRepository,
userConfigRepository,
accountRepository,
searchUserRepository,
syncManager,
Expand Down Expand Up @@ -1737,6 +1742,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 @@ -1922,6 +1933,9 @@ class UserSessionScope internal constructor(
launch {
updateSelfClientCapabilityToLegalHoldConsent()
}
launch {
users.observeCertificateRevocationForSelfClient()
}
}

fun onDestroy() {
Expand Down
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 @@ -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 @@ -52,8 +53,13 @@ import com.wire.kalium.logic.feature.e2ei.usecase.GetMembersE2EICertificateStatu
import com.wire.kalium.logic.feature.e2ei.usecase.GetMembersE2EICertificateStatusesUseCaseImpl
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCaseImpl
<<<<<<< HEAD
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusUseCaseImpl
=======
import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCaseImpl
>>>>>>> 35d3229ed7 (feat: Observe self client certificate revocation (WPB-6145) (#2384))
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 +81,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 +183,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)
}
}
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.user.e2ei

import com.wire.kalium.logic.configuration.UserConfigRepository
import com.wire.kalium.logic.functional.fold
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf

/**
* Use case that observes if the user should be notified about revoked E2ei certificate.
*/
interface ObserveShouldNotifyForRevokedCertificateUseCase {
suspend operator fun invoke(): Flow<Boolean>
}

internal class ObserveShouldNotifyForRevokedCertificateUseCaseImpl(
private val userConfigRepository: UserConfigRepository
) : ObserveShouldNotifyForRevokedCertificateUseCase {
@OptIn(ExperimentalCoroutinesApi::class)
override suspend operator fun invoke(): Flow<Boolean> =
userConfigRepository.observeShouldNotifyForRevokedCertificate().flatMapLatest {
it.fold(
{ flowOf(false) },
{ shouldNotify ->
flowOf(shouldNotify)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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
import io.mockative.Mock
import io.mockative.classOf
import io.mockative.eq
import io.mockative.given
import io.mockative.mock
import io.mockative.verify
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

class MarkNotifyForRevokedCertificateAsNotifiedUseCaseTest {

@Test
fun givenUserConfigRepository_whenRunningUseCase_thenSetShouldNotifyForRevokedCertificateOnce() =
runTest {
val (arrangement, markNotifyForRevokedCertificateAsNotified) = Arrangement()
.withUserConfigRepository()
.arrange()

markNotifyForRevokedCertificateAsNotified.invoke()

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::setShouldNotifyForRevokedCertificate)
.with(eq(false))
.wasInvoked()
}

internal class Arrangement {

@Mock
val userConfigRepository = mock(classOf<UserConfigRepository>())

fun arrange() = this to MarkNotifyForRevokedCertificateAsNotifiedUseCaseImpl(
userConfigRepository = userConfigRepository
)

fun withUserConfigRepository() = apply {
given(userConfigRepository)
.function(userConfigRepository::setShouldNotifyForRevokedCertificate)
.whenInvokedWith(eq(false))
.thenReturn(Unit)
}
}
}
Loading
Loading