diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt index 4c26afca..63275c4b 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt @@ -61,7 +61,7 @@ internal class MXOlmDevice( // They are not stored in 'store' to avoid to remember to which devices we sent the session key. // Plus, in cryptography, it is good to refresh sessions from time to time. // The key is the session id, the value the outbound group session. - private val mOutboundGroupSessionStore: MutableMap + private val mOutboundGroupSessionStore: MutableMap = HashMap() // Store a set of decrypted message indexes for each group session. // This partially mitigates a replay attack where a MITM resends a group @@ -75,7 +75,7 @@ internal class MXOlmDevice( // The first level keys are timeline ids. // The second level keys are strings of form "||" // Values are true. - private val mInboundGroupSessionMessageIndexes: MutableMap> + private val mInboundGroupSessionMessageIndexes: MutableMap> = HashMap() /** * inboundGroupSessionWithId error @@ -107,8 +107,6 @@ internal class MXOlmDevice( mOlmUtility = null } - mOutboundGroupSessionStore = HashMap() - try { deviceCurve25519Key = mOlmAccount!!.identityKeys()[OlmAccount.JSON_KEY_IDENTITY_KEY] } catch (e: Exception) { @@ -120,8 +118,6 @@ internal class MXOlmDevice( } catch (e: Exception) { Timber.e(e, "## MXOlmDevice : cannot find " + OlmAccount.JSON_KEY_FINGER_PRINT_KEY + " with error") } - - mInboundGroupSessionMessageIndexes = HashMap() } /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt index 3c621ec6..b042e32f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.internal.crypto.model.rest import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.session.crypto.sas.SasMode import im.vector.matrix.android.internal.crypto.verification.SASVerificationTransaction import timber.log.Timber @@ -23,6 +24,7 @@ import timber.log.Timber /** * Sent by Alice to initiate an interactive key verification. */ +@JsonClass(generateAdapter = true) class KeyVerificationStart : SendToDeviceObject { /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt index 441d7a41..f4598fcb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt @@ -59,7 +59,7 @@ internal class DefaultSasVerificationService(private val mCredentials: Credentia // Event received from the sync fun onToDeviceEvent(event: Event) { - CryptoAsyncHelper.getDecryptBackgroundHandler().post { + CryptoAsyncHelper.getDecryptBackgroundHandler().post { // TODO We are already in a BG thread when (event.type) { EventType.KEY_VERIFICATION_START -> { onStartRequestReceived(event) @@ -226,10 +226,10 @@ internal class DefaultSasVerificationService(private val mCredentials: Credentia } } - override fun onSuccess(info: MXUsersDevicesMap) { + override fun onSuccess(data: MXUsersDevicesMap) { CryptoAsyncHelper.getDecryptBackgroundHandler().post { - if (info.getUserDeviceIds(otherUserId).contains(startReq.fromDevice)) { - success(info) + if (data.getUserDeviceIds(otherUserId).contains(startReq.fromDevice)) { + success(data) } else { error() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/IncomingSASVerificationTransaction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/IncomingSASVerificationTransaction.kt index e9bc6788..33b792e3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/IncomingSASVerificationTransaction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/IncomingSASVerificationTransaction.kt @@ -38,8 +38,9 @@ internal class IncomingSASVerificationTransaction( private val mCredentials: Credentials, private val mCryptoStore: IMXCryptoStore, private val mSendToDeviceTask: SendToDeviceTask, - private val mTaskExecutor: TaskExecutor, transactionId: String, + private val mTaskExecutor: TaskExecutor, deviceFingerprint: String, + transactionId: String, otherUserID: String) : SASVerificationTransaction( mSasVerificationService, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASVerificationTransaction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASVerificationTransaction.kt index 583029a1..332dcb3a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASVerificationTransaction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SASVerificationTransaction.kt @@ -24,11 +24,11 @@ import im.vector.matrix.android.api.session.crypto.sas.SasMode import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.internal.crypto.CryptoAsyncHelper -import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo import im.vector.matrix.android.internal.crypto.model.MXKey import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.model.rest.* +import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith @@ -182,7 +182,7 @@ internal abstract class SASVerificationTransaction( is KeyVerificationAccept -> onVerificationAccept(event) is KeyVerificationKey -> onKeyVerificationKey(senderId, event) is KeyVerificationMac -> onKeyVerificationMac(event) - else -> { + else -> { //nop } } @@ -323,11 +323,11 @@ internal abstract class SASVerificationTransaction( if (shortCodeBytes!!.size < 5) return null return getDecimalCodeRepresentation(shortCodeBytes!!) } - SasMode.EMOJI -> { + SasMode.EMOJI -> { if (shortCodeBytes!!.size < 6) return null return getEmojiCodeRepresentation(shortCodeBytes!!).joinToString(" ") { it.emoji } } - else -> return null + else -> return null } } diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt b/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt index 88017efd..308b900f 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt @@ -75,7 +75,7 @@ class AppModule(private val context: Context) { } single { - IncomingVerificationRequestHandler(get(), get(), get()) + IncomingVerificationRequestHandler(context, get()) } diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt index a3ca69ce..2e412de3 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt @@ -17,7 +17,7 @@ package im.vector.riotredesign.features.crypto.verification import android.content.Context import im.vector.matrix.android.api.Matrix -import im.vector.matrix.android.api.auth.data.Credentials +import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState @@ -28,11 +28,10 @@ import im.vector.riotredesign.features.popup.PopupAlertManager * Listens to the VerificationManager and add a new notification when an incoming request is detected. */ class IncomingVerificationRequestHandler(val context: Context, - private val credentials: Credentials, - verificationService: SasVerificationService) : SasVerificationService.SasVerificationListener { + private val session: Session) : SasVerificationService.SasVerificationListener { - init { - verificationService.addListener(this) + fun ensureStarted() { + session.getSasVerificationService().addListener(this) } override fun transactionCreated(tx: SasVerificationTransaction) {} @@ -53,7 +52,7 @@ class IncomingVerificationRequestHandler(val context: Context, ).apply { contentAction = Runnable { val intent = SASVerificationActivity.incomingIntent(context, - credentials.userId, + session.sessionParams.credentials.userId, tx.otherUserId, tx.transactionId) weakCurrentActivity?.get()?.startActivity(intent) @@ -71,7 +70,7 @@ class IncomingVerificationRequestHandler(val context: Context, context.getString(R.string.action_open), Runnable { val intent = SASVerificationActivity.incomingIntent(context, - credentials.userId, + session.sessionParams.credentials.userId, tx.otherUserId, tx.transactionId) weakCurrentActivity?.get()?.startActivity(intent) @@ -85,11 +84,11 @@ class IncomingVerificationRequestHandler(val context: Context, } SasVerificationTxState.Cancelled, SasVerificationTxState.OnCancelled, - SasVerificationTxState.Verified -> { + SasVerificationTxState.Verified -> { //cancel related notification PopupAlertManager.cancelAlert("kvr_${tx.transactionId}") } - else -> Unit + else -> Unit } } diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index e3f443e5..a7237494 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -37,6 +37,7 @@ import im.vector.riotredesign.core.extensions.replaceFragment import im.vector.riotredesign.core.platform.OnBackPressed import im.vector.riotredesign.core.platform.ToolbarConfigurable import im.vector.riotredesign.core.platform.VectorBaseActivity +import im.vector.riotredesign.features.crypto.verification.IncomingVerificationRequestHandler import im.vector.riotredesign.features.home.room.detail.LoadingRoomDetailFragment import im.vector.riotredesign.features.rageshake.BugReporter import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler @@ -53,6 +54,9 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { private val homeActivityViewModel: HomeActivityViewModel by viewModel() private val homeNavigator by inject() + // TODO Move this elsewhere + private val incomingVerificationRequestHandler by inject() + private var progress: ProgressDialog? = null private val drawerListener = object : DrawerLayout.SimpleDrawerListener() { @@ -88,6 +92,8 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { progress?.dismiss() } }) + + incomingVerificationRequestHandler.ensureStarted() } override fun onDestroy() { @@ -124,7 +130,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - android.R.id.home -> { + android.R.id.home -> { drawerLayout.openDrawer(GravityCompat.START) return true } @@ -137,7 +143,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { return true } // TODO Temporary code here to create a room - R.id.tmp_menu_create_room -> { + R.id.tmp_menu_create_room -> { homeActivityViewModel.createRoom() return true } diff --git a/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt index 996811c4..ec619d15 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/workers/signout/SignOutViewModel.kt @@ -86,8 +86,6 @@ class SignOutViewModel : ViewModel(), KeysBackupService.KeysBackupStateListener * The backup check on logout flow has to be displayed if there are keys in the store, and the keys backup state is not Ready */ fun doYouNeedToBeDisplayed(session: Session?): Boolean { - return false - return session ?.inboundGroupSessionsCount(false) ?: 0 > 0