* Don't run migration for Rust crypto if the legacy store is empty
Fixes https://github.com/element-hq/element-web/issues/27447
* Add copyright for the TypeScript files in legacy DB dumps
* Provide a type for the accountPickle we check for before migration
* Remove redundant backup response
This is unused
* Simplify keys response
* Downgrade log message.
---------
Co-authored-by: Richard van der Hoff <richard@matrix.org>
* `initRustCrypto`: allow app to pass in the store key directly
... instead of using the pickleKey. This allows us to avoid a slow PBKDF
operation.
* Fix link in doc-comment
* Fix fields of MSC 3266 summary object
Also remove redundant room_type field which is inherited from elsewhere
* Export the MSC 3266 summary type
* Use proper endpoint for MSC 3266 summary lookup
Use the endpoint recommended by the MSC
* Rename newly-exported symbol to not start with I
* Use "export type"
* Lint
* Fix type of "encryption" field
* Add TSDoc documentation
* Add basic integration test for getRoomSummary
* Lint
* Use fallback endpoint for MSC3266
* Improve test coverage
* Lint
* Refactor async catch to satisfy linter
* Increase test coverage
* Add `PerSessionKeyBackupDownloader.isKeyBackupDownloadConfigured()`
* Add new `RustBackupManager.getServerBackupInfo`
... and a convenience method in PerSessionKeyBackupDownloader to access it.
* Crypto.spec: move `useRealTimers` to global `afterEach`
... so that we don't need to remember to do it everywhere.
* Use fake timers for UTD error code tests
This doesn't have any effect on the tests, but *does* stop jest from hanging
when you run the tests in in-band mode. It shouldn't *really* be needed, but
using fake timers gives more reproducible tests, and I don't have the
time/patience to debug why it is needed.
* Use new error codes for UTDs from historical events
* Migrate own identity trust to rust crypto
* Fix gendoc not happy if msk of IDownloadKeyResult has a signature
* add missing mock
* code review
* Code review
* Review gh suggestion
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Review gh suggestion
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Review gh suggestion
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Review gh suggestion
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* review move function down in file
* Review gh suggestion
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Review gh suggestion
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Review: Cleaning tests, renaming
* Review: better comment
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Comment paragraphs
* retry until initial key query is successfull
* Validate backup private key before migrating it
* post merge fix
* Fix test, missing mock
* Use crypto wasm instead of lib olm to check backup key
* typo
* code review
* quick lint
---------
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* initial implementation of device dehydration
* add dehydrated flag for devices
* add missing dehydration.ts file, add test, add function to schedule dehydration
* add more dehydration utility functions
* stop scheduled dehydration when crypto stops
* bump matrix-crypto-sdk-wasm version, and fix tests
* adding dehydratedDevices member to mock OlmDevice isn't necessary any more
* fix yarn lock file
* more tests
* fix test
* more tests
* fix typo
* fix logic for checking if dehydration supported
* make changes from review
* add missing file
* move setup into another function
* apply changes from review
* implement simpler API
* fix type and move the code to the right spot
* apply suggestions from review
* make sure that cross-signing and secret storage are set up
* Clean up decryption failure integ tests
* Fix the names
* Stop waiting as soon as the event is decrypted, even if code is wrong (so
tests fail rather than time out if the code is wrong)
* Bump timeouts on some tests
These tend to fail due to slow init of wasm artifacts
* Factor out `onDecryptionKeyMissingError` call
* Factor out `onMegolmDecryptionError`
* Fix highlights from threads disappearing on new messages
This changes interface of Room, so this is a BREAKING CHANGE.
Correctly mirrors the logic we use for room notifications for thread
notifications, ie. set only the total notifications count from the
server if it's zero.
I'm not delighted with this since it ends up with function on room
whose contract is to do something frankly, deeply weird and
unintuitive. However, this is the hack we use for room notifications
and it, empirically, works well enough. To do better, we'd need much
more complex logic to overlay notification counts for decrypted messages.
Fixes https://github.com/element-hq/element-web/issues/25523
* Add tests for the special notification behaviour in syncing
* Correctly copy the room logic for reseting notifications
We were always ignoring the highlight count, even for encrypted rooms,
which was broken because we don't do the local calculation for unencrypted
rooms.
* Move code for processing our own receipts to Room
This is some code to process our own receipts and recalculate our
notification counts.
There was no reason for this to be in client. Room is still rather
large, but at least it makes somewhat more sense there.
Moving as a refactor before I start work on it.
* Add test for the client-side e2e notifications code
* Extend logic for local notification processing to threads
There's collection of logic for for processing receipts and recomputing
notifications for encrypted rooms, but we didn't do the same for threads.
As a reasult, when I tried pulling some of the logic over in
https://github.com/matrix-org/matrix-js-sdk/pull/4106
clearing notifications on threads just broke.
This extends the logic of reprocessing local notifications when a receipt
arrives to threads.
Based on https://github.com/matrix-org/matrix-js-sdk/pull/4109
* simplify object literal
* Add tests & null guard
* Remove unused imports
* Add another skipped test
* Unused import
* enable tests
* Fix thread support nightmare
* Try this way
* Unused import
* Comment the bear trap
* expand comment
* Move code for processing our own receipts to Room
This is some code to process our own receipts and recalculate our
notification counts.
There was no reason for this to be in client. Room is still rather
large, but at least it makes somewhat more sense there.
Moving as a refactor before I start work on it.
* Add test for the client-side e2e notifications code
* simplify object literal
* Introduce Membership TS type
* Adapt the Membership TS type to be an enum
* Add docstrings for KnownMembership and Membership
* Move Membership types into a separate file, exported from types.ts
---------
Co-authored-by: Stanislav Demydiuk <s.demydiuk@gmail.com>
The root event of a thread used to arrive with the pagination request, but this was unspecced and so got changed to simply fetch the root event. In many (almost all) cases this shouldn't be necessary because the thread should already have its root event: re-use it if it's already there. This is only in pagination, so there's no reason to believe that the root event would have changed and needs to be re-fetched.
This removes a number of duplicate calls to the /event/ endpoint from the tests.
* crypto.spec: make `keyResponder` a local var
it is never used between functions, so making it external was confusing
* Persist encryption state to the rust room list.
* `MatrixClient.shouldEncryptEventForRoom`: fix for rust crypto
Previously, we were not bothering to ask the Rust Crypto stack if it thought we
should be encrypting for a given room. This adds a new method to `CryptoApi`,
wires it up for legacy and Rust crypto, and calls it.
* Tests for persistent room list
* Decrypt and Import full backups in chunk with progress
* backup chunk decryption jsdoc
* Review: fix capitalization
* review: better var name
* review: fix better iterate on object
* review: extract utility function
* review: Improve test, ensure mock calls
* review: Add more test for decryption or import failures
* Review: fix typo
Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
---------
Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
* Fix new threads not appearing.
We try to update the thread roots when creating a thread, but a thread
can take some time to be ready after being created so we were calling it
too soon. Add a listener for the Update event to update the thread roots
once it's ready.
Fixes https://github.com/element-hq/element-web/issues/26799
* Don't recreate the event when we update
and also add a comment to the test
* Hopefully make sonarcloud happy
* Fix `CryptoStore.countEndToEndSessions`
This was apparently never tested, and was implemented incorrectly.
* Add `CryptoStore.countEndToEndInboundGroupSessions`
* Emit events to indicate migration progress
* Use a `StoreHandle` to init OlmMachine
This will be faster if we need to prepare the store.
* Include "needsBackup" flag in inbound group session batches
* On startup, import data from libolm cryptostore
* ISessionExtended -> SessionExtended
* `getOwnDeviceKeys`: use `olmMachine.identityKeys`
This is simpler, and doesn't rely on us having done a device query to work.
* Factor out `requestKeyBackupVersion` utility
* Factor out `makeMatrixHttpApi` function
* Convert `initRustCrypto` to take a params object
* Improve logging in startup
... to help figure out what is taking so long.
* Remove m.thread filter from relations API call
We used MSC3981 to pass the recurse param to the /relations
endpoint so that we could get relations to events in a thread, but
we kept the rel_type filter on (as m.thread) so no second-order relations
would ever have been returned (a nested thread isn't a thing).
This removes the filter and does some filtering on the client side to
remove any events that shouldn't live in the threaded timeline (ie.
non-thread relations to the thread root event).
This should help fix stuck unreads because it will avoid the event that
the receipt refers to going missing (but only on HSes that support MSC3981).
For https://github.com/vector-im/element-web/issues/26718
* Fix import cycle
* Remove params from expected calls in tests to match
* Unused import
* initial commit
* new interation test
* more comments
* fix test, quick refactor on request version
* cleaning and logs
* fix type
* cleaning
* remove delegate stuff
* remove events and use timer mocks
* fix import
* ts ignore in tests
* Quick cleaning
* code review
* Use Errors instead of Results
* cleaning
* review
* remove forceCheck as not useful
* bad naming
* inline pauseLoop
* mark as paused in finally
* code review
* post merge fix
* rename KeyDownloadRateLimit
* use same config in loop and pass along
* Test whether an event not in a room's timeline causes notification count increase
Commited separately to demonstrate test failing before.
* Don't fix up notification counts if event isn't in the room
As explained by the comment, hopefully.
* Fix other test
* Rust-crypto: fix `bootstrapCrossSigning` on second call
Currently, `bootstrapCrossSigning` raises an exception if it is called a second
time before secret storage is set up. It is easily fixed by checking that 4S is
set up before trying to export to 4S.
Also a few logging fixes while we're in the area.
* Factor out an `AccountDataAccumulator`
* Another test for bootstrapCrossSigning
MatrixClient API was exposing two methods that only worked for legacy crypto:
- getDeviceEd25519Key
- getDeviceCurve25519Key
=> These are used in the react-sdk for some functionality (rageshake, sentry, rendez-vous).
I have deprecated those calls from MatrixClient and created a new API in CryptoApi (where it belongs):
getOwnDeviceKeys(): Promise<OwnDeviceKeys>
* fix members loaded on intitial sync
* Update test to use KeyResponder
* Use E2EKeyResponder
* code review
* better comment
* fix test
* post merge fix
* fix imports
* refactoring, better names
* code review
* clean tests
* Cleanups per review comments
* fix test
* Apply suggestions from code review
---------
Co-authored-by: Richard van der Hoff <richard@matrix.org>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Support for stable MSC3882 get_login_token
* Make changes non-breaking by deprecation
* Remove deprecated exports from MSC3882 stabilisation
* Feat remove support for unstable MSC3882
* Remove bad line from rebase
* Fix issue
* Fix jest test
* Fix even more jest failures
* Fix formatting
* Add a test
* Write test for older code
* Fix lint
* Rename method
* Make ctor deprecated
* Element-R: reduce log spam when checking server key backup
Fixes a lot of spam in the logs about "uncaught in promise: No room_keys
found".
* Improve integ tests for backup query after UTD
* Yield in the backup decryption loop
* Fix another broken test
* Wire up history visibility in `RoomEncryptor.ts`
* Add more tests to history visibility conversion
* Factorize `expectSendMessage` and `expectSendMegolmMessage`
* Use correct import
* Fix overwriteRoutes
* Update comments
* Element-R: silence log errors when viewing a pending event
Fixes the second half of vector-im/element-web#26272
* Update spec/integ/crypto/crypto.spec.ts
* Handle backup secret gossip
* use getSecretsFromInbox
* add gossip test
* use delete secret API
* fix logger
* better comment and cleaning
* free the pkSigning
* fix typo
* add missing mocks
* improve coverage
* better var name
* quick refactoring
* add more tests
* Review, format and comments
* refactor move more logic to backup.ts
* poll secret inbox
* missing mock
* Update src/rust-crypto/rust-crypto.ts
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Update src/rust-crypto/rust-crypto.ts
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Update src/rust-crypto/rust-crypto.ts
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Update src/rust-crypto/backup.ts
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Update src/rust-crypto/rust-crypto.ts
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* code review
* fix comment
* remove comment
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* quick factorise
---------
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* very messy poc
* iterate
* more types and use tokenRefreshFunction
* working refresh without persistence
* tidy
* add claims to completeauhtorizationcodegrant response
* export tokenrefresher from matrix
* add idtokenclaims
* add claims to completeauhtorizationcodegrant response
* only one token refresh attempt at a time
* tests
* comments
* add tokenRefresher class
* export generateScope
* export oidc from matrix
* test refreshtoken
* mark experimental
* add getRefreshToken to client
* Apply suggestions from code review
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* remove some vars in test
* make TokenRefresher un-abstract, comments and improvements
* remove invalid jsdoc
* Update src/oidc/tokenRefresher.ts
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Code review improvements
* fix verification integ tests
* remove unused type from props
* fix incomplete mock fn in fetch.spec
* document TokenRefreshFunction
* comments
* tidying
* update for injected logger
---------
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>