Improve clarity of the algorithm to enable encryption for DMs
This commit is contained in:
parent
2bccd19f84
commit
fbd0bbc575
@ -25,7 +25,7 @@ import im.vector.matrix.android.internal.crypto.model.rest.UserPasswordAuth
|
||||
|
||||
interface CrossSigningService {
|
||||
|
||||
fun isCrossSigningEnabled(): Boolean
|
||||
fun isCrossSigningVerified(): Boolean
|
||||
|
||||
fun isUserTrusted(otherUserId: String): Boolean
|
||||
|
||||
|
@ -305,7 +305,7 @@ internal class DefaultCrossSigningService @Inject constructor(
|
||||
return cryptoStore.getCrossSigningInfo(userId)?.isTrusted() == true
|
||||
}
|
||||
|
||||
override fun isCrossSigningEnabled(): Boolean {
|
||||
override fun isCrossSigningVerified(): Boolean {
|
||||
return checkSelfTrust().isVerified()
|
||||
}
|
||||
|
||||
|
@ -55,5 +55,4 @@ internal open class CrossSigningInfoEntity(
|
||||
.forEach { crossSigningKeys.remove(it) }
|
||||
info?.let { crossSigningKeys.add(it) }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -878,8 +878,8 @@ internal class DefaultVerificationService @Inject constructor(
|
||||
otherUserId = otherUserId
|
||||
)
|
||||
|
||||
// We can SCAN or SHOW QR codes only if cross-signing is enabled
|
||||
val methodValues = if (crossSigningService.isCrossSigningEnabled()) {
|
||||
// We can SCAN or SHOW QR codes only if cross-signing is verified
|
||||
val methodValues = if (crossSigningService.isCrossSigningVerified()) {
|
||||
// Add reciprocate method if application declares it can scan or show QR codes
|
||||
// Not sure if it ok to do that (?)
|
||||
val reciprocateMethod = methods
|
||||
|
@ -17,7 +17,6 @@
|
||||
package im.vector.matrix.android.internal.session.room.create
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.api.extensions.orTrue
|
||||
import im.vector.matrix.android.api.session.crypto.crosssigning.CrossSigningService
|
||||
import im.vector.matrix.android.api.session.room.failure.CreateRoomFailure
|
||||
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
|
||||
@ -58,32 +57,11 @@ internal class DefaultCreateRoomTask @Inject constructor(
|
||||
) : CreateRoomTask {
|
||||
|
||||
override suspend fun execute(params: CreateRoomParams): String {
|
||||
val createRoomParams = params
|
||||
.takeIf { it.enableEncryptionIfInvitedUsersSupportIt }
|
||||
?.takeIf { crossSigningService.isCrossSigningEnabled() }
|
||||
?.takeIf { it.invite3pids.isNullOrEmpty() }
|
||||
?.invitedUserIds
|
||||
?.let { userIds ->
|
||||
val keys = deviceListManager.downloadKeys(userIds, forceDownload = false)
|
||||
|
||||
userIds.any { userId ->
|
||||
if (keys.map[userId].isNullOrEmpty()) {
|
||||
// A user has no device, so do not enable encryption
|
||||
true
|
||||
} else {
|
||||
// Check that every user's device have at least one key
|
||||
keys.map[userId]?.values?.any { it.keys.isNullOrEmpty() } ?: true
|
||||
}
|
||||
}
|
||||
}
|
||||
.orTrue()
|
||||
.let { cannotEnableEncryption ->
|
||||
if (!cannotEnableEncryption) {
|
||||
val createRoomParams = if (canEnableEncryption(params)) {
|
||||
params.enableEncryptionWithAlgorithm()
|
||||
} else {
|
||||
params
|
||||
}
|
||||
}
|
||||
|
||||
val createRoomResponse = executeRequest<CreateRoomResponse>(eventBus) {
|
||||
apiCall = roomAPI.createRoom(createRoomParams)
|
||||
@ -105,6 +83,28 @@ internal class DefaultCreateRoomTask @Inject constructor(
|
||||
return roomId
|
||||
}
|
||||
|
||||
private suspend fun canEnableEncryption(params: CreateRoomParams): Boolean {
|
||||
return params.enableEncryptionIfInvitedUsersSupportIt
|
||||
&& crossSigningService.isCrossSigningVerified()
|
||||
&& params.invite3pids.isNullOrEmpty()
|
||||
&& params.invitedUserIds?.isNotEmpty() == true
|
||||
&& params.invitedUserIds.let { userIds ->
|
||||
val keys = deviceListManager.downloadKeys(userIds, forceDownload = false)
|
||||
|
||||
userIds.all { userId ->
|
||||
keys.map[userId].let { deviceMap ->
|
||||
if (deviceMap.isNullOrEmpty()) {
|
||||
// A user has no device, so do not enable encryption
|
||||
false
|
||||
} else {
|
||||
// Check that every user's device have at least one key
|
||||
deviceMap.values.all { !it.keys.isNullOrEmpty() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun handleDirectChatCreation(params: CreateRoomParams, roomId: String) {
|
||||
val otherUserId = params.getFirstInvitedUserId()
|
||||
?: throw IllegalStateException("You can't create a direct room without an invitedUser")
|
||||
|
@ -35,7 +35,6 @@ import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.ScreenComponent
|
||||
import im.vector.riotx.core.extensions.commitTransactionNow
|
||||
import im.vector.riotx.core.extensions.exhaustive
|
||||
import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment
|
||||
import im.vector.riotx.features.crypto.verification.choose.VerificationChooseMethodFragment
|
||||
import im.vector.riotx.features.crypto.verification.conclusion.VerificationConclusionFragment
|
||||
|
Loading…
x
Reference in New Issue
Block a user