Commit Graph

6331 Commits

Author SHA1 Message Date
Damir Jelić
a94e2f06ee Ensure that we're not creating the same session twice
Usually it's impossible to create a Olm session from a pre-key message
twice. The one-time key that should be used for the 3DH step will be
used up and we're going to throw a `MissingOneTimeKey` error.

This used to be true and unproblematic until we added fallback keys,
these keys will not get discarded immediately after they have been used
once.

This means that a pre-key message, for which we already have a Session,
but decryption for it fails, might create a new Session overwriting the
existing one which will essentially reset the ratchet.
2023-06-16 16:56:09 +02:00
Damir Jelić
817dcde4d8 Test that we're not able to decrypt replayed messages 2023-06-16 16:56:09 +02:00
Benjamin Bouvier
76ed3511b5 Add a value-based lock in the CryptoStores (#2049)
This implements a value-based lock in the crypto stores. The intent is to use that for multiple processes to be able to make writes into the store concurrently, while still cooperating on who does them. In particular, we need this for #1928, since we may have up to two different processes trying to write into the crypto store at the same time.

## New methods in the `CryptoStore` trait

The idea is to introduce two new methods touching **custom values** in the crypto store:

- one to atomically insert a value, only if it was missing (so, not following the semantics of `upsert` used in the `set_custom_value`) 
- one to atomically remove a custom value

Those two operations match the semantics we want:

- take the lock only if it ain't taken already == insert an entry only if it was missing
- release the lock = remove the entry

By looking at the number of lines affected by the query, we can infer whether the insert/remove happened or not, that is, if we managed to take the lock or not.

## High-level APIs

I've also added an high-level API, `CryptoStoreLock`, that helps managing such a lock, and adds some niceties on top of that:

- exponential backoff to retry attempts at acquiring the lock, when it was already taken
- attempt to gracefully recover when the lock has been taken by an app that's been killed by the environment
- full configuration of the key / value / backoff parameters

While it'd be nice to have something like a `CryptoStoreLockGuard`, it's hard to implement without being racy, because of the `async` statements that would happen in the `Drop` method (and async drop isn't stable yet).

## Test program

There's also a test program in which I shamelessly show my rudimentary unix skills; I've put it in the `labs/` directory but this could as well be a large integration test. A parent program initially fills a custom crypto store, then creates a `pipe()` for 1-way communication with a child created with `fork()`; then the parent sends commands to the child. These commands consist in reading and writing into the crypto store, using a lock. And while the child attempts to perform these operations, the parent tries hard to get the lock at the same time. This helps figuring out a few issues and making sure that cross-process locking would work as intended.
2023-06-16 13:05:54 +00:00
Ivan Enderlin
1660c71dfd feat(ui): Add bump_event_types for all_rooms in RoomList
feat(ui): Add `bump_event_types` for `all_rooms` in `RoomList`
2023-06-16 14:52:10 +02:00
Ivan Enderlin
646fb35b3a feat(ui): Add bump_event_types for all_rooms in RoomList.
This patch configures the `bump_event_types` paramter for the
`all_rooms` list in `RoomList`.
2023-06-16 14:49:08 +02:00
Benjamin Bouvier
bae1a71c81 feat: make OlmMachine resettable (#2091)
* feat: make `OlmMachine` resettable by making it an Arc<RwLock> instead of a OnceCell
* chore: fix e2e-encryption scoping
2023-06-16 12:39:08 +00:00
Ivan Enderlin
3d859674a8 fix(ui): Enable SS caching on RoomList
fix(ui): Enable SS caching on `RoomList`
2023-06-16 14:36:21 +02:00
Ivan Enderlin
a75808e338 fix(ui): Enable SS caching on RoomList. 2023-06-16 14:31:45 +02:00
Ivan Enderlin
dc06893130 fix(sdk): Disable the receipts extension temporarily
fix(sdk): Disable the `receipts` extension temporarily
2023-06-16 14:06:29 +02:00
Ivan Enderlin
489898fd40 fix(sdk): Disable the receipts extension temporarily.
Please see https://github.com/matrix-org/matrix-rust-sdk/issues/2037.
2023-06-16 13:40:38 +02:00
Ivan Enderlin
85b6eaa4c7 feat(ffi): Implement RoomList::invites
feat(ffi): Implement `RoomList::invites`
2023-06-16 13:31:53 +02:00
Ivan Enderlin
305d55d551 feat(base) In Sliding Sync, find out which rooms we have left from state events
In Sliding Sync, find out which rooms we have left from state events
2023-06-16 13:27:28 +02:00
Ivan Enderlin
bae6fc71d0 test(ui): Add a test specifically for RoomList::invites. 2023-06-16 13:10:36 +02:00
Ivan Enderlin
7a1d59e9a2 feat(ffi): Implement RoomList::invites. 2023-06-16 12:43:36 +02:00
Ivan Enderlin
e09a44831b feat(ui): Implement RoomList::invites. 2023-06-16 12:43:12 +02:00
Ivan Enderlin
5d82d5db89 feat(ui): Add the invites list in the RoomList.
The `invites` list is added when the first rooms are loaded, so that it
doesn't slow the first initial start up.
2023-06-16 12:28:42 +02:00
Richard van der Hoff
6199ca069c crypto-js: Add register_changes_callback methods to the verification classes (#2067) 2023-06-16 11:25:50 +01:00
Ivan Enderlin
c9a9a5c20a fix(ui): SlidingSync::subscribe_to_room marks room as having missing members
fix(ui): `SlidingSync::subscribe_to_room` marks room as having missing members
2023-06-16 11:45:37 +02:00
Ivan Enderlin
a99a7b4a5a test(sdk): Test that room subscription makes members not synced. 2023-06-16 11:23:11 +02:00
Ivan Enderlin
c515643442 doc(sdk): Fix typos. 2023-06-16 10:35:32 +02:00
Ivan Enderlin
d45f871106 doc(sdk): Fix intralink. 2023-06-16 10:34:48 +02:00
Ivan Enderlin
3a70b2e8ab fix(ui): SlidingSync::subscribe_to_room marks room as having missing members.
Fix https://github.com/matrix-org/matrix-rust-sdk/issues/2004.
2023-06-16 09:44:36 +02:00
Jonas Platte
db5c9d8c4b ffi: Add Room::get_timeline_event_content_by_event_id 2023-06-15 17:24:18 +02:00
Ivan Enderlin
ec1172c353 feat(ui+ffi): Implement RoomList::entries_loading_state
feat(ui+ffi): Implement `RoomList::entries_loading_state`
2023-06-15 17:20:42 +02:00
Ivan Enderlin
61d4850a66 chore: Make Clippy happy. 2023-06-15 16:18:08 +02:00
Ivan Enderlin
1f6a0b23f0 fix(ui): Set visible_rooms with a default range
fix(ui): Set `visible_rooms` with a default range
2023-06-15 16:08:17 +02:00
Ivan Enderlin
5673422831 test(ui): Use stream_assert to simplify the code. 2023-06-15 15:58:08 +02:00
Ivan Enderlin
d935f52c86 doc(sdk): Update documentation of SlidingSyncList::state_stream. 2023-06-15 15:53:06 +02:00
Ivan Enderlin
0ff9073a14 feat(ffi): Implement RoomList::entries_loading_state.
This patch implements `RoomList::entries_loading_state`.
2023-06-15 15:50:21 +02:00
Ivan Enderlin
a073c1422c test(ui): Test RoomList::entries_loading_state. 2023-06-15 15:45:30 +02:00
Ivan Enderlin
4e92738c28 feat(ui): Implement RoomList::entries_loading_state.
This patch implements `RoomList::entries_loading_state`, which
is a basic forwarding from the `all_rooms` sliding sync list'
`state_stream()` result.
2023-06-15 15:45:30 +02:00
Ivan Enderlin
db6798321c feat(sdk): SlidingSyncList::state_stream returns a tuple.
This patch updates `SlidingSyncList::state_stream` to return
a tuple `(SlidingSyncListLoadingState, impl Stream<Item =
SlidingSyncListLoadingState>)`.
2023-06-15 15:45:30 +02:00
Ivan Enderlin
f10f0d017d feat(sdk): Rename SlidingSyncState to SlidingSyncListLoadingState.
This patch renames `SlidingSyncState` to `SlidingSyncListLoadingState`
because:

1. It's about a list information,
2. It's about the loading state, not a generic state.
2023-06-15 15:45:28 +02:00
Ivan Enderlin
1c480398d2 fix(ui): Set visible_rooms with a default range.
The MSC3575 says that if no `ranges` for a list is provided, it defaults
to `0..=99`. We don't want that! This patch sets the default value to
`0..=19` for the `visible_rooms`.
2023-06-15 15:37:35 +02:00
Jonas Platte
52d2fa1a72 ffi: Clean up 2023-06-15 15:20:46 +02:00
Jonas Platte
12df1f38ed ffi: Remove remaining callback interfaces from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte
899c0d59e6 ffi: Remove sliding sync things from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte
867b3665d2 ffi: Remove re-exports from timeline module 2023-06-15 15:20:46 +02:00
Jonas Platte
daf59356cb ffi: Remove room list from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte
53ae4362f6 ffi: Remove unused public Rust API 2023-06-15 15:20:46 +02:00
Jonas Platte
b789b9e063 ffi: Remove room / timeline things from UDL 2023-06-15 15:20:46 +02:00
Jonas Platte
b1c8859eb9 Upgrade UniFFI 2023-06-15 15:20:46 +02:00
Jonas Platte
0e618bea5c ui: Don't use TryFutureExt where not necessary 2023-06-15 14:37:40 +02:00
Ivan Enderlin
31d834048f feat(fii): Implement RoomList::apply_input
feat(fii): Implement `RoomList::apply_input`
2023-06-15 13:22:09 +02:00
Benjamin Bouvier
1fd039c64f sliding sync: lazily generate and include the transaction id, only if it's useful (#2063)
* feat: lazily generate and include the transaction id, only if it's useful
* chore: add a small `LazyTransactionId` wrapper that ensures it's only created once

---------

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-15 10:30:24 +00:00
Kévin Commaille
16a63d352c base: Remove the session field from StateChanges
It is never set nor used.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-15 11:12:40 +02:00
Ivan Enderlin
59565657fa feat(ffi): Implement RoomList::apply_input.
This patch implements `RoomList::apply_input`. Usage example:

```rust
room_list.apply_input(RoomListInput::Viewport { ranges: vec![RoomListRange { start: 10, end_inclusive: 20 }]}).await?;
```
2023-06-15 11:12:17 +02:00
Ivan Enderlin
ea9a85395a chore(ui): Add missing trailing commas. 2023-06-15 11:11:48 +02:00
Jonas Platte
78135fcce9 ffi: Add message_event_content_new 2023-06-15 10:44:40 +02:00
Jonas Platte
7feba6f814 ffi: Use Duration instead of u64
Resolves FIXME comment.
2023-06-15 10:44:40 +02:00