Commit Graph

7669 Commits

Author SHA1 Message Date
Damir Jelić 645bbd67df Remove a unused error type 2023-11-06 14:19:12 +01:00
Damir Jelić 26ede608b0 Add a method which checks if a backup decryption key matches a backup info 2023-11-06 14:19:12 +01:00
Damir Jelić 554aa0404a Add a higher level method to decrypt backed up room keys 2023-11-06 14:19:12 +01:00
Damir Jelić 3438e7de9b Add a higher level method to sign backup versions (#2819) 2023-11-06 12:50:51 +00:00
Damir Jelić 44bb9a3d8f Add a method to create an ExportedRoomKey from a BackedUpRoomKey 2023-11-06 13:41:57 +01:00
Damir Jelić bc5b190509 Add a method to get the RoomKeyBackupInfo to the BackupDecryptionKey 2023-11-06 12:41:22 +01:00
Damir Jelić 2e20f00d99 Add an example for the secret storage support 2023-11-06 10:41:44 +01:00
Damir Jelić 760053b15d Add a test for the secret storage support in the main crate 2023-11-06 10:41:44 +01:00
Damir Jelić e599fa1ccf Add secret storage support to the main SDK crate 2023-11-06 10:41:44 +01:00
Jonas Platte c7fbfd4db8 ffi: Add MediaFileHandle::persist 2023-11-06 10:32:11 +01:00
Jonas Platte ad392a1977 sdk: Add MediaFileHandle::persist 2023-11-06 10:32:11 +01:00
Jonas Platte 57136247bf ffi: Add use_cache parameter to get_media_file 2023-11-06 10:32:11 +01:00
Damir Jelić e5b06bd6d8 Enable backups in the crypto crate by default 2023-11-03 19:17:10 +01:00
Damir Jelić beb01eacfa fixup! Use the better Signatures type in the MegolmV1BackupKey type 2023-11-03 17:01:47 +01:00
Damir Jelić 1e9fab1e4e Use the better Signatures type in the MegolmV1BackupKey type 2023-11-03 17:01:47 +01:00
Benjamin Bouvier 1be7fab4fd ffi: have the (ffi) NotificationClient keep the (ffi) Client alive
Otherwise, it's possible for the `NotificationClient` to be destroyed *after* the ffi `Client`, and then the hack introduced in the previous commit won't work.
2023-11-03 16:54:54 +01:00
Benjamin Bouvier ad5761bfb5 fix(ffi): don't leak Client instances
A detached task was spawned to react upon session changes, and that task captured a clone of the current `Client`.
This caused a leak of the `Client`, because that task would never get aborted, and would not stop by itself.
The fix here consists in having `Client::set_delegate` return a task handle that needs to be stashed by the FFI
users, and cancelled when the Client gets out of scope. This fixes the leak, by removing the last reference onto
the Client.

Then, when dropping the Client, we have to drop the Stores in it. These stores may be sqlite-based stores, which
make use of deadpool. Deadpool has a sync wrapper that will call `block_on` in a `drop` method, and as such it
requires to be in the scope of a tokio runtime to run properly. To avoid breaking all abstractions and giving
access to the inners of the `Client`, the hack used here to properly be in a runtime when dropping the stores is
to replace the inner sdk `Client` in the FFI `Client::drop` method (and replace it with a dummy client that is
minimally configured and will use in-memory stores).
2023-11-03 16:54:54 +01:00
Damir Jelić efb72063ac Add a backup specific method to import room keys 2023-11-03 15:34:11 +01:00
Jonas Platte 9ef6103912 Insert strategic Box::pin to reduce async stack size 2023-11-03 12:23:59 +01:00
Jonas Platte 71c6b98d6a crypto: Box inner field of Account
This reduces its stack size to less than a third of what it previously
was and thus helps with async fn stack size problems.
2023-11-03 12:23:59 +01:00
Jonas Platte dc86835ae2 base: Box large RoomInfo fields
RoomInfo is often passed around by value, including in futures where
holding types with a large stack size is especially problematic¹.
It might make sense to move the actual data of (Base)RoomInfo into
an inner struct that is always held inside a Box or Arc, but this change
should have most of the benefits of that while being a bit simpler.

¹ https://github.com/rust-lang/rust/issues/69826
2023-11-03 12:23:59 +01:00
Benjamin Bouvier ab4c524212 crypto(perf): don't hold the cache lock while waiting on a user key query (#2806)
* crypto(fix): don't hold the cache lock while waiting on a user key query

Fixes #2802. The lock was only useful to sync the database and the in-memory cache for the users awaiting a key query request.
So it's possible to slightly tweak the API by moving the method from `SyncedKeyQueryManager` to non-synced `KeyQueryManager`, and require a
`StoreCacheGuard` (i.e. the owned lock, so we can manually drop it when we feel like so).

I've looked at all the other methods, and they do require the cache for writing into it and the store.
At the limit we could also move `SyncedKeyQueryManager::users_for_key_query`
into `KeyQueryManager`, but the lock in there is hold for a very short-time, so it shouldn't be an issue.

* Add test for the key query deadlock while waiting for the response.

* Update crates/matrix-sdk-crypto/src/machine.rs

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2023-11-03 11:36:54 +01:00
Richard van der Hoff c2f422209f Review comment: process failed devices together 2023-11-03 10:43:26 +01:00
Richard van der Hoff d90c623375 Add a test for devices with no key map 2023-11-03 10:43:26 +01:00
Richard van der Hoff abd6779210 Inline OlmMachine::receive_keys_claim_response
it's a bit pointless.
2023-11-03 10:43:26 +01:00
Richard van der Hoff d48c27dc86 Remove redundant key_id arg on create_session test helper 2023-11-03 10:43:26 +01:00
Richard van der Hoff 303417eae2 Factor out SessionManager::create_sessions
... and use it in some tests.

Simplify some of the test code by not building a whole keys/claim response.
2023-11-03 10:43:26 +01:00
Richard van der Hoff 017d72e80f Hoist check for missing OTKs to SessionManager
`Account::create_outbound_session` no longer takes an entire list of keys;
rather it takes a single key and it is up to the caller to pick a key out of
the list.

This in turn means that `SessionCreationError` loses one of its reason codes.
2023-11-03 10:43:26 +01:00
Timo d7f6231acd Add perParticipantE2EE to element call url. (#2807)
* Add `perParticipantE2EE` to element call url
* add ffi
* nightly fmt
* refactor to use enum + test
* rename to PerParticipantKeys
* cleanup (spelling + formatting)

Signed-off-by: Timo K <toger5@hotmail.de>
2023-11-03 10:42:50 +01:00
Marco Romano 6a27fc2e04 Upgrade uniffi
This will include https://github.com/mozilla/uniffi-rs/pull/1781
Which fixes https://github.com/mozilla/uniffi-rs/issues/1760
2023-11-03 10:19:20 +01:00
Jonas Platte 3481cde1dc Fix unquoted strings in tracing fields 2023-11-02 17:46:38 +01:00
Jonas Platte d821d611ba sdk: Clean up logging in sliding_sync
- Don't include pos in event data, it's available in a parent span
- Remove superfluous backtick
- Rewrap an `info!` invocation
2023-11-02 17:46:38 +01:00
Jonas Platte 4485abbfdf Replace all two uses of async-std with equivalent tokio functionality 2023-11-02 17:21:48 +01:00
Jonas Platte 2d19c7ad65 crypto: Use Option::map in UsersForKeyQuery::maybe_register_waiting_task 2023-11-02 17:21:48 +01:00
Jonas Platte 1692460b30 Simplify dependency specifications for tokio
matrix-sdk-common and matrix-sdk-crypto were repeating things that would
be inherited from the workspace dependency specification anyways.
2023-11-02 17:21:48 +01:00
Benjamin Bouvier 250d63c6da fix: change the event_type after encrypting
The event_type passed to `encrypt_room_event_raw` must be the one of the cleartext event, not `m.room.encrypted`. The returned event has the expected type.
2023-11-02 16:56:50 +01:00
Jonas Platte 0a33642851 widget: Change content to RawValue representation 2023-11-02 16:56:50 +01:00
Jonas Platte 64c9fa5542 sdk: Allow different raw JSON types for send_raw, send_state_event_raw 2023-11-02 16:56:50 +01:00
Jonas Platte d042bcce04 crypto: Optimize OutboundGroupSession::encrypt 2023-11-02 16:56:50 +01:00
Jonas Platte 7d52322687 crypto: Update raw encryption methods to take &Raw content 2023-11-02 16:56:50 +01:00
Jonas Platte b797635255 crypto: Restrict visibility of internal types
This makes it more obvious that breaking changes to these types don't
break the public API.
2023-11-02 16:56:50 +01:00
Jonas Platte d9845c1658 crypto: Put event type before content for raw encryption methods 2023-11-02 16:56:50 +01:00
Daniel Abramov 4428b525ea widget: Implement limits for requests 2023-11-02 14:56:51 +00:00
Jonas Platte b67ca2c123 ci: Increase log level for coverage job 2023-11-02 12:58:03 +01:00
Jonas Platte 7be84ca71a test: Deduplicate tracing_subscriber initialization
… and set a sensible default log level.
2023-11-02 12:58:03 +01:00
Jonas Platte 9956b56a2c test: Remove unused helpers feature from integration testing crate 2023-11-02 12:58:03 +01:00
Jonas Platte afcc7022a2 Exclude remaining Debug impls from coverage reporting 2023-11-02 12:58:03 +01:00
Benjamin Bouvier 8de33f68f3 integration tests: randomize user names better
In the previous situation, running the tests with `cargo test` would sometimes fail because despite appending the number of milliseconds since
the start of epoch to the user names, some user names would clash across different tests, leading to unexpected results. This fixes it by using
an actual RNG in there, so the names don't ever clash.
2023-11-01 07:57:46 +01:00
Damir Jelić 2efb09907b Add a minimal integration test that sends a message in an encrypted room (#2799) 2023-10-31 19:45:18 +01:00
Jonas Platte 91e7f2f722 sdk: Add changes to send-event API to changelog 2023-10-31 12:46:10 +01:00