mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
SAS Tested
This commit is contained in:
parent
e70fd8e351
commit
102bc9c01b
@ -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<String, OlmOutboundGroupSession>
|
||||
private val mOutboundGroupSessionStore: MutableMap<String, OlmOutboundGroupSession> = 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 "<senderKey>|<session_id>|<message_index>"
|
||||
// Values are true.
|
||||
private val mInboundGroupSessionMessageIndexes: MutableMap<String, MutableMap<String, Boolean>>
|
||||
private val mInboundGroupSessionMessageIndexes: MutableMap<String, MutableMap<String, Boolean>> = 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()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
@ -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<MXDeviceInfo>) {
|
||||
override fun onSuccess(data: MXUsersDevicesMap<MXDeviceInfo>) {
|
||||
CryptoAsyncHelper.getDecryptBackgroundHandler().post {
|
||||
if (info.getUserDeviceIds(otherUserId).contains(startReq.fromDevice)) {
|
||||
success(info)
|
||||
if (data.getUserDeviceIds(otherUserId).contains(startReq.fromDevice)) {
|
||||
success(data)
|
||||
} else {
|
||||
error()
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ class AppModule(private val context: Context) {
|
||||
}
|
||||
|
||||
single {
|
||||
IncomingVerificationRequestHandler(get(), get(), get())
|
||||
IncomingVerificationRequestHandler(context, get())
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<HomeNavigator>()
|
||||
|
||||
// TODO Move this elsewhere
|
||||
private val incomingVerificationRequestHandler by inject<IncomingVerificationRequestHandler>()
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user