diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt index d131960893..a60d0fd9ac 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt @@ -142,12 +142,12 @@ data class Event( } fun toContentStringWithIndent(): String { - val contentMap = toContent().toMutableMap() + val contentMap = toContent() return JSONObject(contentMap).toString(4) } fun toClearContentStringWithIndent(): String? { - val contentMap = this.mxDecryptionResult?.payload?.toMutableMap() + val contentMap = this.mxDecryptionResult?.payload val adapter = MoshiProvider.providesMoshi().adapter(Map::class.java) return contentMap?.let { JSONObject(adapter.toJson(it)).toString(4) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt index 78e07c9428..6ab950a1a0 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt @@ -776,14 +776,12 @@ internal class DefaultCryptoService @Inject constructor( } when (existingRequest.secretName) { -// "m.key.self_signing", SELF_SIGNING_KEY_SSSS_NAME -> { if (device.trustLevel?.isLocallyVerified() == true) { crossSigningService.onSecretSSKGossip(secretContent.secretValue) return } } -// "m.key.user_signing", USER_SIGNING_KEY_SSSS_NAME -> { if (device.trustLevel?.isLocallyVerified() == true) { cryptoStore.storePrivateKeysInfo(null, null, secretContent.secretValue) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/SecretShareRequest.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/SecretShareRequest.kt index 093387926e..86ae042166 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/SecretShareRequest.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/SecretShareRequest.kt @@ -22,7 +22,7 @@ import com.squareup.moshi.JsonClass * Class representing a room key request content */ @JsonClass(generateAdapter = true) -internal data class SecretShareRequest( +data class SecretShareRequest( @Json(name = "action") override val action: String? = GossipingToDeviceObject.ACTION_SHARE_REQUEST, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationTransaction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationTransaction.kt index 83668284a4..2563748662 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationTransaction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationTransaction.kt @@ -74,11 +74,10 @@ internal abstract class DefaultVerificationTransaction( // Mark my keys as trusted locally crossSigningService.markMyMasterKeyAsTrusted() } - - outgoingGossipingRequestManager.sendSecretShareRequest(SELF_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*"))) - outgoingGossipingRequestManager.sendSecretShareRequest(USER_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*"))) -// outgoingGossipingRequestManager.sendSecretShareRequest("m.key.self_signing", mapOf(userId to listOf(otherDeviceId ?: "*"))) -// outgoingGossipingRequestManager.sendSecretShareRequest("m.key.user_signing", mapOf(userId to listOf(otherDeviceId ?: "*"))) + if (!crossSigningService.canCrossSign()) { + outgoingGossipingRequestManager.sendSecretShareRequest(SELF_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*"))) + outgoingGossipingRequestManager.sendSecretShareRequest(USER_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*"))) + } } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsEpoxyController.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsEpoxyController.kt index 5cce238e82..8760f9ebb2 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsEpoxyController.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsEpoxyController.kt @@ -25,9 +25,11 @@ import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.internal.crypto.model.event.OlmEventContent +import im.vector.matrix.android.internal.crypto.model.event.SecretSendEventContent import im.vector.matrix.android.internal.crypto.model.rest.ForwardedRoomKeyContent import im.vector.matrix.android.internal.crypto.model.rest.GossipingToDeviceObject import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyShareRequest +import im.vector.matrix.android.internal.crypto.model.rest.SecretShareRequest import im.vector.riotx.R import im.vector.riotx.core.date.VectorDateFormatter import im.vector.riotx.core.epoxy.loadingItem @@ -35,6 +37,7 @@ import im.vector.riotx.core.extensions.exhaustive import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.resources.DateProvider import im.vector.riotx.core.resources.StringProvider +import im.vector.riotx.core.ui.list.GenericItem import im.vector.riotx.core.ui.list.genericFooterItem import im.vector.riotx.core.ui.list.genericItem import im.vector.riotx.core.ui.list.genericItemHeader @@ -81,6 +84,7 @@ class GossipingEventsEpoxyController @Inject constructor( eventList.forEachIndexed { _, event -> genericItem { id(event.hashCode()) + itemClickAction(GenericItem.Action("view").apply { perform = Runnable { interactionListener?.didTap(event) } }) title( if (event.isEncrypted()) { "${event.getClearType()} [encrypted]" @@ -133,6 +137,37 @@ class GossipingEventsEpoxyController @Inject constructor( textStyle = "bold" } +" ${encryptedContent?.senderKey}" + } else if (event.getClearType() == EventType.SEND_SECRET) { + val content = event.getClearContent().toModel() + + span("\nrequestId:") { + textStyle = "bold" + } + +" ${content?.requestId}" + span("\nFrom Device:") { + textStyle = "bold" + } + +" ${event.mxDecryptionResult?.payload?.get("sender_device")}" + } else if (event.getClearType() == EventType.REQUEST_SECRET) { + val content = event.getClearContent().toModel() + span("\nreqId:") { + textStyle = "bold" + } + +" ${content?.requestId}" + span("\naction:") { + textStyle = "bold" + } + +" ${content?.action}" + if (content?.action == GossipingToDeviceObject.ACTION_SHARE_REQUEST) { + span("\nsecretName:") { + textStyle = "bold" + } + +" ${content.secretName}" + } + span("\nrequestedBy: ") { + textStyle = "bold" + } + +"${content?.requestingDeviceId}" } } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt index bac98aeec6..48e48c125c 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/devtools/GossipingEventsPaperTrailFragment.kt @@ -21,17 +21,22 @@ import android.view.MenuItem import android.view.View import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState +import im.vector.matrix.android.api.session.events.model.Event import im.vector.riotx.R import im.vector.riotx.core.extensions.cleanup import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.platform.VectorBaseFragment +import im.vector.riotx.core.resources.ColorProvider +import im.vector.riotx.core.utils.jsonViewerStyler import kotlinx.android.synthetic.main.fragment_generic_recycler.* +import org.billcarsonfr.jsonviewer.JSonViewerDialog import javax.inject.Inject class GossipingEventsPaperTrailFragment @Inject constructor( val viewModelFactory: GossipingEventsPaperTrailViewModel.Factory, - private val epoxyController: GossipingEventsEpoxyController -) : VectorBaseFragment() { + private val epoxyController: GossipingEventsEpoxyController, + private val colorProvider: ColorProvider +) : VectorBaseFragment(), GossipingEventsEpoxyController.InteractionListener { override fun getLayoutResId() = R.layout.fragment_generic_recycler @@ -46,13 +51,13 @@ class GossipingEventsPaperTrailFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) recyclerView.configureWith(epoxyController, showDivider = true) -// epoxyController.interactionListener = this + epoxyController.interactionListener = this } override fun onDestroyView() { super.onDestroyView() recyclerView.cleanup() -// epoxyController.interactionListener = null + epoxyController.interactionListener = null } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -63,4 +68,18 @@ class GossipingEventsPaperTrailFragment @Inject constructor( return super.onOptionsItemSelected(item) } } + + override fun didTap(event: Event) { + if (event.isEncrypted()) { + event.toClearContentStringWithIndent() + } else { + event.toContentStringWithIndent() + }?.let { + JSonViewerDialog.newInstance( + it, + -1, + jsonViewerStyler(colorProvider) + ).show(childFragmentManager, "JSON_VIEWER") + } + } }