* Remove deprecated calls in `webrtc/call.ts`
* Throw error when legacy call was used
* Remove `MatrixClient.initLegacyCrypto` (#4620)
* Remove `MatrixClient.initLegacyCrypto`
* Remove `MatrixClient.initLegacyCrypto` in README.md
* Remove tests using `MatrixClient.initLegacyCrypto`
* Remove legacy crypto support in `sync` api (#4622)
* Remove deprecated `DeviceInfo` in `webrtc/call.ts` (#4654)
* chore(legacy call): Remove `DeviceInfo` usage
* refactor(legacy call): throw `GroupCallUnknownDeviceError` at the end of `initOpponentCrypto`
* Remove deprecated methods and attributes of `MatrixClient` (#4659)
* feat(legacy crypto)!: remove deprecated methods of `MatrixClient`
* test(legacy crypto): update existing tests to not use legacy crypto
- `Embedded.spec.ts`: casting since `encryptAndSendToDevices` is removed from `MatrixClient`.
- `room.spec.ts`: remove deprecated usage of `MatrixClient.crypto`
- `matrix-client.spec.ts` & `matrix-client-methods.spec.ts`: remove calls of deprecated methods of `MatrixClient`
* test(legacy crypto): remove test files using `MatrixClient` deprecated methods
* test(legacy crypto): update existing integ tests to run successfully
* feat(legacy crypto!): remove `ICreateClientOpts.deviceToImport`.
`ICreateClientOpts.deviceToImport` was used in the legacy cryto. The rust crypto doesn't support to import devices in this way.
* feat(legacy crypto!): remove `{get,set}GlobalErrorOnUnknownDevices`
`globalErrorOnUnknownDevices` is not used in the rust-crypto. The API is marked as unstable, we can remove it.
* Remove usage of legacy crypto in `event.ts` (#4666)
* feat(legacy crypto!): remove legacy crypto usage in `event.ts`
* test(legacy crypto): update event.spec.ts to not use legacy crypto types
* Remove legacy crypto export in `matrix.ts` (#4667)
* feat(legacy crypto!): remove legacy crypto export in `matrix.ts`
* test(legacy crypto): update `megolm-backup.spec.ts` to import directly `CryptoApi`
* Remove usage of legacy crypto in integ tests (#4669)
* Clean up legacy stores (#4663)
* feat(legacy crypto!): keep legacy methods used in lib olm migration
The rust cryto needs these legacy stores in order to do the migration from the legacy crypto to the rust crypto. We keep the following methods of the stores:
- Used in `libolm_migration.ts`.
- Needed in the legacy store tests.
- Needed in the rust crypto test migration.
* feat(legacy crypto): extract legacy crypto types in legacy stores
In order to be able to delete the legacy crypto, these stores shouldn't rely on the legacy crypto. We need to extract the used types.
* feat(crypto store): remove `CryptoStore` functions used only by tests
* test(crypto store): use legacy `MemoryStore` type
* Remove deprecated methods of `CryptoBackend` (#4671)
* feat(CryptoBackend)!: remove deprecated methods
* feat(rust-crypto)!: remove deprecated methods of `CryptoBackend`
* test(rust-crypto): remove tests of deprecated methods of `CryptoBackend`
* Remove usage of legacy crypto in `embedded.ts` (#4668)
The interface of `encryptAndSendToDevices` changes because `DeviceInfo` is from the legacy crypto. In fact `encryptAndSendToDevices` only need pairs of userId and deviceId.
* Remove legacy crypto files (#4672)
* fix(legacy store): fix legacy store typing
In https://github.com/matrix-org/matrix-js-sdk/pull/4663, the storeXXX methods were removed of the CryptoStore interface but they are used internally by IndexedDBCryptoStore.
* feat(legacy crypto)!: remove content of `crypto/*` except legacy stores
* test(legacy crypto): remove `spec/unit/crypto/*` except legacy store tests
* refactor: remove unused types
* doc: fix broken link
* doc: remove link tag when typedoc is unable to find the CryptoApi
* Clean up integ test after legacy crypto removal (#4682)
* test(crypto): remove `newBackendOnly` test closure
* test(crypto): fix duplicate test name
* test(crypto): remove `oldBackendOnly` test closure
* test(crypto): remove `rust-sdk` comparison
* test(crypto): remove iteration on `CRYPTO_BACKEND`
* test(crypto): remove old legacy comments and tests
* test(crypto): fix documentations and removed unused expect
* Restore broken link to `CryptoApi` (#4692)
* chore: fix linting and formatting due to merge
* Remove unused crypto type and missing doc (#4696)
* chore(crypto): remove unused types
* doc(crypto): add missing link
* test(call): add test when crypto is enabled
* Update src with globalThis
* Update spec with globalThis
* Replace in more spec/ places
* More changes to src/
* Add a linter rule for global
* Prettify
* lint
* Move `SecretEncryptedPayload` in `src/utils/@types`
* Move `encryptAES` to a dedicated file. Moved in a utils folder.
* Move `deriveKeys` to a dedicated file in order to share it
* Move `decryptAES` to a dedicated file. Moved in a utils folder.
* Move `calculateKeyCheck` to a dedicated file. Moved in a utils folder.
* Remove AES functions in `aes.ts` and export new ones for backward compatibility
* Update import to use new functions
* Add `src/utils` entrypoint in `README.md`
* - Rename `SecretEncryptedPayload` to `AESEncryptedSecretStoragePayload`.
- Move into `src/@types`
* Move `calculateKeyCheck` into `secret-storage.ts`.
* Move `deriveKeys` into `src/utils/internal` folder.
* - Rename `encryptAES` on `encryptAESSecretStorageItem`
- Change named export by default export
* - Rename `decryptAES` on `decryptAESSecretStorageItem`
- Change named export by default export
* Update documentation
* Update `decryptAESSecretStorageItem` doc
* Add lnk to spec for `calculateKeyCheck`
* Fix downstream tests
* 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>
* Add utility to check for non migrated legacy db
* code review changes
* add unit tests for existsAndIsNotMigrated
* ensure indexeddb is clean for each state
* 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
We had two identical sets of base64 functions in the js-sdk, both
using Buffer which isn't really available in the browser unless you're
using an old webpack (ie. what element-web uses). This PR:
* Takes the crypto base64 file and moves it out of crypto (because
we use base64 for much more than just crypto)
* Makes them work in a browser without the Buffer global
* Removes the other base64 functions
* Changes everything to use the new common ones
* Adds a comment explaining why the function is kinda ugly and how
soul destroyingly awful the JS ecosystem is.
* Runs the tests with both impls
* Changes the test to not just test the decoder against the encoder
* Adds explicit support & tests for (decoding) base64Url (I'll add an
encode method later, no need for that to go in this PR too).
* Refactor key backup recovery to prepare for rust
* rust backup restore support
* Move export out of old crypto to api with re-export
* extract base64 utility
* add tests for base64 util
* more efficient regex
* fix typo
* Define `UIAuthCallback` type and use in `IBootstrapCrossSigningOpts`
* Move `IBootstrapCrossSigningOpts` to `crypto-api` and rename
* Replace uses of `IBootstrapCrossSigningOpts`
... with `BootstrapCrossSigningOpts`
* Update src/crypto-api.ts
* Add `getUserDeviceInfo` to `CryptoBackend` and old crypto impl
* Add `getUserDeviceInfo` WIP impl to `rust-crypto`
* Add tests for `downloadUncached`
* WIP test
* Fix typo and use `downloadDeviceToJsDevice`
* Add `getUserDeviceInfo` to `client.ts`
* Use new `Device` class instead of `IDevice`
* Add tests for `device-convertor`
* Add method description for `isInRustUserIds` in `rust-crypto.ts`
* Misc
* Fix typo
* Fix `rustDeviceToJsDevice`
* Fix comments and new one
* Review of `device.ts`
* Remove `getUserDeviceInfo` from `client.ts`
* Review of `getUserDeviceInfo` in `rust-crypto.ts`
* Fix typo in `index.ts`
* Review `device-converter.ts`
* Add documentation to `getUserDeviceInfo` in `crypto-api.ts`
* Last changes in comments
* Element-R: implement `{get,set}TrustCrossSignedDevices`
A precursor to https://github.com/vector-im/element-web/issues/25092
* Pull out new `DeviceVerificationStatus`
Define a new base class to replace `DeviceTrustLevel`. The intention is to have
a cleaner interface which is easier to expose from the new crypto impl
* Define, and implement, a new `CryptoApi.getDeviceVerificationStatus`
This is similar to `checkDeviceTrust`, which we're deprecating, but:
* is `async`, meaning we can implement it in Rust
* Returns a `DeviceVerificationStatus` instead of a `DeviceTrustLevel`
* Returns `null` rather than "not verified" if the device is unknown
* add some tests
* Export DeviceVerificationStatus as a proper class
... so that we can instantiate it in tests
* Pull `SecretStorageCallbacks` out of `ICryptoCallbacks`
* Pull the storage part of SecretStorage out to a new class
* Move SecretSharing to a separate class
* Move `ISecretRequest` into `SecretSharing.ts`
* Pull out ISecretStorage interface, and use it
* Mark old `SecretStorage` as deprecated, and rename accesses to it
* Move a `SecretStorage` unit test into its own file
* Use new `SecretStorage` in a couple of places
* add some more unit tests
* Fix test file name
... to match the unit under test
* even more tests
* Add a load of comments
* Rename classes
* Fix some broken tsdoc links
* fix broken test
* Fix compaints about superlinear regex
* just one more test
* Remove redundant `IAccountDataClient.getAccountData`
This is never called, so we may as well get rid of it
* Move a few more interfaces into `secret-storage.ts`
* Use interfaces from `secret-storage`
* Move IAccountDataClient to secret-storage
* Use `AccountDataClient` from `secret-storage`
* move SECRET_STORAGE_ALGORITHM_V1_AES to secret-storage
* Use `SECRET_STORAGE_ALGORITHM_V1_AES` from `secret-storage`
* Add a test case for the quality gate
* Update src/secret-storage.ts
I introduced a flaky test to confirm that `MegolmEncryption#prepareToEncrypt`
didn't block the main thread too much, but it turns out that, when run in
varying environments, it tends to fail.
The same behavior is guaranteed by the following cancellation test - if the
thread is blocked, it can't be cancelled.
Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
NOTE: This commit introduces a backwards-compatible API change.
Adds the ability to cancel `MegolmEncryption#prepareToEncrypt` by returning
a cancellation function. The bulk of the processing happens in
`getDevicesInRoom`, which now accepts a 'getter' that allows the caller to
indicate cancellation.
See https://github.com/matrix-org/matrix-js-sdk/issues/1255Closes#1255
Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
* Use a PrefixedLogger throughout `megolm.ts`
Rather than manually adding `in ${this.roomId}` to each log line, use a
PrefixedLogger to achieve the same effect more consistently.
* Clean up logging in megolm.ts
Where we log a list of devices, we don't need the whole deviceinfo, just the
device id. All that noise makes it very hard to read the logs.
* Log users that we find in the room when encrypting
* Reduce log verbosity on decryption retries
Part of https://github.com/vector-im/element-web/issues/21972. Eventually I want to replace the whole of the current `Crypto` implementation with an alternative implementation, but in order to get from here to there, I'm factoring out a common interface which will be implemented by both implementations.
I'm also determined to fix the problem where the innards of the crypto implementation are exposed to applications via the `MatrixClient.crypto` property.
It's not (yet) entirely clear what shape this interface should be, so I'm going with a minimal approach and adding things as we know we need them. This means that we need to keep the old `client.crypto` property around as well as a new `client.cryptoBackend` property. Eventually `client.crypto` will go away, but that will be a breaking change in the js-sdk.
ensureOutboundSession uses and modifies the setupPromise of the
MegolmEncryption class. Some comments suggest that setupPromise will
always resolve, in other words it should never contain a promise that
will get rejected.
Other comments also seem to suggest that the return value of
ensureOutboundSession, a promise as well, may fail.
The critical error here is that the promise that gets set as
the next setupPromise, as well as the promise that ensureOutboundSession
returns, is the same promise.
It seems that the intention was for setupPromise to contain a promise
that will always resolve to either `null` or `OutboundSessionInfo`.
We can see that a couple of lines before we set setupPromise to its new
value we construct a promise that logs and discards errors using the
`Promise.catch()` method.
The `Promise.catch()` method does not mutate the promise, instead it
returns a new promise. The intention of the original author might have
been to set the next setupPromise to the promise which `Promise.catch()`
produces.
This patch modifies the updating of setupPromise in the
ensureOutboundSession so that setupPromise discards errors correctly.
Using `>>=` to represent the promise chaining operation, setupPromise is
now updated using the following logic:
setupPromise = previousSetupPromise >>= setup >>= discardErrors
Rather than waiting for the application to call `.startClient`, upload the
device keys during `initCrypto()`. Element-R is going to approach this slightly
differently (it wants to manage the decision on key uploads itself), so this
lays some groundwork by collecting the libolm-specific bits together.
To make it easier to track down where to-device messages are getting lost,
add a custom property to each one, and log its value. Synapse will also log
this property.