-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Indicate user with valid E2EI certificate (WPB-3228) (#2335)
* feat: Indicate user with valid E2EI certificate * Code style fix * feat: Indicate user with valid E2EI certificate: review comments * Review updates * Review fixes --------- Co-authored-by: Mojtaba Chenani <[email protected]>
- Loading branch information
1 parent
0696b8e
commit 52f2033
Showing
12 changed files
with
625 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...in/com/wire/kalium/logic/feature/e2ei/usecase/GetMembersE2EICertificateStatusesUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 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.cryptography.WireIdentity | ||
import com.wire.kalium.logic.data.conversation.MLSConversationRepository | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.data.user.UserId | ||
import com.wire.kalium.logic.feature.e2ei.CertificateStatus | ||
import com.wire.kalium.logic.feature.e2ei.PemCertificateDecoder | ||
import com.wire.kalium.logic.functional.fold | ||
|
||
/** | ||
* This use case is used to get the e2ei certificates of all the users in Conversation. | ||
* Return [Map] where keys are [UserId] and values - nullable [CertificateStatus] of corresponding user. | ||
*/ | ||
interface GetMembersE2EICertificateStatusesUseCase { | ||
suspend operator fun invoke(conversationId: ConversationId, userIds: List<UserId>): Map<UserId, CertificateStatus?> | ||
} | ||
|
||
class GetMembersE2EICertificateStatusesUseCaseImpl internal constructor( | ||
private val mlsConversationRepository: MLSConversationRepository, | ||
private val pemCertificateDecoder: PemCertificateDecoder | ||
) : GetMembersE2EICertificateStatusesUseCase { | ||
override suspend operator fun invoke(conversationId: ConversationId, userIds: List<UserId>): Map<UserId, CertificateStatus?> = | ||
mlsConversationRepository.getMembersIdentities(conversationId, userIds).fold( | ||
{ mapOf() }, | ||
{ | ||
it.mapValues { (_, identities) -> | ||
identities.getUserCertificateStatus(pemCertificateDecoder) | ||
} | ||
} | ||
) | ||
} | ||
|
||
/** | ||
* @return null if list is empty; | ||
* [CertificateStatus.REVOKED] if any certificate is revoked; | ||
* [CertificateStatus.EXPIRED] if any certificate is expired; | ||
* [CertificateStatus.VALID] otherwise. | ||
*/ | ||
fun List<WireIdentity>.getUserCertificateStatus(pemCertificateDecoder: PemCertificateDecoder): CertificateStatus? { | ||
val certificates = this.map { pemCertificateDecoder.decode(it.certificate, it.status) } | ||
return if (certificates.isEmpty()) { | ||
null | ||
} else if (certificates.any { it.status == CertificateStatus.REVOKED }) { | ||
CertificateStatus.REVOKED | ||
} else if (certificates.any { it.status == CertificateStatus.EXPIRED }) { | ||
CertificateStatus.EXPIRED | ||
} else { | ||
CertificateStatus.VALID | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...onMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetUserE2EICertificateUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 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.data.conversation.MLSConversationRepository | ||
import com.wire.kalium.logic.data.user.UserId | ||
import com.wire.kalium.logic.feature.e2ei.CertificateStatus | ||
import com.wire.kalium.logic.feature.e2ei.PemCertificateDecoder | ||
import com.wire.kalium.logic.functional.fold | ||
|
||
/** | ||
* This use case is used to get the e2ei certificate status of specific user | ||
*/ | ||
interface GetUserE2eiCertificateStatusUseCase { | ||
suspend operator fun invoke(userId: UserId): GetUserE2eiCertificateStatusResult | ||
} | ||
|
||
class GetUserE2eiCertificateStatusUseCaseImpl internal constructor( | ||
private val mlsConversationRepository: MLSConversationRepository, | ||
private val pemCertificateDecoder: PemCertificateDecoder | ||
) : GetUserE2eiCertificateStatusUseCase { | ||
override suspend operator fun invoke(userId: UserId): GetUserE2eiCertificateStatusResult = | ||
mlsConversationRepository.getUserIdentity(userId).fold( | ||
{ | ||
GetUserE2eiCertificateStatusResult.Failure.NotActivated | ||
}, | ||
{ identities -> | ||
identities.getUserCertificateStatus(pemCertificateDecoder)?.let { | ||
GetUserE2eiCertificateStatusResult.Success(it) | ||
} ?: GetUserE2eiCertificateStatusResult.Failure.NotActivated | ||
} | ||
) | ||
} | ||
|
||
sealed class GetUserE2eiCertificateStatusResult { | ||
class Success(val status: CertificateStatus) : GetUserE2eiCertificateStatusResult() | ||
sealed class Failure : GetUserE2eiCertificateStatusResult() { | ||
data object NotActivated : Failure() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.