mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 18:36:21 +03:00
rust fallback key support + stable ids
This commit is contained in:
parent
c4e03c59a0
commit
51b960361b
7 changed files with 27 additions and 11 deletions
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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 ->
|
||||
|
|
Loading…
Reference in a new issue