diff --git a/Cargo.lock b/Cargo.lock index c5bfbd124..ac9b90c74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -550,9 +550,9 @@ dependencies = [ [[package]] name = "eyeball-im" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43e8e9d31591be508826b875d8fe6056aebcaec3281ac0e45434ff303686c566" +checksum = "4790c03df183c2b46665c1a58118c04fd3e3976ec2fe16a0aa00e00c9eea7754" dependencies = [ "futures-core", "imbl", @@ -903,9 +903,9 @@ dependencies = [ [[package]] name = "imbl" -version = "5.0.0" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4308a675e4cfc1920f36a8f4d8fb62d5533b7da106844bd1ec51c6f1fa94a0c" +checksum = "0fade8ae6828627ad1fa094a891eccfb25150b383047190a3648d66d06186501" dependencies = [ "archery", "bitmaps", @@ -1208,8 +1208,7 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb33a986495135e217f28cfe0918bf7d01a9800e42f4ef88afbd48e23b8cc53" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=0d563459f49d8940b6ebdc8464642accf1c78aa4#0d563459f49d8940b6ebdc8464642accf1c78aa4" dependencies = [ "eyeball-im", "futures-core", @@ -1232,8 +1231,7 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61bf6c3195de301c98339283413a4e9d9d63c4f214ef8955147643caab161256" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=0d563459f49d8940b6ebdc8464642accf1c78aa4#0d563459f49d8940b6ebdc8464642accf1c78aa4" dependencies = [ "aes", "aquamarine", @@ -1301,8 +1299,7 @@ dependencies = [ [[package]] name = "matrix-sdk-indexeddb" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2752015e69b6b56a8df72e52f91a834771259f755eb1c65232b77348ffb16b" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=0d563459f49d8940b6ebdc8464642accf1c78aa4#0d563459f49d8940b6ebdc8464642accf1c78aa4" dependencies = [ "anyhow", "async-trait", @@ -1331,8 +1328,7 @@ dependencies = [ [[package]] name = "matrix-sdk-qrcode" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e46baa0a7fd0e6e648887c0edfeb739682f7e12242986ffdf4300791cdbe199" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=0d563459f49d8940b6ebdc8464642accf1c78aa4#0d563459f49d8940b6ebdc8464642accf1c78aa4" dependencies = [ "byteorder", "qrcode", @@ -1344,8 +1340,7 @@ dependencies = [ [[package]] name = "matrix-sdk-store-encryption" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e0aac550e685306fbbd57faae8f98af9812f19bbf0f83da7559d67cf4789679" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=0d563459f49d8940b6ebdc8464642accf1c78aa4#0d563459f49d8940b6ebdc8464642accf1c78aa4" dependencies = [ "base64", "blake3", @@ -1823,8 +1818,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7b698b728bc3747f564a9115c83b4f2e229b52377f6a1cca2e6add9cf4a13be" +source = "git+https://github.com/ruma/ruma?rev=2f64faeabb85950de27e9829faeb389d2779ac57#2f64faeabb85950de27e9829faeb389d2779ac57" dependencies = [ "assign", "js_int", @@ -1839,8 +1833,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b54e56c591f9ad686defb0bacbebba5c8882eb0c9f8734f6a080345b4e3dd941" +source = "git+https://github.com/ruma/ruma?rev=2f64faeabb85950de27e9829faeb389d2779ac57#2f64faeabb85950de27e9829faeb389d2779ac57" dependencies = [ "as_variant", "assign", @@ -1863,8 +1856,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac7f59b9f7639667d0d6ae3ae242c8912e9ed061cea1fbaf72710a402e83b53e" +source = "git+https://github.com/ruma/ruma?rev=2f64faeabb85950de27e9829faeb389d2779ac57#2f64faeabb85950de27e9829faeb389d2779ac57" dependencies = [ "as_variant", "base64", @@ -1897,8 +1889,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.31.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34fa815769ed4fe1ef5b50aa0ba6f350317c13b5a9f1e008b014f4a3ddf14204" +source = "git+https://github.com/ruma/ruma?rev=2f64faeabb85950de27e9829faeb389d2779ac57#2f64faeabb85950de27e9829faeb389d2779ac57" dependencies = [ "as_variant", "indexmap", @@ -1922,8 +1913,7 @@ dependencies = [ [[package]] name = "ruma-html" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6124d74847ea788601477c89a44485894432a806824cae93885c5825a8ae9dbc" +source = "git+https://github.com/ruma/ruma?rev=2f64faeabb85950de27e9829faeb389d2779ac57#2f64faeabb85950de27e9829faeb389d2779ac57" dependencies = [ "as_variant", "html5ever", @@ -1934,8 +1924,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14a7b93ac1e571c585f8fa5cef09c07bb8a15529775fd56b9a3eac4f9233dff2" +source = "git+https://github.com/ruma/ruma?rev=2f64faeabb85950de27e9829faeb389d2779ac57#2f64faeabb85950de27e9829faeb389d2779ac57" dependencies = [ "js_int", "thiserror 2.0.16", @@ -1944,8 +1933,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9911c7188517f28505d2d513339511d00e0f50cec5c2dde820cd0ec7e6a833" +source = "git+https://github.com/ruma/ruma?rev=2f64faeabb85950de27e9829faeb389d2779ac57#2f64faeabb85950de27e9829faeb389d2779ac57" dependencies = [ "cfg-if", "proc-macro-crate", diff --git a/Cargo.toml b/Cargo.toml index 7050d2c1b..3157526dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,9 +64,9 @@ futures-util = "0.3.27" getrandom = { version = "0.3.0", features = ["wasm_js"] } http = "1.1.0" js-sys = "0.3.49" -matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"] , version = "0.14.0" } -matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"] , version = "0.14.0" } -matrix-sdk-qrcode = { optional = true , version = "0.14.0" } +matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"] , git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0d563459f49d8940b6ebdc8464642accf1c78aa4" } +matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"] , git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0d563459f49d8940b6ebdc8464642accf1c78aa4" } +matrix-sdk-qrcode = { optional = true , git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0d563459f49d8940b6ebdc8464642accf1c78aa4" } serde = "1.0.91" serde_json = "1.0.91" serde-wasm-bindgen = "0.6.5" @@ -85,7 +85,8 @@ vergen-gitcl = { version = "1.0.0", features = ["build"] } [dependencies.matrix-sdk-crypto] default-features = false features = ["js", "automatic-room-key-forwarding", "experimental-encrypted-state-events"] -version = "0.14.0" +git = "https://github.com/matrix-org/matrix-rust-sdk" +rev = "0d563459f49d8940b6ebdc8464642accf1c78aa4" [lints.rust] # Workaround for https://github.com/rustwasm/wasm-bindgen/issues/4283, while we work up the courage to upgrade diff --git a/src/error.rs b/src/error.rs index 3ce47c7e1..39e467d68 100644 --- a/src/error.rs +++ b/src/error.rs @@ -63,7 +63,7 @@ impl From for MegolmDecryptionError { maybe_withheld: Option<&WithheldCode>| -> MegolmDecryptionError { let description = value.to_string().into(); - let maybe_withheld = maybe_withheld.map(|code| code.to_string().to_owned().into()); + let maybe_withheld = maybe_withheld.map(|code| code.as_str().to_owned().into()); MegolmDecryptionError { code, description, maybe_withheld } }; diff --git a/src/store.rs b/src/store.rs index 9d9c47dc5..6769cf266 100644 --- a/src/store.rs +++ b/src/store.rs @@ -234,20 +234,28 @@ impl_from_to_inner!(matrix_sdk_crypto::store::types::RoomKeyWithheldInfo => Room #[wasm_bindgen] impl RoomKeyWithheldInfo { - /// The User ID of the user that sent us the `m.room_key.withheld` message. + /// The User ID of the sender of the withheld information. + /// + /// This may be the sender of an `m.room_key.withheld` event, or the sender + /// of a shared room key bundle under MSC4268. #[wasm_bindgen(getter)] pub fn sender(&self) -> UserId { self.inner.withheld_event.sender.to_owned().into() } /// The encryption algorithm of the session that is being withheld. + /// + /// This may be from an `m.room_key.withheld` event, or from a shared room + /// key bundle under MSC4268. #[wasm_bindgen(getter)] pub fn algorithm(&self) -> EncryptionAlgorithm { self.inner.withheld_event.content.algorithm().into() } - /// The `code` from the `m.room_key.withheld` message, such as - /// `m.unverified`. + /// The `code` indicating why the key was withheld. + /// + /// This may be the `code` from an `m.room_key.withheld` event (such as + /// `m.unverified`), or from a shared room key bundle under MSC4268. #[wasm_bindgen(getter, js_name = "withheldCode")] pub fn withheld_code(&self) -> String { self.inner.withheld_event.content.withheld_code().as_str().to_owned() diff --git a/tests/machine.test.ts b/tests/machine.test.ts index a333a3ab1..e6ea54685 100644 --- a/tests/machine.test.ts +++ b/tests/machine.test.ts @@ -899,6 +899,59 @@ describe(OlmMachine.name, () => { expect(withheld[0].withheldCode).toEqual("m.unverified"); }); + test("decrypting a message from a withheld session throws MegolmDecryptionError with correct withheld code", async () => { + const m = await machine(); + + // Simulate receiving a withheld event for a session + const withheldEvent = { + sender: "@alice:example.com", + type: "m.room_key.withheld", + content: { + algorithm: "m.megolm.v1.aes-sha2", + code: "m.unverified", + reason: "Device not verified", + room_id: room.toString(), + sender_key: m.identityKeys.curve25519.toBase64(), + session_id: "SESSION_ID_WITHHELD", + }, + }; + await m.receiveSyncChanges( + JSON.stringify([withheldEvent]), + new DeviceLists(), + new Map(), + undefined, + ); + + // Now try to decrypt a message from that session + const encryptedEvent = { + type: "m.room.encrypted", + event_id: "$xxxxx:example.org", + origin_server_ts: Date.now(), + sender: user.toString(), + content: { + algorithm: "m.megolm.v1.aes-sha2", + ciphertext: + "AwgAEpABhetEzzZzyYrxtEVUtlJnZtJcURBlQUQJ9irVeklCTs06LwgTMQj61PMUS4VyYOX+PD67+hhU40/8olOww+Ud0m2afjMjC3wFX+4fFfSkoWPVHEmRVucfcdSF1RSB4EmKPIP4eo1X6x8kCIMewBvxl2sI9j4VNvDvAN7M3zkLJfFLOFHbBviI4FN7hSFHFeM739ZgiwxEs3hIkUXEiAfrobzaMEM/zY7SDrTdyffZndgJo7CZOVhoV6vuaOhmAy4X2t4UnbuVJGJjKfV57NAhp8W+9oT7ugwO", + sender_key: m.identityKeys.curve25519.toBase64(), + session_id: "SESSION_ID_WITHHELD", + }, + unsigned: { + age: 1234, + }, + }; + + try { + const decryptionSettings = new DecryptionSettings(TrustRequirement.Untrusted); + await m.decryptRoomEvent(JSON.stringify(encryptedEvent), room, decryptionSettings); + fail("Expected MegolmDecryptionError to be thrown"); + } catch (err) { + expect(err).toBeInstanceOf(MegolmDecryptionError); + console.log((err as MegolmDecryptionError).description); + expect((err as MegolmDecryptionError).code).toStrictEqual(DecryptionErrorCode.MissingRoomKey); + expect((err as MegolmDecryptionError).maybe_withheld).toEqual("m.unverified"); + } + }); + test("can export room keys", async () => { let m = await machine(); await m.shareRoomKey(room, [new UserId("@bob:example.org")], new EncryptionSettings());