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

Add restore_with_access_token to the FFI auth service. #866

Merged
merged 2 commits into from
Jul 26, 2022

Conversation

pixlwave
Copy link
Member

@pixlwave pixlwave commented Jul 20, 2022

This PR is likely a temporary addition until #859 is implemented to allow for element-hq/element-x-ios#137 to be completed with the proof of concept implementation.

The new method first creates an in-memory client to perform a /whoami and get the user ID and device ID. Then it creates a second client with a store path set and sets this one up for real.

Forked from #860 so would need to wait for that to be merged first.

@pixlwave pixlwave requested a review from a team July 20, 2022 19:25
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

So this is one of those things that scares me quite a bit. Namely if we're logging in with an access token, that token will have a device ID attached to it and this device ID might have already some E2EE keys attached to it.

If the device already has some E2EE keys attached to it and we locally aren't the owners of those keys, we're going to try to upload and attach another pair of E2EE keys to the device.

This can easily lead to broken E2EE setups where we can't decrypt other peoples messages, nor are they able to decrypt ours.

One way to ensure that the device isn't already taken is to send out a /keys/query request, and see if there are any device keys attached to this device ID.

On the other hand, since this is mostly a WIP thing while OIDC gets developed and is only touching the bindings I'm inclined to let it slide. Please just add a big warning or TODO about this.

bindings/matrix-sdk-ffi/src/authentication_service.rs Outdated Show resolved Hide resolved
@zecakeh
Copy link
Collaborator

zecakeh commented Jul 21, 2022

In my opinion this could be improved (as in less hacky) and then reused for #859, because the same logic needed here will be required for implementing it. The only thing that would change after it's implemented is that this method wouldn't need to be public anymore.

By "hacky" I mean that we shouldn't have to create a temporary client with a fake user ID and device ID just to be able to make a call to /whoami.

@pixlwave
Copy link
Member Author

The direction OIDC is going in is to not generate the device ID on the server and instead leave it to the clients to do. In fact, it looks like this PR was just merged: matrix-org/matrix-authentication-service#285

I'll find out more info about this.

@zecakeh
Copy link
Collaborator

zecakeh commented Jul 21, 2022

Ah I didn't know about that, it's good to know.

@pixlwave
Copy link
Member Author

pixlwave commented Jul 22, 2022

@zecakeh More information on this:

do it during the login process. You would have to include a scope like ‘urn:matrix:device:XXYYZZ’ in the authorisation request

@pixlwave pixlwave force-pushed the doug/login-access-token branch from 2141808 to 535d230 Compare July 22, 2022 16:28
@pixlwave pixlwave changed the title Add login_access_token to the FFI auth service. Add restore_with_access_token to the FFI auth service. Jul 22, 2022
@pixlwave
Copy link
Member Author

pixlwave commented Jul 22, 2022

if we're logging in with an access token, that token will have a device ID attached to it and this device ID might have already some E2EE keys attached to it.

I've moved the device ID creation out to the app (using it to define the login scope as mentioned above) and have updated this PR to have a restore_with_access_token method that requires both the access token and the device ID.

I've also made some small tweaks to use the existing discovery client for the whoami similarly to #859.

@pixlwave pixlwave requested a review from poljar July 26, 2022 09:58
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

This approach is much more reasonable, thanks. Just left a small question, probably not important.

.map_err(AuthenticationError::from)?;

// Restore the client using the session.
client
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to modify the original client behind the mutex as well, or is that not important?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm that's an interesting point. I don't see it as important as the service should be finished with when this succeeds. I think its fine for now but maybe we'll need to revisit this in the future 👍

@pixlwave pixlwave force-pushed the doug/login-access-token branch from 535d230 to bda7db3 Compare July 26, 2022 13:53
pixlwave added 2 commits July 26, 2022 15:00
Add a device ID parameter to restore_with_access_token
@pixlwave pixlwave force-pushed the doug/login-access-token branch from bda7db3 to a951a27 Compare July 26, 2022 14:00
@pixlwave pixlwave changed the base branch from doug/client-path to main July 26, 2022 14:02
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Looks good.

@poljar poljar enabled auto-merge July 26, 2022 14:06
@poljar poljar disabled auto-merge July 26, 2022 14:49
@poljar poljar merged commit 4175e6b into main Jul 26, 2022
@poljar poljar deleted the doug/login-access-token branch July 26, 2022 15:10
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.

3 participants