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

chore(crypto): Add consistency check on device when loading account #4564

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/matrix-sdk-crypto/src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ impl OlmMachine {
});
}

// The own device data is always created and saved when the account is created.
// So we expect the own device to exist here. Checking for consistency.
let own_device = store.get_own_device().await;
if own_device.is_err() {
return Err(CryptoStoreError::IncompleteAccountNoOwnDevice);
}

Span::current()
.record("ed25519_key", display(account.identity_keys().ed25519))
.record("curve25519_key", display(account.identity_keys().curve25519));
Expand Down
4 changes: 4 additions & 0 deletions crates/matrix-sdk-crypto/src/store/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub enum CryptoStoreError {
#[error("can't save/load sessions or group sessions in the store before an account is stored")]
AccountUnset,

/// An account was saved but no own device was found.
#[error("Incomplete account, account data was saved but no own device was found")]
IncompleteAccountNoOwnDevice,
Comment on lines +34 to +36
Copy link
Member

Choose a reason for hiding this comment

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

I'm not enthusiastic about adding this here as yet another error code that any API can return: error handling is really hard when you call matrix-sdk-crypto APIs because there are thousands of possible error cases.

Maybe we can specialise the result from with_store?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I was not sure about this one. What do you mean by "specialise" the result?

Copy link
Member

Choose a reason for hiding this comment

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

make it return a different error type in its Result, which more closely reflects the actual possible failure modes of that particular method.


/// The store doesn't support multiple accounts and data from another device
/// was discovered.
#[error(
Expand Down
Loading