Commit Graph

78 Commits

Author SHA1 Message Date
Skye Elliot
13b86a3f5d tests: Add test_room_encrypted_state_event_send 2025-08-22 14:27:05 +01:00
Kévin Commaille
1eb8f6ac16 Fix shared history test
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-08-12 17:25:22 +03:00
Jonas Platte
42d2b93489 refactor: Introduce TestResult and use it in a couple random places 2025-08-06 22:21:39 +00:00
Hubert Chathi
a4da6ba7c8 Exclude insecure devices on Olm encryption (#5457)
Fixes the encrypting part of
https://github.com/matrix-org/matrix-rust-sdk/issues/4147

Probably easiest to review commit-by-commit

<!-- description of the changes in this PR -->

- [x] Public API changes documented in changelogs (optional)

<!-- Sign-off, if not part of the commits -->
<!-- See CONTRIBUTING.md if you don't know what this is -->
Signed-off-by:
2025-08-04 08:50:32 +01:00
Benjamin Bouvier
b645c1101f refactor(test): avoid proliferation of builder submethods in the MockClientBuilder
Instead of having one static method duplicating an underlying
`ClientBuilder` method, we can pass the builder directly to a closure,
that will replace it. Call sites are a bit more verbose, but that would
avoid having to add duplicate `MockClientBuilder` methods for each
`ClientBuilder` method.
2025-07-30 11:56:31 +02:00
Kévin Commaille
4931c0749e Upgrade Ruma again
This patch updates our `Raw` API usage since the newly added `JsonCastable` that disallows Raw casts that are known to fail deserialization. 

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-07-22 12:59:26 +00:00
Damir Jelić
f14994baa9 test(sdk): Test if we accept historic room key bundles arriving out of order 2025-07-17 16:39:31 +02:00
Kévin Commaille
577a8feb12 refactor(sdk): Expose directly the URI of MatrixMockServer
Since there are several places that use it.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-07-07 09:42:47 +02:00
Jonas Platte
07808b4301 refactor: Enable extra code style clippy lints 2025-07-05 21:20:34 +02:00
Valere Fedronic
cd141c5b84 feat(widget): Receive custom to-device messages in widgets in e2ee rooms
Proper support for receiving to-device messages for widgets.

If the widget is in an e2ee room, clear to-device traffic will be excluded. Also filter out internal to-device messages that widgets should not be aware off.
2025-06-17 16:00:44 +02:00
Valere Fedronic
7126fc8a29 feat(crypto): Emmit EncryptionInfo with event handlers for to-device messages as well 2025-06-13 14:31:22 +02:00
Damir Jelić
0e9ce0271e refactor: Create a store/types submodule 2025-06-10 13:53:09 +02:00
Jonas Platte
65bb20c965 refactor: Clean up tracing and formatting macro uses (#5192)
Signed-off-by: Jonas Platte <jplatte+matrix@posteo.de>
2025-06-09 12:15:59 +02:00
Valere
f7265c39e0 cleanup: Reuse existing server.mock_sync instead of custom function 2025-06-05 14:29:50 +02:00
Valere
4468c36b14 review: extend existing MatrixMockServer instead of creating another 2025-06-05 14:29:50 +02:00
Valere
25841c787e refactor(test): Extract common crypto mock server helper 2025-06-05 14:29:50 +02:00
Jonas Platte
8eec683793 refactor: Use inline format arguments more
Automated with cargo clippy --fix --workspace --all-targets.
2025-05-29 13:19:59 +02:00
Valere Fedronic
21de891ea5 feat(sdk): Add the encrypt_and_send_raw_to_device method
This method allows users to encrypt and send custom to-device events to a set of devices of their choosing.
2025-05-19 11:20:25 +00:00
Kévin Commaille
c8da9cb462 refactor(oauth): Remove the issuer from OAuthAuthData
It is actually unused, and now that we only need homeserver URLs for
static registrations, users don't need to access it easily.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-04-03 12:52:17 +03:00
Damir Jelić
e2e5b39afa test(sdk): Test that resetting cross-signing with an invalid password errors out 2025-03-28 15:23:52 +01:00
Damir Jelić
6fec953ff0 test(sdk): Use the MatrixMockServer for the cross-signing reset test 2025-03-28 15:23:52 +01:00
Kévin Commaille
f6c5addf55 refactor(sdk): Remove experimental-oidc feature
Now that is compiles under WASM and that the API was cleaned up, it
should be okay.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-24 14:04:04 +02:00
Kévin Commaille
7ad1b113dc doc(oauth): Change mentions of OpenID Connect to OAuth 2.0
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-18 17:18:34 +01:00
Kévin Commaille
00d7a77ebe refactor(encryption): Rename OidcCrossSigningResetInfo to OAuthCrossSigningResetInfo
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-18 17:18:34 +01:00
Ivan Enderlin
d03ed3063c feat: Introduce EncryptionState.
This patch introduces the new `EncryptionState` to represent the 3
possible states: `Encrypted`, `NotEncrypted` or `Unknown`. All the
`is_encrypted` methods have been replaced by `encryption_state`.
The most noticable change is in `matrix_sdk::Room` where `async fn
is_encrypted(&self) -> Result<bool>` has been replaced by `fn fn
encryption_state(&self) -> EncryptionState`. However, a new `async
fn latest_encryption_state(&self) -> Result<EncryptionState>` method
“restores” the previous behaviour by calling `request_encryption_state`
if necessary.

The idea is that the caller is now responsible to call
`request_encryption_state` if desired, or use `latest_encryption_state`
to automate the call if necessary. `encryption_state` is now non-async
and infallible everywhere.

`matrix-sdk-ffi` has been updated but no methods have been added for
the moment.
2025-03-11 12:28:16 +01:00
Kévin Commaille
dd01479c6b refactor(sdk): Use a single SessionTokens type
Since MatrixSessionTokens and OidcSessionTokens are identical.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-03-10 09:12:38 +01:00
Kévin Commaille
54ab46dcb4 test(oidc): Use MatrixMockServer for cross-signing test
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-26 14:31:46 +01:00
Damir Jelić
bfa89bc73f feat(crypto): Add support for the shared_history flag defined in MSC3061
This patch adds support for the `shared_history` flag from MSC3061 to
the `m.room_key` content, exported room keys, and backed-up room keys.

The flag is now persisted in our `InboundGroupSession`. Additionally,
when creating a new `InboundGroupSession`, we ensure the
`shared_history`  flag is set appropriately.

MSC3061: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
2025-02-25 16:52:23 +01:00
Kévin Commaille
31e78c2a1b refactor(oidc): Only support public clients (#4634)
This should be the most common case, and is already the only case
supported by the higher level APIs like `url_for_oidc` and
`login_with_qr_code`. It simplifies the API because we can call
`restore_registered_client` directly from `register_client`, which was a
TODO.

- [x] Public API changes documented in changelogs (optional)

---------

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-13 11:40:17 +01:00
Damir Jelić
8042abe5f5 fix(recovery): Delete the known secrets from 4s when disabling recovery 2025-02-11 15:28:33 +01:00
Ivan Enderlin
78d9e1292f chore(sdk): Do not iterate over the entire iterator when we can reach back.
This patch uses `next_back()` instead of `last()`, which is equivalent
but `last()` requires to iterate over the entire iterator, while
`next_back()` is a single operation.
2025-01-31 14:07:43 +01:00
Kévin Commaille
3e78e441d4 refactor(sdk): Move oidc module to authentication::oidc
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-22 20:22:13 +01:00
Kévin Commaille
02c2e55855 refactor(sdk): Move matrix_auth module to authentication::matrix
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-01-22 20:22:13 +01:00
Ivan Enderlin
61dd560499 feat: Remove the experimental-sliding-sync feature flag.
Sliding sync is no longer experimental. It has a solid MSC4186, along
with a solid implementation inside Synapse. It's time to consider it
mature.

The SDK continues to support the old MSC3575 in addition to MSC4186.
This patch only removes the `experimental-sliding-sync` feature flag.
2025-01-08 21:30:41 +01:00
Kévin Commaille
5158b39277 refactor!: Upgrade Ruma to 0.11.0
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-10-30 09:42:19 +01:00
Benjamin Bouvier
7089ff51c4 refactor(room): take the transaction id by ownership in with_transaction_id
This allows letting the caller whether they need to clone it or not, and
avoids a spurious clone in one call site.
2024-10-17 16:54:50 +02:00
Richard van der Hoff
07cfe3da94 timeline: make TimelineEvent fields private
... and add accessors instead.

Give `TimelineEvent` the same treatment we just gave `SyncTimelineEvent`: make
the fields private, and use accessors where we previously used direct access.
2024-10-09 15:19:26 +01:00
Benjamin Bouvier
19e89bbd6a tests: make test_incremental_upload_of_keys_sliding_sync less dependent on timing 2024-09-09 14:21:51 +02:00
Benjamin Bouvier
a07be884b7 tests: try to address intermittent failure of test_incremental_upload_of_keys
My theory is that the intermittent failure depends on the ordering of
the requests, and if the /keys/upload request happened before the key
backup request, then after failing the next key backup request wouldn't
run.

This is likely a small typo that the key upload returns a 404 error
instead of a 200, let's see if this improves the situation.
2024-09-09 14:21:51 +02:00
Stefan Ceriu
5b14fe6f34 crypto: fix OIDC cross-signing reset flows after backend authorization failure response change (#3933) 2024-09-03 14:43:46 +00:00
Benjamin Bouvier
b8d90286aa testing: enforce a test_ prefix for tests
This will only apply to `async_test` functions, but I think this is a
win:

1. for consistency within the codebase, since I've started doing so in
many places,
2. because these function names will clearly identify these functions as
tests, in the call tree interfaces, when rendered using the LSP
show-callers/show-callees functionality.
2024-09-02 12:02:43 +02:00
Ivan Enderlin
de8537f8b0 feat: Use sliding_sync::Version everywhere.
This patch replaces all the API using simplified sliding sync, or
sliding sync proxy, by a unified `sliding_sync::Version` type!

This patch disables auto-discovery for the moment. It will be re-enable
with the next patches.
2024-08-27 17:25:12 +02:00
Benjamin Bouvier
a0c8b71236 refactor(sdk): merge Room::event and Room::event_with_config
It's better to have fewer public APIs, especially when there's little
annoyance to have it. We could use a request builder that converts into
a Future, too, but considering there's only a single optional parameter,
it's fine to include it in the function's signature.
2024-08-12 11:51:54 +02:00
Stefan Ceriu
1160383d71 sdk: fix identity reset not actually disabling backups when not enabled locally, resulting in conflicts and failing to correctly setup the newly reset session 2024-08-02 15:25:42 +03:00
Stefan Ceriu
d7f3914673 sdk: throw an error instead of silently failing when disabling backups if they weren't previously enabled locally
- also change back the state from `disabling` to `unknown`
2024-08-02 15:25:42 +03:00
Stefan Ceriu
db064626fa sdk: Add high level method for resetting the user's identity and deleting all associated secrets 2024-07-29 16:52:03 +03:00
Damir Jelić
f0ef37efae tests: Add tests for the cross-signing reset 2024-07-24 11:03:54 +02:00
Damir Jelić
0d00bda0c6 encryption: Add a method to reset cross-signing keys 2024-07-24 11:03:54 +02:00
Ivan Enderlin
ea2a27075a feat(ffi,base,ui,sdk): Migrate from sliding sync to simplified sliding sync.
This patch migrates the entire SDK to sliding sync to simplified sliding
sync.
2024-07-17 16:33:37 +02:00
Damir Jelić
a34e19617a recovery: Ensure that we don't miss updates to the backup state
This patch switches the way we update the recovery state upon changes in
the backup state. Previously two places updated the recovery state after
the backup state changed:

    1. A method living in the recovery subsystem that the backup
       subsystem itself calls.
    2. An event handler which is called when we receive a m.secret.send
       event.

The first method is a hack because it introduces a circular dependency
between the recovery and backup subsystems.

More importantly, the second method can miss updates, because the backup
subsystem has a similar event handler which then processes the secret we
received and if the secret was a backup recovery key, enables backups.

Depending on the order these event handlers are called, the recovery
subsystem might update the recovery state before the secret has been
handled.

The backup subsystem provides an async stream which broadcasts updates
to the backup state, letting the recovery subsystem listen to this
stream and update its state if we notice such updates fixes both
problems we listed above. The method in the first bullet point was
completely removed, the event handler is kept for other secret types but
we don't rely on it for the backup state anymore.
2024-07-01 14:38:26 +02:00