diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/crosssigning/CrossSigningService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/crosssigning/CrossSigningService.kt index 6a0311f202..99423ed094 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/crosssigning/CrossSigningService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/crypto/crosssigning/CrossSigningService.kt @@ -26,6 +26,8 @@ import im.vector.matrix.android.internal.crypto.model.rest.UserPasswordAuth interface CrossSigningService { + fun isCrossSigningEnabled(): Boolean + fun isUserTrusted(otherUserId: String): Boolean /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt index 56bf79af99..ca281ac7ef 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt @@ -212,7 +212,7 @@ internal class DefaultCrossSigningService @Inject constructor( this.constraints = TaskConstraints(true) this.callback = object : MatrixCallback { override fun onSuccess(data: Unit) { - Timber.i("## CrossSigning - Keys succesfully uploaded") + Timber.i("## CrossSigning - Keys successfully uploaded") // Sign the current device with SSK val uploadSignatureQueryBuilder = UploadSignatureQueryBuilder() @@ -248,7 +248,7 @@ internal class DefaultCrossSigningService @Inject constructor( this.constraints = TaskConstraints(true) this.callback = object : MatrixCallback { override fun onSuccess(data: Unit) { - Timber.i("## CrossSigning - signatures succesfuly uploaded") + Timber.i("## CrossSigning - signatures successfully uploaded") callback?.onSuccess(Unit) } @@ -293,23 +293,22 @@ internal class DefaultCrossSigningService @Inject constructor( * ┏━━━━━━━━┓ ┏━━━━━━━━┓ * ┃ ALICE ┃ ┃ BOB ┃ * ┗━━━━━━━━┛ ┗━━━━━━━━┛ - * MSK ┌────────────▶MSK + * MSK ┌────────────▶ MSK * │ - * │ │ │ - * │ SSK │ └──▶ SSK ──────────────────┐ - * │ │ │ - * │ │ USK │ - * └──▶ USK ────────────┘ (not visible by │ - * Alice) │ - * ▼ - * ┌──────────────┐ - * │ BOB's Device │ - * └──────────────┘ + * │ │ + * │ SSK │ + * │ │ + * │ │ + * └──▶ USK ────────────┘ */ override fun isUserTrusted(otherUserId: String): Boolean { return cryptoStore.getCrossSigningInfo(userId)?.isTrusted() == true } + override fun isCrossSigningEnabled(): Boolean { + return checkSelfTrust().isVerified() + } + /** * Will not force a download of the key, but will verify signatures trust chain */ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt index 92b5ea6e26..e2ef60d990 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt @@ -601,7 +601,7 @@ internal class DefaultVerificationService @Inject constructor( return } if (checkKeysAreDownloaded(event.senderId, readyReq.fromDevice ?: "") == null) { - Timber.e("## SAS Verification device ${readyReq.fromDevice} is not knwown") + Timber.e("## SAS Verification device ${readyReq.fromDevice} is not known") // TODO cancel? return } @@ -833,10 +833,19 @@ internal class DefaultVerificationService @Inject constructor( otherUserId = otherUserId ) - // Add reciprocate method if application declares it can scan or show QR codes - // Not sure if it ok to do that (?) - val reciprocateMethod = methods.firstOrNull { it == VerificationMethod.QR_CODE_SCAN || it == VerificationMethod.QR_CODE_SHOW }?.let { listOf(VERIFICATION_METHOD_RECIPROCATE) }.orEmpty() - val methodValues = (methods.map { it.toValue() } + reciprocateMethod).distinct() + // We can SCAN or SHOW QR codes only if cross-signing is enabled + val methodValues = if (crossSigningService.isCrossSigningEnabled()) { + // Add reciprocate method if application declares it can scan or show QR codes + // Not sure if it ok to do that (?) + val reciprocateMethod = methods.firstOrNull { it == VerificationMethod.QR_CODE_SCAN || it == VerificationMethod.QR_CODE_SHOW }?.let { listOf(VERIFICATION_METHOD_RECIPROCATE) }.orEmpty() + methods.map { it.toValue() } + reciprocateMethod + } else { + // Filter out SCAN and SHOW qr code method + methods + .filter { it != VerificationMethod.QR_CODE_SHOW && it != VerificationMethod.QR_CODE_SCAN } + .map { it.toValue() } + } + .distinct() transport.sendVerificationRequest(methodValues, localID, otherUserId, roomId) { syncedId, info -> // We need to update with the syncedID diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt index cca6f32067..4548313ba1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/PendingVerificationRequest.kt @@ -39,7 +39,9 @@ data class PendingVerificationRequest( val cancelConclusion: CancelCode? = null, val isSuccessful: Boolean = false, val handledByOtherSession: Boolean = false, + // TODO Move to OutgoingQrCodeTransaction val myGeneratedSecret: String? = null, + // TODO Move to OutgoingQrCodeTransaction val qrCodeText: String? = null ) {