Add incoming key forward trail

This commit is contained in:
Valere 2022-03-16 17:47:52 +01:00
parent b1db6ca180
commit ae6df469e2
6 changed files with 76 additions and 26 deletions

View file

@ -234,6 +234,15 @@ internal class MXMegolmDecryption(
fromDevice = fromDevice,
event = event)
cryptoStore.saveIncomingForwardKeyAuditTrail(
roomId = roomKeyContent.roomId,
sessionId = roomKeyContent.sessionId,
senderKey = senderKey,
algorithm = roomKeyContent.algorithm ?: "",
userId = event.senderId ?: "",
deviceId = fromDevice ?: "",
chainIndex = index.toLong())
// The index is used to decide if we cancel sent request or if we wait for a better key
outgoingKeyRequestManager.postCancelRequestForSessionIfNeeded(roomKeyContent.sessionId, roomKeyContent.roomId, senderKey, index)
}

View file

@ -417,6 +417,16 @@ internal interface IMXCryptoStore {
chainIndex: Long?
)
fun saveIncomingForwardKeyAuditTrail(
roomId: String,
sessionId: String,
senderKey: String,
algorithm: String,
userId: String,
deviceId: String,
chainIndex: Long?
)
fun addNewSessionListener(listener: NewSessionListener)
fun removeSessionListener(listener: NewSessionListener)

View file

@ -1269,30 +1269,51 @@ internal class RealmCryptoStore @Inject constructor(
}
}
override fun saveForwardKeyAuditTrail(roomId: String,
sessionId: String,
senderKey: String,
algorithm: String,
userId: String,
deviceId: String,
chainIndex: Long?) {
monarchy.writeAsync { realm ->
val now = System.currentTimeMillis()
realm.createObject<AuditTrailEntity>().apply {
this.ageLocalTs = now
this.type = TrailType.OutgoingKeyForward.name
val info = ForwardInfo(
roomId = roomId,
sessionId = sessionId,
senderKey = senderKey,
alg = algorithm,
userId = userId,
deviceId = deviceId,
chainIndex = chainIndex
)
MoshiProvider.providesMoshi().adapter(ForwardInfo::class.java).toJson(info)?.let {
this.contentJson = it
}
override fun saveForwardKeyAuditTrail(roomId: String,
sessionId: String,
senderKey: String,
algorithm: String,
userId: String,
deviceId: String,
chainIndex: Long?) {
saveForwardKeyTrail(roomId, sessionId, senderKey, algorithm, userId, deviceId, chainIndex, false)
}
override fun saveIncomingForwardKeyAuditTrail(roomId: String,
sessionId: String,
senderKey: String,
algorithm: String,
userId: String,
deviceId: String,
chainIndex: Long?) {
saveForwardKeyTrail(roomId, sessionId, senderKey, algorithm, userId, deviceId, chainIndex, true)
}
private fun saveForwardKeyTrail(roomId: String,
sessionId: String,
senderKey: String,
algorithm: String,
userId: String,
deviceId: String,
chainIndex: Long?,
incoming: Boolean
) {
monarchy.writeAsync { realm ->
val now = System.currentTimeMillis()
realm.createObject<AuditTrailEntity>().apply {
this.ageLocalTs = now
this.type = if (incoming) TrailType.IncomingKeyForward.name else TrailType.OutgoingKeyForward.name
val info = ForwardInfo(
roomId = roomId,
sessionId = sessionId,
senderKey = senderKey,
alg = algorithm,
userId = userId,
deviceId = deviceId,
chainIndex = chainIndex
)
MoshiProvider.providesMoshi().adapter(ForwardInfo::class.java).toJson(info)?.let {
this.contentJson = it
}
}
}

View file

@ -49,6 +49,12 @@ class GossipingEventsSerializer {
append("code: ${it.code} ")
}
}
TrailType.IncomingKeyForward -> {
append("from:${info.userId}|${info.deviceId} - ")
(trail.info as? ForwardInfo)?.let {
append("chainIndex: ${it.chainIndex} ")
}
}
else -> {
append("??")
}

View file

@ -89,10 +89,13 @@ class GossipingTrailPagedEpoxyController @Inject constructor(
// no additional info
}
TrailType.IncomingKeyForward -> {
val fInfo = event.info as ForwardInfo
span("\nchainIndex: ") {
textStyle = "bold"
}
+"${fInfo.chainIndex}"
}
TrailType.Unknown -> {
}
}
}

View file

@ -53,6 +53,7 @@ class IncomingKeyRequestPagedController @Inject constructor(
textStyle = "bold"
}
span("${roomKeyRequest.userId}")
+"\n"
+host.vectorDateFormatter.format(roomKeyRequest.localCreationTimestamp, DateFormatKind.DEFAULT_DATE_AND_TIME)
span("\nsessionId:") {
textStyle = "bold"