rust fallback key support + stable ids

This commit is contained in:
valere 2023-01-30 15:24:56 +01:00
parent c4e03c59a0
commit 51b960361b
7 changed files with 27 additions and 11 deletions

View File

@ -1033,7 +1033,8 @@ internal class DefaultCryptoService @Inject constructor(
override suspend fun receiveSyncChanges(
toDevice: ToDeviceSyncResponse?,
deviceChanges: DeviceListResponse?,
keyCounts: DeviceOneTimeKeysCountSyncResponse?
keyCounts: DeviceOneTimeKeysCountSyncResponse?,
deviceUnusedFallbackKeyTypes: List<String>?
) {
withContext(coroutineDispatchers.crypto) {
deviceListManager.handleDeviceListsChanges(deviceChanges?.changed.orEmpty(), deviceChanges?.left.orEmpty())

View File

@ -222,7 +222,13 @@ interface CryptoService {
fun start()
suspend fun onSyncWillProcess(isInitialSync: Boolean)
fun isStarted(): Boolean
suspend fun receiveSyncChanges(toDevice: ToDeviceSyncResponse?, deviceChanges: DeviceListResponse?, keyCounts: DeviceOneTimeKeysCountSyncResponse?)
suspend fun receiveSyncChanges(
toDevice: ToDeviceSyncResponse?,
deviceChanges: DeviceListResponse?,
keyCounts: DeviceOneTimeKeysCountSyncResponse?,
deviceUnusedFallbackKeyTypes: List<String>?)
suspend fun onLiveEvent(roomId: String, event: Event, isInitialSync: Boolean, cryptoStoreAggregator: CryptoStoreAggregator?)
suspend fun onStateEvent(roomId: String, event: Event, cryptoStoreAggregator: CryptoStoreAggregator?) {}
suspend fun onSyncCompleted(syncResponse: SyncResponse, cryptoStoreAggregator: CryptoStoreAggregator)

View File

@ -64,5 +64,12 @@ data class SyncResponse(
* but that algorithm is not listed in device_unused_fallback_key_types, the client will upload a new key.
*/
@Json(name = "org.matrix.msc2732.device_unused_fallback_key_types")
val deviceUnusedFallbackKeyTypes: List<String>? = null,
)
val devDeviceUnusedFallbackKeyTypes: List<String>? = null,
@Json(name = "device_unused_fallback_key_types")
val stableDeviceUnusedFallbackKeyTypes: List<String>? = null,
) {
@Transient
val deviceUnusedFallbackKeyTypes: List<String>? = stableDeviceUnusedFallbackKeyTypes ?: devDeviceUnusedFallbackKeyTypes
}

View File

@ -46,6 +46,6 @@ internal data class KeysUploadBody(
* If the user had previously uploaded a fallback key for a given algorithm, it is replaced.
* The server will only keep one fallback key per algorithm for each user.
*/
@Json(name = "org.matrix.msc2732.fallback_keys")
@Json(name = "fallback_keys")
val fallbackKeys: JsonDict? = null
)

View File

@ -183,7 +183,8 @@ internal class SyncResponseHandler @Inject constructor(
cryptoService.receiveSyncChanges(
syncResponse.toDevice,
syncResponse.deviceLists,
syncResponse.deviceOneTimeKeysCount
syncResponse.deviceOneTimeKeysCount,
syncResponse.deviceUnusedFallbackKeyTypes
)
}.also {
Timber.v("Finish handling toDevice in $it ms")

View File

@ -263,7 +263,8 @@ internal class OlmMachine @Inject constructor(
suspend fun receiveSyncChanges(
toDevice: ToDeviceSyncResponse?,
deviceChanges: DeviceListResponse?,
keyCounts: DeviceOneTimeKeysCountSyncResponse?
keyCounts: DeviceOneTimeKeysCountSyncResponse?,
deviceUnusedFallbackKeyTypes: List<String>?,
): ToDeviceSyncResponse {
val response = withContext(coroutineDispatchers.io) {
val counts: MutableMap<String, Int> = mutableMapOf()
@ -282,9 +283,8 @@ internal class OlmMachine @Inject constructor(
.adapter(ToDeviceSyncResponse::class.java)
val events = adapter.toJson(toDevice ?: ToDeviceSyncResponse())
// TODO once our sync response type parses the unused fallback key
// field pass in the list of unused fallback keys here
val receiveSyncChanges = inner.receiveSyncChanges(events, devices, counts, unusedFallbackKeys = null)
val receiveSyncChanges = inner.receiveSyncChanges(events, devices, counts, deviceUnusedFallbackKeyTypes)
val outAdapter = moshi.adapter<List<Event>>(
Types.newParameterizedType(

View File

@ -605,10 +605,11 @@ internal class RustCryptoService @Inject constructor(
override suspend fun receiveSyncChanges(
toDevice: ToDeviceSyncResponse?,
deviceChanges: DeviceListResponse?,
keyCounts: DeviceOneTimeKeysCountSyncResponse?
keyCounts: DeviceOneTimeKeysCountSyncResponse?,
deviceUnusedFallbackKeyTypes: List<String>?,
) {
// Decrypt and handle our to-device events
val toDeviceEvents = this.olmMachine.receiveSyncChanges(toDevice, deviceChanges, keyCounts)
val toDeviceEvents = this.olmMachine.receiveSyncChanges(toDevice, deviceChanges, keyCounts, deviceUnusedFallbackKeyTypes)
// Notify the our listeners about room keys so decryption is retried.
toDeviceEvents.events.orEmpty().forEach { event ->