mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-24 08:36:10 -04:00
feat(crypto): Throw an error if our user/device pair isn't what we have in the store
This commit is contained in:
@@ -78,7 +78,8 @@ use crate::{
|
||||
Signatures,
|
||||
},
|
||||
verification::{Verification, VerificationMachine, VerificationRequest},
|
||||
CrossSigningKeyExport, ReadOnlyDevice, RoomKeyImportResult, SignatureError, ToDeviceRequest,
|
||||
CrossSigningKeyExport, CryptoStoreError, ReadOnlyDevice, RoomKeyImportResult, SignatureError,
|
||||
ToDeviceRequest,
|
||||
};
|
||||
|
||||
/// State machine implementation of the Olm/Megolm encryption protocol used for
|
||||
@@ -233,11 +234,18 @@ impl OlmMachine {
|
||||
) -> StoreResult<Self> {
|
||||
let account = match store.load_account().await? {
|
||||
Some(a) => {
|
||||
debug!(
|
||||
ed25519_key = a.identity_keys().ed25519.to_base64().as_str(),
|
||||
"Restored an Olm account"
|
||||
);
|
||||
a
|
||||
if user_id != a.user_id() || device_id != a.device_id() {
|
||||
return Err(CryptoStoreError::MismatchedAccount {
|
||||
expected: (a.user_id().to_owned(), a.device_id().to_owned()),
|
||||
got: (user_id.to_owned(), device_id.to_owned()),
|
||||
});
|
||||
} else {
|
||||
debug!(
|
||||
ed25519_key = a.identity_keys().ed25519.to_base64().as_str(),
|
||||
"Restored an Olm account"
|
||||
);
|
||||
a
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let account = ReadOnlyAccount::new(user_id, device_id);
|
||||
|
||||
@@ -725,6 +725,19 @@ pub enum CryptoStoreError {
|
||||
#[error("can't save/load sessions or group sessions in the store before an account is stored")]
|
||||
AccountUnset,
|
||||
|
||||
/// The store doesn't support multiple accounts and data from another device
|
||||
/// was discovered.
|
||||
#[error(
|
||||
"the account in the store doesn't match the account in the constructor: \
|
||||
expected {}:{}, got {}:{}", .expected.0, .expected.1, .got.0, .got.1
|
||||
)]
|
||||
MismatchedAccount {
|
||||
/// The expected user/device id pair.
|
||||
expected: (OwnedUserId, OwnedDeviceId),
|
||||
/// The user/device id pair that was loaded from the store.
|
||||
got: (OwnedUserId, OwnedDeviceId),
|
||||
},
|
||||
|
||||
/// An IO error occurred.
|
||||
#[error(transparent)]
|
||||
Io(#[from] IoError),
|
||||
|
||||
Reference in New Issue
Block a user