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( override suspend fun receiveSyncChanges(
toDevice: ToDeviceSyncResponse?, toDevice: ToDeviceSyncResponse?,
deviceChanges: DeviceListResponse?, deviceChanges: DeviceListResponse?,
keyCounts: DeviceOneTimeKeysCountSyncResponse? keyCounts: DeviceOneTimeKeysCountSyncResponse?,
deviceUnusedFallbackKeyTypes: List<String>?
) { ) {
withContext(coroutineDispatchers.crypto) { withContext(coroutineDispatchers.crypto) {
deviceListManager.handleDeviceListsChanges(deviceChanges?.changed.orEmpty(), deviceChanges?.left.orEmpty()) deviceListManager.handleDeviceListsChanges(deviceChanges?.changed.orEmpty(), deviceChanges?.left.orEmpty())

View file

@ -222,7 +222,13 @@ interface CryptoService {
fun start() fun start()
suspend fun onSyncWillProcess(isInitialSync: Boolean) suspend fun onSyncWillProcess(isInitialSync: Boolean)
fun isStarted(): 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 onLiveEvent(roomId: String, event: Event, isInitialSync: Boolean, cryptoStoreAggregator: CryptoStoreAggregator?)
suspend fun onStateEvent(roomId: String, event: Event, cryptoStoreAggregator: CryptoStoreAggregator?) {} suspend fun onStateEvent(roomId: String, event: Event, cryptoStoreAggregator: CryptoStoreAggregator?) {}
suspend fun onSyncCompleted(syncResponse: SyncResponse, 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. * 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") @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. * 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. * 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 val fallbackKeys: JsonDict? = null
) )

View file

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

View file

@ -263,7 +263,8 @@ internal class OlmMachine @Inject constructor(
suspend fun receiveSyncChanges( suspend fun receiveSyncChanges(
toDevice: ToDeviceSyncResponse?, toDevice: ToDeviceSyncResponse?,
deviceChanges: DeviceListResponse?, deviceChanges: DeviceListResponse?,
keyCounts: DeviceOneTimeKeysCountSyncResponse? keyCounts: DeviceOneTimeKeysCountSyncResponse?,
deviceUnusedFallbackKeyTypes: List<String>?,
): ToDeviceSyncResponse { ): ToDeviceSyncResponse {
val response = withContext(coroutineDispatchers.io) { val response = withContext(coroutineDispatchers.io) {
val counts: MutableMap<String, Int> = mutableMapOf() val counts: MutableMap<String, Int> = mutableMapOf()
@ -282,9 +283,8 @@ internal class OlmMachine @Inject constructor(
.adapter(ToDeviceSyncResponse::class.java) .adapter(ToDeviceSyncResponse::class.java)
val events = adapter.toJson(toDevice ?: ToDeviceSyncResponse()) 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 // 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>>( val outAdapter = moshi.adapter<List<Event>>(
Types.newParameterizedType( Types.newParameterizedType(

View file

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