matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust crypto: support migration to Rust crypto

richvdh opened this issue · comments

Part of support for migration to Rust Crypto. Depends on matrix-org/matrix-rust-sdk-crypto-wasm#78 and #3963.

Add a new migrateFromLegacyCrypto(legacyStore) method to js-sdk/src/rust-crypto, and call it in MatrixClient.initRustCrypto, before calling RustCrypto.initRustCrypto. First, it needs to check if there might be data to migrate:

  • Call CryptoStore.containsData and skip out if no data.
  • Call CryptoStore.startup.
  • Call CryptoStore.getMigrationState and skip any steps below that are done. Otherwise:
  • Extract the following and send to the rust layer:
    • (Pickled) account.
    • Private cross-signing keys (via CryptoStore.getSecretStorePrivateKey("master") etc)
    • Encrypted rooms (via CryptoStore.getEndToEndRooms)
    • Backup decryption key (via CryptoStore.getSecretStorePrivateKey("m.megolm_backup.v1"))
    • Backup version: we'll have to fetch this from the server (and check the key matches the above).
      Afterwards, call CryptoStore.setMigrationState to flag that this initial import has been done.
  • Then, migrate the Olm and Megolm sessions, in batches.

We need to emit some sort of progress indication, so that the app can give feedback. Probably something as simple as a crypto.dataMigrationProgress event, whose payload includes two numbers including a total number of steps, and a number of steps so far. We can wire this into the progress_listener callback of the rust migration functions.

We are ignoring:

  • Tracked users - I think the rust layer can figure this out for itself
  • Outgoing room key requests - hopefully we won't do these in ER anyway
  • session_problems - stores Olm sessions with decryption problems, for unwedging. We can let the Rust layer figure this out.

Stuff we may need to figure out how to import later:

  • List of withheld inbound group sessions
  • parked_shared_history and shared_history_inbound_group_sessons - something to do with history-share-on-invite, which we don't support in ER yet?