matrix-org / matrix-ios-sdk

The Matrix SDK for iOS
Apache License 2.0
451 stars 211 forks source link

Fix | Share room keys with dehydrated devices with rust stack #1858

Closed BillCarsonFr closed 3 months ago

BillCarsonFr commented 4 months ago

Pull Request Checklist

Fixes https://github.com/element-hq/element-ios/issues/7795

The new MSC3814https://github.com/matrix-org/matrix-spec-proposals/pull/3814 is introducing a new format for dehydrated devices (to get messages even if all your sessions are logged out). As per the new format, the DeviceKey payload from a keys/query call now contains a new boolean field dehydrated, that is used when computing the signature. The problem is that the SDK converts the http response to a JSON Model MXKeysQueryResponse and this model was not aware of that field. As a consequence when passing back the response to rust via markRequestAsSent using model.jsonString(), the dehydrated field was dropped, thus the rust layer was refusing the device because the signature was invalid.

First approach would be to add the dehydrated field to the model, but this is not very future proof as any new future field would cause the same problem. The rust crypto stack also just pass this payload and is not using it (the legacy stack neeeded the typed model).

Unfortunatly I cannot just modify the existing model to just use a generic Dictionnary because some parts of the sdk for the legacy crypto still needed it. So I created a new MXKeysQueryResponseRaw almost similar to the existing MXKeysQueryResponse, but that is not trying to convert the device info to a typed model. This is now used by the rust layer to query and pass back to the olm machine.

BillCarsonFr commented 4 months ago

I have been testing this PR against a local Web instance running on a synapse with msc3814_enabled. Not sure how possible to do a test in SDK for that.