Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

BillCarsonFr
Copy link
Member

Pull Request Checklist

Fixes element-hq/element-ios#7795

The new MSC3814matrix-org/matrix-spec-proposals#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
Copy link
Member Author

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.

@BillCarsonFr BillCarsonFr marked this pull request as ready for review June 5, 2024 16:28
/**
The device keys per devices per users.
*/
@property (nonatomic) NSDictionary<NSString *, id> *deviceKeys;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the existing MXKeysQueryResponse this was a MXUsersDevicesMap<MXDeviceInfo*> *deviceKeys

Copy link
Member

@stefanceriu stefanceriu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a sensible approach to me, I trust you that you tested it and it works properly 😉

Copy link
Member

@uhoreg uhoreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the code, but looks plausible.

/**
Cross-signing keys per users.
*/
@property (nonatomic) NSDictionary<NSString*, MXCrossSigningInfo*> *crossSigningKeys;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How easy would it be to do the same thing to the cross-signing keys, because we'll have the same problem here. If it's easy, may as well do it while we're touching the code here.

@BillCarsonFr BillCarsonFr merged commit e1288e7 into develop Jun 24, 2024
3 checks passed
@BillCarsonFr BillCarsonFr deleted the valere/fix_sending_to_dehydrated_device branch June 24, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Element-iOS session doesn't encrypt for a dehydrated device
3 participants