Skip to content

Commit 2bb9c5f

Browse files
authored
Merge pull request #248 from matrix-org/rav/update_sdk_2/mismatched_sender
Add `DecryptionErrorCode::MismatchedSender`.
2 parents e3b691b + 6e42cc2 commit 2bb9c5f

File tree

10 files changed

+77
-74
lines changed

10 files changed

+77
-74
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# UNRELEASED
22

3+
- Update matrix-rust-sdk to `6ab11a032`.
4+
5+
- Add a new error code for `MegolmDecryptionError`, `DecryptionErrorCode::MismatchedSender`, indicating that the sender of the event does not match the owner of the device that established the Megolm session. ([#248](https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/248))
6+
37
# matrix-sdk-crypto-wasm v15.0.0
48

59
- Update matrix-rusk-sdk to `0.12.0`, which includes:
@@ -41,7 +45,8 @@ Update matrix-sdk-crypto to `0.11.1`, which includes:
4145

4246
- Check the sender of an event matches owner of session, preventing sender
4347
spoofing by homeserver owners.
44-
[13c1d20](https://github.com/matrix-org/matrix-rust-sdk/commit/13c1d2048286bbabf5e7bc6b015aafee98f04d55) (High, [GHSA-x958-rvg6-956w](https://github.com/matrix-org/matrix-rust-sdk/security/advisories/GHSA-x958-rvg6-956w)).
48+
[13c1d20](https://github.com/matrix-org/matrix-rust-sdk/commit/13c1d2048286bbabf5e7bc6b015aafee98f04d55) (
49+
High, [GHSA-x958-rvg6-956w](https://github.com/matrix-org/matrix-rust-sdk/security/advisories/GHSA-x958-rvg6-956w)).
4550

4651
# matrix-sdk-crypto-wasm v14.2.0
4752

Cargo.lock

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ futures-util = "0.3.27"
6464
getrandom = { version = "0.3.0", features = ["wasm_js"] }
6565
http = "1.1.0"
6666
js-sys = "0.3.49"
67-
matrix-sdk-common = { version = "0.12.0", features = ["js"] }
68-
matrix-sdk-indexeddb = { version = "0.12.0", default-features = false, features = ["e2e-encryption"] }
69-
matrix-sdk-qrcode = { version = "0.12.0", optional = true }
67+
matrix-sdk-common = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "6ab11a032", features = ["js"] }
68+
matrix-sdk-indexeddb = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "6ab11a032", default-features = false, features = ["e2e-encryption"] }
69+
matrix-sdk-qrcode = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "6ab11a032", optional = true }
7070
serde = "1.0.91"
7171
serde_json = "1.0.91"
7272
serde-wasm-bindgen = "0.6.5"
@@ -83,7 +83,8 @@ wasm-bindgen-test = "0.3.37"
8383
vergen-gitcl = { version = "1.0.0", features = ["build"] }
8484

8585
[dependencies.matrix-sdk-crypto]
86-
version = "0.12.0"
86+
git = "https://github.com/matrix-org/matrix-rust-sdk"
87+
rev = "6ab11a032"
8788
default-features = false
8889
features = ["js", "automatic-room-key-forwarding"]
8990

src/backup.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use crate::impl_from_to_inner;
1010
#[derive(Debug, Clone)]
1111
#[wasm_bindgen]
1212
pub struct BackupDecryptionKey {
13-
pub(crate) inner: store::BackupDecryptionKey,
13+
pub(crate) inner: store::types::BackupDecryptionKey,
1414
}
1515

16-
impl_from_to_inner!(store::BackupDecryptionKey => BackupDecryptionKey);
16+
impl_from_to_inner!(store::types::BackupDecryptionKey => BackupDecryptionKey);
1717

1818
/// The public part of the backup key.
1919
#[derive(Debug, Clone)]
@@ -43,15 +43,15 @@ impl BackupDecryptionKey {
4343
#[wasm_bindgen(js_name = "createRandomKey")]
4444
pub fn create_random_key() -> BackupDecryptionKey {
4545
BackupDecryptionKey {
46-
inner: store::BackupDecryptionKey::new()
46+
inner: store::types::BackupDecryptionKey::new()
4747
.expect("Can't gather enough randomness to create a recovery key"),
4848
}
4949
}
5050

5151
/// Try to create a [`BackupDecryptionKey`] from a base 64 encoded string.
5252
#[wasm_bindgen(js_name = "fromBase64")]
5353
pub fn from_base64(key: String) -> Result<BackupDecryptionKey, JsError> {
54-
Ok(Self { inner: store::BackupDecryptionKey::from_base64(&key)? })
54+
Ok(Self { inner: store::types::BackupDecryptionKey::from_base64(&key)? })
5555
}
5656

5757
/// Convert the backup decryption key to a base 64 encoded string.
@@ -92,8 +92,8 @@ pub struct RoomKeyCounts {
9292
pub backed_up: f64,
9393
}
9494

95-
impl From<matrix_sdk_crypto::store::RoomKeyCounts> for RoomKeyCounts {
96-
fn from(inner: matrix_sdk_crypto::store::RoomKeyCounts) -> Self {
95+
impl From<store::types::RoomKeyCounts> for RoomKeyCounts {
96+
fn from(inner: store::types::RoomKeyCounts) -> Self {
9797
RoomKeyCounts {
9898
// There is no `TryFrom<usize> for f64`, so first downcast the usizes to u32, then back
9999
// up to f64

src/dehydrated_devices.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use js_sys::{Array, JsString, Uint8Array};
66
use matrix_sdk_crypto::{
7-
dehydrated_devices, store::DehydratedDeviceKey as InnerDehydratedDeviceKey,
7+
dehydrated_devices, store::types::DehydratedDeviceKey as InnerDehydratedDeviceKey,
88
};
99
use wasm_bindgen::prelude::*;
1010

src/error.rs

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Errors related to room event decryption.
22
33
use js_sys::JsString;
4-
use matrix_sdk_common::deserialized_responses::VerificationLevel;
4+
use matrix_sdk_common::deserialized_responses::{VerificationLevel, WithheldCode};
55
use matrix_sdk_crypto::{vodozemac, MegolmError};
6+
use tracing::warn;
67
use wasm_bindgen::prelude::wasm_bindgen;
78

89
/// Decryption error codes
@@ -25,6 +26,9 @@ pub enum DecryptionErrorCode {
2526
SenderIdentityVerificationViolation,
2627
/// Other failure.
2728
UnableToDecrypt,
29+
/// The `sender` field on the event does not match the owner of the device
30+
/// that established the Megolm session.
31+
MismatchedSender,
2832
}
2933

3034
/// Js Decryption error with code.
@@ -55,52 +59,47 @@ impl MegolmDecryptionError {
5559

5660
impl From<MegolmError> for MegolmDecryptionError {
5761
fn from(value: MegolmError) -> Self {
62+
let decryption_error = |code: DecryptionErrorCode,
63+
maybe_withheld: Option<&WithheldCode>|
64+
-> MegolmDecryptionError {
65+
let description = value.to_string().into();
66+
let maybe_withheld = maybe_withheld.map(|code| code.to_string().to_owned().into());
67+
MegolmDecryptionError { code, description, maybe_withheld }
68+
};
69+
5870
match &value {
59-
MegolmError::MissingRoomKey(withheld_code) => MegolmDecryptionError {
60-
code: DecryptionErrorCode::MissingRoomKey,
61-
description: value.to_string().into(),
62-
maybe_withheld: withheld_code
63-
.as_ref()
64-
.map(|code| code.to_string().to_owned().into()),
65-
},
71+
MegolmError::MissingRoomKey(withheld_code) => {
72+
decryption_error(DecryptionErrorCode::MissingRoomKey, withheld_code.as_ref())
73+
}
6674
MegolmError::Decryption(vodozemac::megolm::DecryptionError::UnknownMessageIndex(
6775
..,
68-
)) => MegolmDecryptionError {
69-
code: DecryptionErrorCode::UnknownMessageIndex,
70-
description: value.to_string().into(),
71-
maybe_withheld: None,
72-
},
73-
MegolmError::MismatchedIdentityKeys { .. } => MegolmDecryptionError {
74-
code: DecryptionErrorCode::UnknownMessageIndex,
75-
description: value.to_string().into(),
76-
maybe_withheld: None,
77-
},
78-
MegolmError::SenderIdentityNotTrusted(VerificationLevel::VerificationViolation) => {
79-
MegolmDecryptionError {
80-
code: DecryptionErrorCode::SenderIdentityVerificationViolation,
81-
description: value.to_string().into(),
82-
maybe_withheld: None,
83-
}
76+
)) => decryption_error(DecryptionErrorCode::UnknownMessageIndex, None),
77+
MegolmError::MismatchedIdentityKeys { .. } => {
78+
decryption_error(DecryptionErrorCode::UnknownMessageIndex, None)
8479
}
85-
MegolmError::SenderIdentityNotTrusted(VerificationLevel::UnsignedDevice) => {
86-
MegolmDecryptionError {
87-
code: DecryptionErrorCode::UnsignedSenderDevice,
88-
description: value.to_string().into(),
89-
maybe_withheld: None,
80+
MegolmError::SenderIdentityNotTrusted(vl) => match vl {
81+
VerificationLevel::VerificationViolation => {
82+
decryption_error(DecryptionErrorCode::SenderIdentityVerificationViolation, None)
9083
}
91-
}
92-
MegolmError::SenderIdentityNotTrusted(VerificationLevel::None(..)) => {
93-
MegolmDecryptionError {
94-
code: DecryptionErrorCode::UnknownSenderDevice,
95-
description: value.to_string().into(),
96-
maybe_withheld: None,
84+
VerificationLevel::UnsignedDevice => {
85+
decryption_error(DecryptionErrorCode::UnsignedSenderDevice, None)
86+
}
87+
VerificationLevel::None(..) => {
88+
decryption_error(DecryptionErrorCode::UnknownSenderDevice, None)
89+
}
90+
VerificationLevel::UnverifiedIdentity => {
91+
// We do not expect to find this in a MegolmError, since even at the strictest
92+
// `TrustRequirement` level, we are happy to accept events from users whose
93+
// identities we have not verified. We spit out a warning and then treat
94+
// it as a generic UTD.
95+
warn!("Unexpected verification level in megolm decryption error {}", value);
96+
decryption_error(DecryptionErrorCode::UnableToDecrypt, None)
97+
}
98+
VerificationLevel::MismatchedSender => {
99+
decryption_error(DecryptionErrorCode::MismatchedSender, None)
97100
}
98-
}
99-
_ => MegolmDecryptionError {
100-
code: DecryptionErrorCode::UnableToDecrypt,
101-
description: value.to_string().into(),
102-
maybe_withheld: None,
103101
},
102+
_ => decryption_error(DecryptionErrorCode::UnableToDecrypt, None),
104103
}
105104
}
106105
}

src/libolm_migration.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ use matrix_sdk_common::ruma::{
2222
};
2323
use matrix_sdk_crypto::{
2424
olm::PrivateCrossSigningIdentity,
25-
store::{BackupDecryptionKey, Changes, DynCryptoStore, PendingChanges},
25+
store::{
26+
types::{BackupDecryptionKey, Changes, PendingChanges},
27+
DynCryptoStore,
28+
},
2629
types::{EventEncryptionAlgorithm, SigningKeys},
2730
vodozemac,
2831
vodozemac::{Curve25519PublicKey, Ed25519PublicKey},

src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use matrix_sdk_common::ruma::{
1717
use matrix_sdk_crypto::{
1818
backups::MegolmV1BackupKey,
1919
olm::{BackedUpRoomKey, ExportedRoomKey},
20-
store::{DeviceChanges, IdentityChanges},
20+
store::types::{DeviceChanges, IdentityChanges},
2121
types::RoomKeyBackupInfo,
2222
CryptoStoreError, EncryptionSyncChanges, GossippedSecret,
2323
};
@@ -632,7 +632,7 @@ impl OlmMachine {
632632
user_signing_key: Option<String>,
633633
) -> Promise {
634634
let me = self.inner.clone();
635-
let export = matrix_sdk_crypto::store::CrossSigningKeyExport {
635+
let export = matrix_sdk_crypto::store::types::CrossSigningKeyExport {
636636
master_key,
637637
self_signing_key,
638638
user_signing_key,

src/store.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ impl IntoCryptoStore for StoreHandle {
142142
#[wasm_bindgen]
143143
#[derive(Debug)]
144144
pub struct CrossSigningKeyExport {
145-
pub(crate) inner: matrix_sdk_crypto::store::CrossSigningKeyExport,
145+
pub(crate) inner: matrix_sdk_crypto::store::types::CrossSigningKeyExport,
146146
}
147147

148-
impl_from_to_inner!(matrix_sdk_crypto::store::CrossSigningKeyExport => CrossSigningKeyExport);
148+
impl_from_to_inner!(matrix_sdk_crypto::store::types::CrossSigningKeyExport => CrossSigningKeyExport);
149149

150150
#[wasm_bindgen]
151151
impl CrossSigningKeyExport {
@@ -172,10 +172,10 @@ impl CrossSigningKeyExport {
172172
#[wasm_bindgen]
173173
#[derive(Debug)]
174174
pub struct RoomKeyInfo {
175-
pub(crate) inner: matrix_sdk_crypto::store::RoomKeyInfo,
175+
pub(crate) inner: matrix_sdk_crypto::store::types::RoomKeyInfo,
176176
}
177177

178-
impl_from_to_inner!(matrix_sdk_crypto::store::RoomKeyInfo => RoomKeyInfo);
178+
impl_from_to_inner!(matrix_sdk_crypto::store::types::RoomKeyInfo => RoomKeyInfo);
179179

180180
#[wasm_bindgen]
181181
impl RoomKeyInfo {
@@ -209,10 +209,10 @@ impl RoomKeyInfo {
209209
#[wasm_bindgen]
210210
#[derive(Debug)]
211211
pub struct RoomKeyWithheldInfo {
212-
pub(crate) inner: matrix_sdk_crypto::store::RoomKeyWithheldInfo,
212+
pub(crate) inner: matrix_sdk_crypto::store::types::RoomKeyWithheldInfo,
213213
}
214214

215-
impl_from_to_inner!(matrix_sdk_crypto::store::RoomKeyWithheldInfo => RoomKeyWithheldInfo);
215+
impl_from_to_inner!(matrix_sdk_crypto::store::types::RoomKeyWithheldInfo => RoomKeyWithheldInfo);
216216

217217
#[wasm_bindgen]
218218
impl RoomKeyWithheldInfo {

src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ impl Default for RoomSettings {
335335
}
336336
}
337337

338-
impl From<matrix_sdk_crypto::store::RoomSettings> for RoomSettings {
339-
fn from(value: matrix_sdk_crypto::store::RoomSettings) -> Self {
338+
impl From<matrix_sdk_crypto::store::types::RoomSettings> for RoomSettings {
339+
fn from(value: matrix_sdk_crypto::store::types::RoomSettings) -> Self {
340340
Self {
341341
algorithm: value.algorithm.into(),
342342
only_allow_trusted_devices: value.only_allow_trusted_devices,
@@ -350,7 +350,7 @@ impl From<matrix_sdk_crypto::store::RoomSettings> for RoomSettings {
350350
}
351351
}
352352

353-
impl From<&RoomSettings> for matrix_sdk_crypto::store::RoomSettings {
353+
impl From<&RoomSettings> for matrix_sdk_crypto::store::types::RoomSettings {
354354
fn from(value: &RoomSettings) -> Self {
355355
Self {
356356
algorithm: value.algorithm.clone().into(),

0 commit comments

Comments
 (0)