Commit Graph

1160 Commits

Author SHA1 Message Date
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
7e142c8132 refactor(oidc): lower cognitive load by removing RegisteredClientData 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
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
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
03bbdce15f ffi: Add in_reply_to field to MessageLikeEventContent::RoomMessage 2023-09-14 12:18:30 +02:00
Jonas Platte
1cbcee4fea Use as_variant crate for shorter code 2023-09-13 18:33:33 +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
Damir Jelić
c32f2444fc Use the base64 encoding/decoding methods from vodozemac in the bindings 2023-09-08 11:43:32 +02:00
Doug
eb865f490a chore(bindings): Handle OIDC metadata changes. (#2503)
Currently when the AuthenticationService is given updated metadata, it is ignored if a dynamic registration has already been made for a selected issuer. This PR fixes that by storing the metadata's hash and resetting the store when there is a mis-match.

Additionally it moves OidcRegistrations out of the FFI into a new authentication module in the UI crate and adds some tests.
2023-09-07 17:28:58 +00:00
Mauro Romito
fa91a74452 feat(bindings): upload user avatar 2023-09-07 18:12:16 +02:00
Doug
d7f5cd51e4 chore(bindings): Add missing contacts field on OidcConfiguration. 2023-09-07 17:43:20 +02:00
Jonas Platte
e655490b9f ffi: Add is_threaded method to timeline Message object 2023-09-07 16:54:21 +02:00
Benjamin Bouvier
28ab8e9efc chore: remove Client::authentication_server_info as it's duplicated from Oidc::authentication_server_info 2023-09-07 10:34:54 +02:00
Ivan Enderlin
b8ed566d78 feat(ffi): Add bindings for RoomListService::sync_indicator.
This patch adds the `RoomListService::sync_indicator` method, along
with the `RoomListServiceSyncIndicatorListener` callback interface, and
`RoomListServiceSyncIndicator` enum.
2023-09-06 17:16:36 +02:00
Benjamin Bouvier
11b3be1a03 feat(notification client): always retry decryption if it failed before
Now that we can decrypt on both of {single|multi} process setups (i.e. available for both android
and ios), we can enable retrying decrypting notifications by default.
2023-09-05 14:17:41 +02:00
Benjamin Bouvier
f13adb24dd feat(sync service): enable the encryption sync by default 2023-09-05 14:17:41 +02:00
Benjamin Bouvier
3d89d750fb chore: rename EncryptionSync to EncryptionSyncService 2023-09-05 14:17:41 +02:00
Benjamin Bouvier
ea2826aac6 chore(FFI): update bindings for changes to the NotificationClient builder 2023-09-05 11:17:14 +02:00
Jonas Platte
2b18a02488 ffi: Use avatar_url from sliding sync for RoomInfo where applicable 2023-09-01 10:47:48 +02:00
Jonas Platte
e02676616f sdk: Make use of clonable FnOnce in event handlers 2023-09-01 10:42:22 +02:00
Benjamin Bouvier
11404010e6 chore: disable colors for logging in FFI for logcat and stdout too 2023-08-31 12:13:25 +02:00
Jonas Platte
06a19f016e ffi: Only ever call ClientDelegate methods in a blocking task
… and clean up a few unnecessary Arc's.
2023-08-30 15:29:06 +02:00
Jonas Platte
5630851062 Upgrade Ruma 2023-08-30 15:22:00 +02:00
Ivan Enderlin
6b50a8988b Merge pull request #2463 from matrix-org/jmartinesp/add-x86-64-workaround-to-crypto-sdk-in-main
Add the x86-64 Android workaround to the Crypto SDK too
2023-08-30 15:12:17 +02:00
Jonas Platte
1311ddbae3 ffi: Disable colorization of tracing fields 2023-08-30 14:07:22 +02:00
Ivan Enderlin
5564d323f5 fix(ui): Try to make RoomListService fast for gigantic accounts with various network speeds
fix(ui): Try to make `RoomListService` fast for gigantic accounts with various network speeds
2023-08-30 14:06:23 +02:00
Ivan Enderlin
3062f30e08 chore(ffi): Add the RoomListServerState::Recovering variant. 2023-08-30 13:17:05 +02:00
Jonas Platte
04fee2952f sdk: Split widget EventFilter into sub-types
… and move them into their own module.

Co-authored-by: Timo K <toger5@hotmail.de>
Co-authored-by: Daniel Abramov <inetcrack2@gmail.com>
2023-08-30 12:57:54 +02:00
Jonas Platte
959b594c43 sdk: Rename widget::Info to WidgetSettings 2023-08-30 12:57:54 +02:00
Alfonso Grillo
c567f963d5 ffi: Add send fn's for poll response and poll end 2023-08-30 09:44:08 +00:00
Nicolas Mauri
1cc11ae988 feat(ffi): Add a notification_mode property to room_info (#2460)
* feat(ffi): Add a notification_mode property to room_info
* feat(sdk): Add a notification_mode() function to Room
* Fix Rust syntax
2023-08-29 12:25:26 +00:00
Doug
58d30454ae feat(bindings): Add logo_uri to OidcConfiguration
… and make most OidcConfiguration properties optional.
2023-08-29 13:35:10 +02:00
Jonas Platte
0590543df1 ffi: Add custom tracing log formatter (#2464)
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-08-28 15:05:21 +00:00
Benjamin Bouvier
b6c658aefa feat: introduce timer helper 2023-08-28 16:52:43 +02:00
aringenbach
8cb00510d2 ffi: use RoomMessageEventContentWithoutRelation for send / reply / edit 2023-08-28 11:26:51 +02:00
Jorge Martín
e7ad46f5a0 Fix formatting 2023-08-25 14:37:09 +02:00
Jorge Martín
1d08ffa05e Add the x86-64 Android workaround to the Crypto SDK too 2023-08-25 13:31:12 +02:00
Jonas Platte
e02aa6b132 ffi: Add Room::{room_info, subscribe_to_room_info_updates} 2023-08-25 11:39:57 +02:00
Jonas Platte
320f5c2155 Rename feature flag for widgets 2023-08-24 14:55:55 +02:00
Jonas Platte
1c3dd38b97 ffi: Add widget API skeleton 2023-08-24 14:55:55 +02:00
Jonas Platte
aac6294755 Rename test modules to tests
… for consistency.
2023-08-24 12:28:34 +02:00
Jonas Platte
3c8a59a43a Remove module::* imports 2023-08-24 12:28:34 +02:00
Jonas Platte
2fb6bdc24c Fix more clippy lints 2023-08-23 17:20:11 +02:00
Marco Romano
3bc7b9136e ui: Add support for polls in timeline 2023-08-23 12:57:52 +00:00