Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for importing stored data from libolm #77

Merged
merged 8 commits into from
Jan 8, 2024
Merged

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Dec 29, 2023

Fixes #78

Based on #76

@richvdh richvdh requested a review from a team as a code owner December 29, 2023 17:41
@richvdh richvdh requested review from bnjbvr and removed request for a team December 29, 2023 17:41
@richvdh richvdh force-pushed the rav/libolm_migration branch from 84c140a to 4ec15cb Compare January 3, 2024 17:39
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Mostly rust-isms in my comments, it would be super nice if someone from the crypto team could double-check the crypto logic here.

src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
tests/libolm_migration.test.ts Show resolved Hide resolved
@richvdh richvdh requested a review from bnjbvr January 4, 2024 12:57
@richvdh
Copy link
Member Author

richvdh commented Jan 4, 2024

@bnjbvr: Thanks for the review! Please take another look.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
Copy link
Member

@BillCarsonFr BillCarsonFr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments. I think that the migration of tracked users is missing?


/// The private, base64-encoded, master cross-signing key.
#[wasm_bindgen(js_name = "crossSigningMasterKey")]
pub cross_signing_master_key: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth addind in the name of the field (or in the binding name) that it's the private part? Same for the 4 secrets?

data.cross_signing_master_key.as_deref(),
data.cross_signing_self_signing_key.as_deref(),
data.cross_signing_user_signing_key.as_deref(),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should .zeroize() the data.cross_signing_* at this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered about that. I concluded it's not worthwhile, because even if we zeroize it on the Rust side, there may well still be copies kicking around in memory from the javascript side which we have no hope of zeroizing. (As https://github.com/veorq/cryptocoding#clean-memory-of-secret-data says: "there's virtually no way to reliably clean secret data in garbage-collected languages (such as ... Javascript)").

And we don't generally zeroize any other sensitive data that is passed through the wasm bindings.

) -> Result<JsValue, JsError> {
let pickle_key = pickle_key.to_vec();

let rust_sessions = sessions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one of the megolm session to import is for some reason malformed/corrupted, will the whole chunk fail to import?
Maybe it would be better to ignore "malformed" and log something but not interrupt all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely convinced. This sounds like we could end up not migrating any sessions, and the user would just be confused.

Also: once the batch is successfully imported, we delete it from the legacy store. So, if we do fail to import any sessions, we'd end up completely throwing them away, which seems very dangerous.

I'd prefer to leave it and see if any errors actually arise in practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exacty related but we have seen sort of similar things when importing from backup, also when migrating tracked users (legacy is more lax on userIds).

Could we return a result with the succesfully migrated things? so that the caller would delete only these and handle the error on the application side?
I'll let you decide what's best

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we return a result with the succesfully migrated things? so that the caller would delete only these and handle the error on the application side?

Well, if we don't delete the broken sessions, then we'll just get stuck in a loop of repeatedly trying to migrate them. (There is no record of "which sessions have been migrated").)

I suppose one thing that we might think about is whether we can display an error to the user if migration goes wrong.

/// * `store_handle` - A connection to the CryptoStore which will be used to
/// store the vodozemac data.
#[wasm_bindgen(js_name = "migrateMegolmSessions")]
pub async fn migrate_megolm_sessions(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be potentially a lot of sessions. Should we inform the caller to do that in chunks? Or have some progress reporting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention is that the application calls this with small enough batches that there is no need for an intermediate progress update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe document that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/libolm_migration.rs Show resolved Hide resolved
/// Can be imported into the rust store with {@link #migrateBaseData}.
#[wasm_bindgen(getter_with_clone)]
#[derive(Debug, Default)]
pub struct BaseMigrationData {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be a list of tracked users here? or a migrate_tracked_users method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed elsewhere: I don't think there's any need to migrate the tracked users.

... to emphasise that we need the private keys
Base automatically changed from rav/store_handle to main January 8, 2024 12:05
@richvdh richvdh enabled auto-merge (squash) January 8, 2024 12:15
@richvdh richvdh merged commit f0200d4 into main Jan 8, 2024
3 checks passed
@richvdh richvdh deleted the rav/libolm_migration branch January 8, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose libolm migration code in wasm bindings
3 participants