Commit Graph

7139 Commits

Author SHA1 Message Date
Damir Jelić
b61f2fbdc4 Test if we're doing the correct request when marking a room as a DM 2023-09-15 16:51:05 +02:00
Damir Jelić
a61205088b Fetch the account data from the server before marking rooms as DMs 2023-09-15 16:51:05 +02:00
Damir Jelić
de90cf413b Add a method to retrieve global account data events from the server 2023-09-15 16:47:22 +02:00
Benjamin Bouvier
774f695eb8 chore(doc): fix documentation 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
ab0982e512 chore(matrix auth): simplify a bit the code of matrix auth's refresh_access_token 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
0cb5f666ae chore(oidc): remove a few unnecessary wrappers, now that OidcCtx is in an Arc'd data structure 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
b9b042ec4a chore(auth): prefix Session data structures with the auth kind 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
7665b15c5a chore(auth): prefix SessionTokens data structures with the auth kind 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
b42cb1c43f chore(oidc): rename OidcContext to OidcCtx for symmetry with AuthCtx 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
2acf21fcd4 refactor(oidc): move AuthCtx::authentication_server_info into OidcContext 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
3144d87c3a refactor(oidc): put the OidcContext in the AuthCtx 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
7e142c8132 refactor(oidc): lower cognitive load by removing RegisteredClientData 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
23f4aedf47 chore(oidc): update some code comments 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
6db19198fc chore(oidc): restore_registered_client doesn't need to be async 2023-09-15 13:03:11 +02:00
Benjamin Bouvier
dde2f408c5 chore(sliding sync): log the room id in the limited flag computation 2023-09-14 19:14:52 +02:00
Benjamin Bouvier
b749b3546f feat(auth): make the session callbacks work for the matrix auth scheme too 2023-09-14 17:42:56 +02:00
Jorge Martín
6c45e56d61 ffi: Add Client.remove_avatar function 2023-09-14 17:02:23 +02:00
Jonas Platte
84daf1f079 ffi: Add RoomListItem::room_info_blocking 2023-09-14 16:49:36 +02:00
Nicolas Mauri
6d8d174a5e ffi: RoomInfo notification mode must reflect the user-defined mode (#2545) 2023-09-14 14:23:32 +02:00
Jonas Platte
fd17bce300 ui: Fix day divider logic
… for when a remote event is re-received while a local echo is pending.
Also simplify test_togglling_reaction integration test so it still passes.
2023-09-14 14:14:44 +02:00
Benjamin Bouvier
67b0305a3e feat: Add a cross-process lock mechanism for OIDC token refresh (#2440)
This adds a cross-process lock for refresh to work correctly.

We want to coordinate token refresh across multiple processes. For that, we're using a cross-process lock, and a value in the database identifying the latest session tokens that are valid (a hash of the actual tokens, for security reasons).

Whenever we run into an HTTP error indicating that the tokens have been invalidated, we try to refresh the access tokens; that's already existing prior to this PR. The novelty introduced is that we take a cross-process lock before doing so, now. Taking this lock will also load a session hash from the database, and we'll compare it against the latest "known" session hash (that the current process saved into its memory).

If there's no mismatch (i.e. the database and the currently known are the same), then we're all good and can keep going with the refresh, synchronize the hashes everywhere (in-memory and database), make sure the client is notified about it (through a new user-provided callback `SaveSessionCallback`; on iOS this will save it into the device's keychain).

Otherwise, that means another process has done a refresh under our feet. In that case, we ask an authoritative source for trusted session tokens. On iOS, they're reloaded from the device keychain; that happens through a new user-provided callback `ReloadSessionCallback`. Then, we make sure that the DB and the in-memory value recall this latest value.

An embedder who would like to make use of the cross-process locking mechanism should call `client.oidc().set_session_callbacks` and `client.oidc().enable_cross_process_refresh`. If only interested with the pings for new sessions, the client may only call `client.oidc().set_session_callbacks`.

Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2418.
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2476

## Future improvements

- More testing of the whole flow. Not sure if mocking will be quite fit for OIDC, as this may require setting up an HTTPS server for the authentication code exchange and other OIDC-specific flows.
- Get rid of `SessionChange`, which duplicates in some way how a client can be notified about session changes.

---

* chore: replace manual StateMemoryStore::new with derived Default

* feat: add store backing for cross-process locking in state store

* chore: rename CryptoStoreLock to CrossProcessStoreLock

* chore: generalize cross-process lock

* feat: move the cross-process locking mechanism to the main crate

* feat: add support for cross-process store lock in the state store 🥳

* feat: implement a cross-process lock for OIDC token refresh

* chore: tweak comment + function name

* feat: make restore_session safe wrt cross-process lock

* feat: add FFI method + add mechanism to reload from keychain

* fix rename

* feat: return early when there was another process refreshed tokens

* fix FFI compile error + tweak some comments

* fix: put the reload_session callback and cross-process locks behind Arc to share them across clients

* feat: Add session retrieval to FFI.

* HACKY; KIDS DON'T DO THIS AT HOME

* chore: log if the hash from db isn't the same from the one from the returned session

* make it simpler to test OIDC token refresh

* some work, that includes fixes and a first test

* feat: require that the reload_session_callback be set at the same time as the cross-process lock

* chore: traces, traces everywhere

* fix: inherit session_change_sender when creating the notification client

* Some FFI improvements to help with tokio problems

* feat: resilient mode when DB/callback disagree about session (callback wins!)

* chore: move sender.send to the finish_refreshing function

* feat: add a save_session callback in the FFI and use it to save the session in keychain while holding XP lock

* fix test expectation after adding the check 🤷

* feat: split the ClientDelegate into two parts, including brand new ClientSessionDelegate

* chore: get rid of lease lock impl in the state store, as it's now unused

* a mix of fmt + clippy

* feat: add ctor for the crossprocessrefreshlockctx

* Include user ID when retrieving session.

Necessary as this isn't known when creating the AuthenticationService.

* yo dawg, you can't block while you block

* share auth data between parent and child client, add lock, AAAAAA this is messy

* tweaks

* feat: make the cross-process store locks generic

And move the implementation to the common crate.

* chore: upgrade some code comments to doc comments in `OngoingMigration`

* feat: implement `CryptoStore::remove_custom_value`

As it's going to be used for the OIDC PR, so as to remove a remembered hash of session tokens.

* remove unneeded remnants

* correctly wait for current request to finish

* feat: make it possible to setup session delegates on android too(?)

* put the cross process stuff in its own file

* typos 🤷

* fix: detach before sending token refresh request, to make sure the response tokens are always properly saved

* kleepee

* First round of review, thanks jonas!

* review round 2. FIGHT

* remove useless logs + avoid using deref explicitly

* more specialized error when cross-process lock is enabled without session callbacks

* fix: avoid cyclic reference between the session callback and client

---------

Co-authored-by: Doug <douglase@element.io>
Co-authored-by: Jonas Platte <jplatte@matrix.org>
2023-09-14 12:47:47 +02:00
Jonas Platte
0c4b8c602c ui: Sanitize m.room.message events in notifications
… including reply fallback stripping.
2023-09-14 12:18:30 +02:00
Jonas Platte
03bbdce15f ffi: Add in_reply_to field to MessageLikeEventContent::RoomMessage 2023-09-14 12:18:30 +02:00
Jonas Platte
af400357f5 Use Self keyword more 2023-09-13 18:33:33 +02:00
Jonas Platte
4da3806a01 indexeddb: Simplify filter_map closure 2023-09-13 18:33:33 +02:00
Jonas Platte
1cbcee4fea Use as_variant crate for shorter code 2023-09-13 18:33:33 +02:00
Jonas Platte
1542abd25a ui: Adjust logs to use natural numbering 2023-09-13 15:17:55 +02:00
Doug
3b685e01b5 feat(bindings): Expose account management action in the bindings. 2023-09-13 14:14:02 +02:00
Doug
7d8c6521ed feat(sdk): Add an action parameter to the OIDC account URL. 2023-09-13 14:14:02 +02:00
Jonas Platte
9a30878f43 ui: Fix a typo 2023-09-13 11:45:11 +02:00
Jonas Platte
958ed1855e ui: Log a warning when TimelineInnerStateTransaction is cancelled 2023-09-13 11:45:11 +02:00
Jonas Platte
a1d730f87b ui: Simplify TimelineInner subscription methods 2023-09-13 11:45:11 +02:00
Jonas Platte
fa0d949600 ui: Change TimelineInnerStateTransaction to be committed explicitly 2023-09-13 11:45:11 +02:00
Jonas Platte
be4c376423 ui: Use ObservableVectorTransaction for timeline 2023-09-13 11:45:11 +02:00
Jonas Platte
55be56e78f ui: Move some functions to TimelineInnerMetadata 2023-09-13 11:45:11 +02:00
Jonas Platte
c6fd3ec4b0 ui: Split non-items fields of TimelineInnerState into separate struct
… as a preparation for further refactorings.
2023-09-13 11:45:11 +02:00
Jonas Platte
7168df8b30 ui: Fix indentation 2023-09-13 11:45:11 +02:00
Jonas Platte
7fad343390 ui: Remove unused import 2023-09-13 11:45:11 +02:00
Jonas Platte
768f062e0c ui: Ignore flaky test
It's still compiled, but not run unless `--ignored` or `--include-ignored`
is passed on the commandline.
2023-09-13 11:40:54 +02:00
Jonas Platte
96ccd6e2bd sdk: Fix unit tests not compiling without testing feature 2023-09-12 18:31:15 +02:00
Jonas Platte
a4101e2f45 Upgrade Ruma 2023-09-12 17:19:56 +02:00
Benjamin Bouvier
d35a8b7fa0 chore: remove one level of indent thanks to let else 2023-09-12 17:02:42 +02:00
Benjamin Bouvier
2d932dc29f feat: don't process the limited flag for e2ee-only sliding syncs 2023-09-12 17:02:42 +02:00
Benjamin Bouvier
654a2f2495 fix(sliding sync): don't mark a response to a locally empty room as limited
When receiving a sliding sync room response for a room that had no local events in its timeline cache,
we'd mark the room as limited before, which is incorrect. It was made worse by the fact that later in
the code, we'd clear the local cache if a room was marked as limited, so this is a problem that would
repeat itself over time (assuming empty responses for that room).

This fixes it and unifies logs so there's only one log line per room, at most.

Fixes https://github.com/vector-im/element-x-android/issues/1281
Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/2540
2023-09-12 17:02:42 +02:00
Jonas Platte
a53bfe5748 Some documentation cleanup 2023-09-12 09:25:19 +02:00
Benjamin Bouvier
b565acd462 feat: log the x-sentry-event-id if we receive it from the server 2023-09-11 14:41:42 +02:00
Jonas Platte
6131e41183 sdk: Replace deprecated function 2023-09-08 12:35:01 +02:00
Jonas Platte
d4904a01b0 Upgrade dependencies
Most notably eyeball-im-util 0.3.1, which includes an important bugfix.
2023-09-08 12:35:01 +02:00
Damir Jelić
c32f2444fc Use the base64 encoding/decoding methods from vodozemac in the bindings 2023-09-08 11:43:32 +02:00
Damir Jelić
72e3079aab Use the base64 encoding/decoding functions from vodozemac 2023-09-08 11:43:32 +02:00