From cb4752812aa1b445e5524179da3ee8c392a57b0e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 6 Mar 2020 15:53:55 +0100 Subject: [PATCH] Hide private key --- .../verification/SendVerificationMessageWorker.kt | 10 +++++++++- .../verification/VerificationTransportRoomMessage.kt | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt index 0d5387bbe0..95376fb0cc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SendVerificationMessageWorker.kt @@ -52,7 +52,7 @@ internal class SendVerificationMessageWorker(context: Context, lateinit var cryptoService: CryptoService override suspend fun doWork(): Result { - val errorOutputData = Data.Builder().putBoolean("failed", true).build() + val errorOutputData = Data.Builder().putBoolean(OUTPUT_KEY_FAILED, true).build() val params = WorkerParamsFactory.fromData(inputData) ?: return Result.success(errorOutputData) @@ -80,4 +80,12 @@ internal class SendVerificationMessageWorker(context: Context, } } } + + companion object { + private const val OUTPUT_KEY_FAILED = "failed" + + fun hasFailed(outputData: Data): Boolean { + return outputData.getBoolean(SendVerificationMessageWorker.OUTPUT_KEY_FAILED, false) + } + } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationTransportRoomMessage.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationTransportRoomMessage.kt index 7a6e3b40ac..75f5ecb034 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationTransportRoomMessage.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationTransportRoomMessage.kt @@ -22,8 +22,8 @@ import androidx.work.ExistingWorkPolicy import androidx.work.Operation import androidx.work.WorkInfo import im.vector.matrix.android.R -import im.vector.matrix.android.api.session.crypto.verification.ValidVerificationInfoRequest import im.vector.matrix.android.api.session.crypto.verification.CancelCode +import im.vector.matrix.android.api.session.crypto.verification.ValidVerificationInfoRequest import im.vector.matrix.android.api.session.crypto.verification.VerificationTxState import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.session.events.model.Event @@ -115,7 +115,7 @@ internal class VerificationTransportRoomMessage( ?.filter { it.state == WorkInfo.State.SUCCEEDED } ?.firstOrNull { it.id == enqueueInfo.second } ?.let { wInfo -> - if (wInfo.outputData.getBoolean("failed", false)) { + if (SendVerificationMessageWorker.hasFailed(wInfo.outputData)) { Timber.e("## SAS verification [${tx?.transactionId}] failed to send verification message in state : ${tx?.state}") tx?.cancel(onErrorReason) } else { @@ -196,7 +196,7 @@ internal class VerificationTransportRoomMessage( ?.filter { it.state == WorkInfo.State.SUCCEEDED } ?.firstOrNull { it.id == workRequest.id } ?.let { wInfo -> - if (wInfo.outputData.getBoolean("failed", false)) { + if (SendVerificationMessageWorker.hasFailed(wInfo.outputData)) { callback(null, null) } else if (wInfo.outputData.getString(localId) != null) { callback(wInfo.outputData.getString(localId), validInfo)