Skip to content

Commit 771c33d

Browse files
committed
chore(crypto): Bump vodozemac
Vodozemac used to accept and return strings when encrypting and decrypting. This is quite unusual for a pure cryptographic library so we switched towards the usual setup where we encrypt/decrypt raw bytes. Since we do encrypt/decrypt JSON strings in Matrix land, we do the string conversions over here.
1 parent f3e69a2 commit 771c33d

File tree

9 files changed

+16
-9
lines changed

9 files changed

+16
-9
lines changed

Diff for: bindings/matrix-sdk-crypto-ffi/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ features = ["rt-multi-thread"]
5757

5858
[dependencies.vodozemac]
5959
git = "https://github.com/matrix-org/vodozemac/"
60-
rev = "d0e744287a14319c2a9148fef3747548c740fc36"
60+
rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd"
6161

6262
[build-dependencies]
6363
uniffi_build = { version = "0.18.0", features = ["builtin-bindgen"] }

Diff for: bindings/matrix-sdk-crypto-js/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ docsrs = []
3030
matrix-sdk-common = { version = "0.5.0", path = "../../crates/matrix-sdk-common" }
3131
matrix-sdk-crypto = { version = "0.5.0", path = "../../crates/matrix-sdk-crypto" }
3232
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f", features = ["client-api-c", "js", "rand", "unstable-msc2676", "unstable-msc2677"] }
33-
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36", features = ["js"] }
33+
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd", features = ["js"] }
3434
wasm-bindgen = "0.2.80"
3535
wasm-bindgen-futures = "0.4.30"
3636
js-sys = "0.3.49"

Diff for: bindings/matrix-sdk-crypto-nodejs/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ matrix-sdk-crypto = { version = "0.5.0", path = "../../crates/matrix-sdk-crypto"
2929
matrix-sdk-common = { version = "0.5.0", path = "../../crates/matrix-sdk-common" }
3030
matrix-sdk-sled = { version = "0.1.0", path = "../../crates/matrix-sdk-sled", default-features = false, features = ["crypto-store"] }
3131
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f", features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] }
32-
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36" }
32+
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd" }
3333
napi = { git = "https://github.com/Hywan/napi-rs", branch = "feat-either-n-up-to-26", default-features = false, features = ["napi6", "tokio_rt"] }
3434
napi-derive = { git = "https://github.com/Hywan/napi-rs", branch = "feat-either-n-up-to-26" }
3535
serde_json = "1.0.79"

Diff for: crates/matrix-sdk-crypto/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ zeroize = { version = "1.3.0", features = ["zeroize_derive"] }
5252
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
5353
tokio = { version = "1.18", default-features = false, features = ["time"] }
5454
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f", features = ["client-api-c", "rand", "canonical-json", "unstable-msc2676", "unstable-msc2677"] }
55-
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36" }
55+
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd" }
5656

5757
[target.'cfg(target_arch = "wasm32")'.dependencies]
5858
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f", features = ["client-api-c", "js", "rand", "canonical-json", "unstable-msc2676", "unstable-msc2677"] }
59-
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36", features = ["js"] }
59+
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd", features = ["js"] }
6060

6161
[dev-dependencies]
6262
futures = { version = "0.3.21", default-features = false, features = ["executor"] }

Diff for: crates/matrix-sdk-crypto/src/olm/account.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,9 @@ impl ReadOnlyAccount {
10401040
last_use_time: now,
10411041
};
10421042

1043-
Ok(InboundCreationResult { session, plaintext: result.plaintext })
1043+
let plaintext = String::from_utf8_lossy(&result.plaintext).to_string();
1044+
1045+
Ok(InboundCreationResult { session, plaintext })
10441046
}
10451047

10461048
/// Create a group session pair.

Diff for: crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ impl InboundGroupSession {
353353
let message = MegolmMessage::from_base64(&content.ciphertext)?;
354354

355355
let decrypted = self.decrypt_helper(&message).await?;
356+
let plaintext = String::from_utf8_lossy(&decrypted.plaintext);
356357

357-
let mut decrypted_value = serde_json::from_str::<Value>(&decrypted.plaintext)?;
358+
let mut decrypted_value = serde_json::from_str::<Value>(&plaintext)?;
358359
let decrypted_object = decrypted_value.as_object_mut().ok_or(EventError::NotAnObject)?;
359360

360361
let server_ts: i64 = event.origin_server_ts.0.into();

Diff for: crates/matrix-sdk-crypto/src/olm/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ pub(crate) mod tests {
173173
let plaintext = "This is a secret to everybody".to_owned();
174174
let ciphertext = outbound.encrypt_helper(plaintext.clone()).await;
175175

176-
assert_eq!(plaintext, inbound.decrypt_helper(&ciphertext).await.unwrap().plaintext);
176+
assert_eq!(
177+
plaintext.as_bytes(),
178+
inbound.decrypt_helper(&ciphertext).await.unwrap().plaintext
179+
);
177180
}
178181

179182
#[async_test]

Diff for: crates/matrix-sdk-crypto/src/olm/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl Session {
8383
/// * `message` - The Olm message that should be decrypted.
8484
pub async fn decrypt(&mut self, message: &OlmMessage) -> Result<String, DecryptionError> {
8585
let plaintext = self.inner.lock().await.decrypt(message)?;
86+
let plaintext = String::from_utf8_lossy(&plaintext).to_string();
8687
self.last_use_time = SecondsSinceUnixEpoch::now();
8788
Ok(plaintext)
8889
}

Diff for: crates/matrix-sdk-qrcode/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ thiserror = "1.0.30"
3030

3131
[dependencies.vodozemac]
3232
git = "https://github.com/matrix-org/vodozemac/"
33-
rev = "d0e744287a14319c2a9148fef3747548c740fc36"
33+
rev = "2404f83f7d3a3779c1f518e4d949f7da9677c3dd"

0 commit comments

Comments
 (0)