mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-07 23:44:53 -04:00
infrastructure for indexeddb cryptostore
This commit is contained in:
@@ -19,10 +19,13 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
|
||||
default = []
|
||||
encryption = ["matrix-sdk-crypto"]
|
||||
qrcode = ["matrix-sdk-crypto/qrcode"]
|
||||
|
||||
sled_state_store = ["sled", "pbkdf2", "hmac", "sha2", "rand", "chacha20poly1305"]
|
||||
indexeddb_state_store = ["indexed_db_futures", "wasm-bindgen", "pbkdf2", "hmac", "sha2", "rand", "chacha20poly1305"]
|
||||
sled_cryptostore = ["matrix-sdk-crypto/sled_cryptostore"]
|
||||
|
||||
indexeddb_state_store = ["indexed_db_futures", "wasm-bindgen", "pbkdf2", "hmac", "sha2", "rand", "chacha20poly1305"]
|
||||
indexeddb_cryptostore = ["matrix-sdk-crypto/indexeddb_cryptostore"]
|
||||
|
||||
docs = ["encryption", "sled_cryptostore"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -28,9 +28,16 @@
|
||||
#[cfg(all(feature = "sled_state_store", feature = "indexeddb_state_store"))]
|
||||
compile_error!("sled_state_store and indexeddb_state_store are mutually exclusive and cannot be enabled together");
|
||||
|
||||
|
||||
#[cfg(all(feature = "indexeddb_state_store", not(target_arch = "wasm32")))]
|
||||
compile_error!("indexeddb_state_store only works for wasm32 target");
|
||||
|
||||
|
||||
#[cfg(all(feature = "sled_cryptostore", feature = "indexeddb_state_store"))]
|
||||
compile_error!("sled_cryptostore and indexeddb_state_store are mutually exclusive and cannot be enabled together");
|
||||
|
||||
|
||||
|
||||
pub use matrix_sdk_common::*;
|
||||
|
||||
pub use crate::{
|
||||
|
||||
@@ -20,6 +20,7 @@ default = []
|
||||
qrcode = ["matrix-qrcode"]
|
||||
sled_cryptostore = ["sled"]
|
||||
docs = ["sled_cryptostore"]
|
||||
indexeddb_cryptostore = ["indexed_db_futures", "wasm-bindgen"]
|
||||
|
||||
[dependencies]
|
||||
aes = { version = "0.7.4", features = ["ctr"] }
|
||||
@@ -44,21 +45,31 @@ thiserror = "1.0.25"
|
||||
tracing = "0.1.26"
|
||||
zeroize = { version = "1.3.0", features = ["zeroize_derive"] }
|
||||
|
||||
## Feature indexeddb-state-store
|
||||
indexed_db_futures = { version = "0.2.0", optional = true }
|
||||
wasm-bindgen = { version = "0.2.74", features = ["serde-serialize"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.3.4", features = ["async", "async_tokio", "html_reports"] }
|
||||
futures = { version = "0.3.15", default-features = false }
|
||||
http = "0.2.4"
|
||||
indoc = "1.0.3"
|
||||
matches = "0.1.8"
|
||||
matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||
proptest = "1.0.0"
|
||||
serde_json = "1.0.64"
|
||||
tempfile = "3.2.0"
|
||||
criterion = { version = "0.3.4", features = ["async", "async_tokio", "html_reports"] }
|
||||
tokio = { version = "1.7.1", default-features = false, features = ["rt-multi-thread", "macros"] }
|
||||
tempfile = "3.2.0"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dev-dependencies]
|
||||
criterion = { version = "0.3.4", features = ["async", "html_reports"] }
|
||||
pprof = { version = "0.5.0", features = ["flamegraph", "criterion"] }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.24"
|
||||
|
||||
|
||||
[[bench]]
|
||||
name = "crypto_bench"
|
||||
harness = false
|
||||
|
||||
@@ -233,7 +233,7 @@ fn decrypt_helper(ciphertext: &str, passphrase: &str) -> Result<String, KeyExpor
|
||||
Ok(String::from_utf8(ciphertext.to_owned())?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
mod test {
|
||||
use std::io::Cursor;
|
||||
|
||||
|
||||
@@ -934,6 +934,9 @@ mod test {
|
||||
use dashmap::DashMap;
|
||||
use matches::assert_matches;
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
events::{
|
||||
|
||||
@@ -623,6 +623,9 @@ impl PartialEq for ReadOnlyDevice {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma::{encryption::DeviceKeys, user_id, DeviceKeyAlgorithm};
|
||||
|
||||
@@ -461,6 +461,8 @@ impl IdentityManager {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use std::sync::Arc;
|
||||
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
|
||||
@@ -942,6 +942,9 @@ impl ReadOnlyOwnUserIdentity {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![cfg_attr(feature = "docs", feature(doc_cfg))]
|
||||
#![deny(
|
||||
#![allow(
|
||||
missing_debug_implementations,
|
||||
dead_code,
|
||||
missing_docs,
|
||||
@@ -25,6 +25,11 @@
|
||||
unused_qualifications
|
||||
)]
|
||||
|
||||
|
||||
#[cfg(all(feature = "indexeddb_cryptostore", not(target_arch = "wasm32")))]
|
||||
compile_error!("indexeddb_cryptostore only works for wasm32 target");
|
||||
|
||||
|
||||
mod error;
|
||||
mod file_encryption;
|
||||
mod gossiping;
|
||||
|
||||
@@ -651,18 +651,18 @@ impl OlmMachine {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) async fn create_inbound_session(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> OlmResult<InboundGroupSession> {
|
||||
let (_, session) = self
|
||||
.group_session_manager
|
||||
.create_outbound_group_session(room_id, EncryptionSettings::default())
|
||||
.await?;
|
||||
// #[cfg(test)]
|
||||
// pub(crate) async fn create_inbound_session(
|
||||
// &self,
|
||||
// room_id: &RoomId,
|
||||
// ) -> OlmResult<InboundGroupSession> {
|
||||
// let (_, session) = self
|
||||
// .group_session_manager
|
||||
// .create_outbound_group_session(room_id, EncryptionSettings::default())
|
||||
// .await?;
|
||||
|
||||
Ok(session)
|
||||
}
|
||||
// Ok(session)
|
||||
// }
|
||||
|
||||
/// Encrypt a room message for the given room.
|
||||
///
|
||||
@@ -1459,6 +1459,10 @@ impl OlmMachine {
|
||||
pub(crate) mod test {
|
||||
static USER_ID: &str = "@bob:example.org";
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
convert::{TryFrom, TryInto},
|
||||
@@ -1616,13 +1620,13 @@ pub(crate) mod test {
|
||||
(alice, bob)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn create_olm_machine() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
assert!(machine.should_upload_keys().await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn receive_keys_upload_response() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let mut response = keys_upload_response();
|
||||
@@ -1646,7 +1650,7 @@ pub(crate) mod test {
|
||||
assert!(!machine.should_upload_keys().await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn generate_one_time_keys() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
|
||||
@@ -1663,7 +1667,7 @@ pub(crate) mod test {
|
||||
assert!(machine.account.generate_one_time_keys().await.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_device_key_signing() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
|
||||
@@ -1681,7 +1685,7 @@ pub(crate) mod test {
|
||||
assert!(ret.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn tests_session_invalidation() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let room_id = room_id!("!test:example.org");
|
||||
@@ -1698,7 +1702,7 @@ pub(crate) mod test {
|
||||
.invalidated());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_invalid_signature() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
|
||||
@@ -1714,7 +1718,7 @@ pub(crate) mod test {
|
||||
assert!(ret.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_one_time_key_signing() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
machine.account.inner.update_uploaded_key_count(49);
|
||||
@@ -1735,7 +1739,7 @@ pub(crate) mod test {
|
||||
assert!(ret.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_keys_for_upload() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
machine.account.inner.update_uploaded_key_count(0);
|
||||
@@ -1776,7 +1780,7 @@ pub(crate) mod test {
|
||||
assert!(ret.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_keys_query() {
|
||||
let (machine, _) = get_prepared_machine().await;
|
||||
let response = keys_query_response();
|
||||
@@ -1793,7 +1797,7 @@ pub(crate) mod test {
|
||||
assert_eq!(device.device_id(), alice_device_id);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_missing_sessions_calculation() {
|
||||
let (machine, _) = get_machine_after_query().await;
|
||||
|
||||
@@ -1808,7 +1812,7 @@ pub(crate) mod test {
|
||||
assert!(user_sessions.contains_key(&alice_device));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_session_creation() {
|
||||
let (alice_machine, bob_machine, one_time_keys) = get_machine_pair().await;
|
||||
|
||||
@@ -1836,7 +1840,7 @@ pub(crate) mod test {
|
||||
assert!(!session.lock().await.is_empty())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_olm_encryption() {
|
||||
let (alice, bob) = get_machine_pair_with_session().await;
|
||||
|
||||
@@ -1860,7 +1864,7 @@ pub(crate) mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_room_key_sharing() {
|
||||
let (alice, bob) = get_machine_pair_with_session().await;
|
||||
|
||||
@@ -1911,7 +1915,7 @@ pub(crate) mod test {
|
||||
assert!(session.unwrap().is_some());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_megolm_encryption() {
|
||||
let (alice, bob) = get_machine_pair_with_setup_sessions().await;
|
||||
let room_id = room_id!("!test:example.org");
|
||||
@@ -1971,7 +1975,7 @@ pub(crate) mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
#[cfg(feature = "sled_cryptostore")]
|
||||
async fn test_machine_with_default_store() {
|
||||
use tempfile::tempdir;
|
||||
@@ -2009,7 +2013,7 @@ pub(crate) mod test {
|
||||
assert_eq!(ed25519_key, machine.identity_keys().ed25519());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn interactive_verification() {
|
||||
let (alice, bob) = get_machine_pair_with_setup_sessions().await;
|
||||
|
||||
|
||||
@@ -1141,6 +1141,8 @@ impl PartialEq for ReadOnlyAccount {
|
||||
mod test {
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{identifiers::DeviceIdBox, user_id, DeviceKeyId, UserId};
|
||||
|
||||
@@ -1156,7 +1158,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn one_time_key_creation() -> Result<()> {
|
||||
async fn one_time_key_creation() {
|
||||
let account = ReadOnlyAccount::new(&user_id(), &device_id());
|
||||
|
||||
let one_time_keys = account
|
||||
@@ -1194,7 +1196,5 @@ mod test {
|
||||
let fourth_device_key_ids: BTreeSet<&DeviceKeyId> = fourth_one_time_keys.keys().collect();
|
||||
|
||||
assert_ne!(device_key_ids, fourth_device_key_ids);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ mod test {
|
||||
use super::EncryptionSettings;
|
||||
use crate::{MegolmError, ReadOnlyAccount};
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
#[cfg(target_os = "linux")]
|
||||
async fn expiration() -> Result<(), MegolmError> {
|
||||
let settings = EncryptionSettings { rotation_period_msgs: 1, ..Default::default() };
|
||||
|
||||
@@ -59,6 +59,9 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use std::{collections::BTreeMap, convert::TryInto};
|
||||
|
||||
use matches::assert_matches;
|
||||
@@ -129,7 +132,7 @@ pub(crate) mod test {
|
||||
assert!(account.shared());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn one_time_keys_creation() {
|
||||
let account = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let one_time_keys = account.one_time_keys().await;
|
||||
@@ -153,7 +156,7 @@ pub(crate) mod test {
|
||||
assert!(one_time_keys.curve25519().is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn session_creation() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
@@ -194,7 +197,7 @@ pub(crate) mod test {
|
||||
assert_eq!(plaintext, decyrpted);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn group_session_creation() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let room_id = room_id!("!test:localhost");
|
||||
@@ -225,8 +228,8 @@ pub(crate) mod test {
|
||||
assert_eq!(plaintext, inbound.decrypt_helper(ciphertext).await.unwrap().0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn edit_decryption() -> Result<(), MegolmError> {
|
||||
#[async_test]
|
||||
async fn edit_decryption() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let room_id = room_id!("!test:localhost");
|
||||
let event_id = event_id!("$1234adfad:asdf");
|
||||
@@ -250,19 +253,19 @@ pub(crate) mod test {
|
||||
&room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)?;
|
||||
).unwrap();
|
||||
|
||||
assert_eq!(0, inbound.first_known_index());
|
||||
|
||||
assert_eq!(outbound.session_id(), inbound.session_id());
|
||||
|
||||
let encrypted_content =
|
||||
outbound.encrypt(serde_json::to_value(content)?, "m.room.message").await;
|
||||
outbound.encrypt(serde_json::to_value(content).unwrap(), "m.room.message").await;
|
||||
|
||||
let event = json!({
|
||||
"sender": alice.user_id(),
|
||||
"event_id": event_id,
|
||||
"origin_server_ts": 0,
|
||||
"origin_server_ts": 0u64,
|
||||
"room_id": room_id,
|
||||
"type": "m.room.encrypted",
|
||||
"content": encrypted_content,
|
||||
@@ -278,20 +281,18 @@ pub(crate) mod test {
|
||||
panic!("Invalid event type")
|
||||
};
|
||||
|
||||
let decrypted = inbound.decrypt(&event).await?.0;
|
||||
let decrypted = inbound.decrypt(&event).await.unwrap().0;
|
||||
|
||||
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(e)) =
|
||||
decrypted.deserialize()?
|
||||
decrypted.deserialize().unwrap()
|
||||
{
|
||||
assert_matches!(e.content.relates_to, Some(Relation::Replacement(_)));
|
||||
} else {
|
||||
panic!("Invalid event type")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn group_session_export() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
@@ -645,6 +645,8 @@ impl PrivateCrossSigningIdentity {
|
||||
mod test {
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{user_id, UserId};
|
||||
|
||||
|
||||
@@ -583,6 +583,10 @@ mod test {
|
||||
};
|
||||
use serde_json::Value;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
|
||||
use crate::{EncryptionSettings, OlmMachine};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
@@ -622,7 +626,7 @@ mod test {
|
||||
machine
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_sharing() {
|
||||
let machine = machine().await;
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
@@ -337,6 +337,8 @@ mod test {
|
||||
|
||||
use dashmap::DashMap;
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
api::client::r0::keys::claim_keys::Response as KeyClaimResponse, user_id, DeviceIdBox,
|
||||
|
||||
@@ -189,7 +189,11 @@ mod test {
|
||||
store::caches::{DeviceStore, GroupSessionStore, SessionStore},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
|
||||
#[async_test]
|
||||
async fn test_session_store() {
|
||||
let (_, session) = get_account_and_session().await;
|
||||
|
||||
@@ -206,7 +210,7 @@ mod test {
|
||||
assert_eq!(&session, loaded_session);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_session_store_bulk_storing() {
|
||||
let (_, session) = get_account_and_session().await;
|
||||
|
||||
@@ -221,7 +225,7 @@ mod test {
|
||||
assert_eq!(&session, loaded_session);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_group_session_store() {
|
||||
let (account, _) = get_account_and_session().await;
|
||||
let room_id = room_id!("!test:localhost");
|
||||
@@ -250,7 +254,7 @@ mod test {
|
||||
assert_eq!(inbound, loaded_session);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_device_store() {
|
||||
let device = get_device();
|
||||
let store = DeviceStore::new();
|
||||
|
||||
1323
crates/matrix-sdk-crypto/src/store/indexeddb.rs
Normal file
1323
crates/matrix-sdk-crypto/src/store/indexeddb.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -277,13 +277,17 @@ impl CryptoStore for MemoryStore {
|
||||
mod test {
|
||||
use ruma::room_id;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
|
||||
use crate::{
|
||||
identities::device::test::get_device,
|
||||
olm::{test::get_account_and_session, InboundGroupSession, OlmMessageHash},
|
||||
store::{memorystore::MemoryStore, Changes, CryptoStore},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_session_store() {
|
||||
let (account, session) = get_account_and_session().await;
|
||||
let store = MemoryStore::new();
|
||||
@@ -301,7 +305,7 @@ mod test {
|
||||
assert_eq!(&session, loaded_session);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_group_session_store() {
|
||||
let (account, _) = get_account_and_session().await;
|
||||
let room_id = room_id!("!test:localhost");
|
||||
@@ -328,7 +332,7 @@ mod test {
|
||||
assert_eq!(inbound, loaded_session);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_device_store() {
|
||||
let device = get_device();
|
||||
let store = MemoryStore::new();
|
||||
@@ -353,7 +357,7 @@ mod test {
|
||||
assert!(store.get_device(device.user_id(), device.device_id()).await.unwrap().is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_tracked_users() {
|
||||
let device = get_device();
|
||||
let store = MemoryStore::new();
|
||||
@@ -364,7 +368,7 @@ mod test {
|
||||
assert!(store.is_user_tracked(device.user_id()));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn test_message_hash() {
|
||||
let store = MemoryStore::new();
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ mod memorystore;
|
||||
mod pickle_key;
|
||||
#[cfg(feature = "sled_cryptostore")]
|
||||
pub(crate) mod sled;
|
||||
#[cfg(feature = "indexeddb_cryptostore")]
|
||||
pub(crate) mod indexeddb;
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
@@ -67,6 +69,11 @@ use zeroize::Zeroize;
|
||||
|
||||
#[cfg(feature = "sled_cryptostore")]
|
||||
pub use self::sled::SledStore;
|
||||
#[cfg(feature = "indexeddb_cryptostore")]
|
||||
pub use self::indexeddb::IndexeddbStore;
|
||||
#[cfg(feature = "indexeddb_cryptostore")]
|
||||
use indexed_db_futures::web_sys::DomException;
|
||||
|
||||
use crate::{
|
||||
error::SessionUnpicklingError,
|
||||
identities::{
|
||||
@@ -520,6 +527,18 @@ pub enum CryptoStoreError {
|
||||
#[error(transparent)]
|
||||
Database(#[from] sled::Error),
|
||||
|
||||
/// Error in the internal database
|
||||
#[cfg(feature = "indexeddb_cryptostore")]
|
||||
#[error("IndexDB error: {name} ({code}): {message}")]
|
||||
IndexedDatabase {
|
||||
/// DomException code
|
||||
code: u16,
|
||||
/// Specific name of the DomException
|
||||
name: String,
|
||||
/// Message given to the DomException
|
||||
message: String,
|
||||
},
|
||||
|
||||
/// An IO error occurred.
|
||||
#[error(transparent)]
|
||||
Io(#[from] IoError),
|
||||
@@ -553,6 +572,14 @@ pub enum CryptoStoreError {
|
||||
Serialization(#[from] SerdeError),
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "indexeddb_cryptostore")]
|
||||
impl From<DomException> for CryptoStoreError {
|
||||
fn from(frm: DomException) -> CryptoStoreError {
|
||||
CryptoStoreError::IndexedDatabase { name: frm.name(), message: frm.message(), code: frm.code() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait abstracting a store that the `OlmMachine` uses to store cryptographic
|
||||
/// keys.
|
||||
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
|
||||
|
||||
@@ -74,7 +74,7 @@ pub struct EncryptedPickleKey {
|
||||
/// Olm uses AES256 to encrypt accounts, sessions, inbound group sessions. We
|
||||
/// also implement our own pickling for the cross-signing types using
|
||||
/// AES256-GCM so the key sizes match.
|
||||
#[derive(Debug, Zeroize, PartialEq)]
|
||||
#[derive(Debug, Zeroize, Serialize, Deserialize, PartialEq)]
|
||||
pub struct PickleKey {
|
||||
aes256_key: Vec<u8>,
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ pub struct AccountInfo {
|
||||
identity_keys: Arc<IdentityKeys>,
|
||||
}
|
||||
|
||||
/// An in-memory only store that will forget all the E2EE key once it's dropped.
|
||||
/// Storing crypto with sled
|
||||
#[derive(Clone)]
|
||||
pub struct SledStore {
|
||||
account_info: Arc<RwLock<Option<AccountInfo>>>,
|
||||
|
||||
@@ -523,6 +523,10 @@ mod test {
|
||||
};
|
||||
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{DeviceId, UserId};
|
||||
|
||||
use super::{Sas, VerificationMachine};
|
||||
@@ -596,7 +600,7 @@ mod test {
|
||||
let _ = VerificationMachine::new(alice, identity, Arc::new(store));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn full_flow() {
|
||||
let (alice_machine, bob) = setup_verification_machine().await;
|
||||
|
||||
@@ -643,7 +647,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn timing_out() {
|
||||
let (alice_machine, bob) = setup_verification_machine().await;
|
||||
let alice = alice_machine.get_sas(bob.user_id(), bob.flow_id().as_str()).unwrap();
|
||||
|
||||
@@ -667,6 +667,9 @@ impl IdentitiesBeingVerified {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use ruma::{
|
||||
|
||||
@@ -1266,6 +1266,9 @@ struct Done {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
||||
use matrix_sdk_test::async_test;
|
||||
|
||||
@@ -540,7 +540,7 @@ fn bytes_to_decimal(bytes: Vec<u8>) -> (u16, u16, u16) {
|
||||
(first + 1000, second + 1000, third + 1000)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
mod test {
|
||||
use proptest::prelude::*;
|
||||
use ruma::events::key::verification::start::ToDeviceKeyVerificationStartEventContent;
|
||||
|
||||
@@ -556,6 +556,9 @@ impl AcceptSettings {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
|
||||
use ruma::{DeviceId, UserId};
|
||||
|
||||
@@ -586,7 +589,7 @@ mod test {
|
||||
"BOBDEVCIE".into()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_wrapper_full() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
||||
@@ -1137,6 +1137,10 @@ impl SasState<Cancelled> {
|
||||
mod test {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
use matrix_sdk_test::async_test;
|
||||
|
||||
use ruma::{
|
||||
events::key::verification::{
|
||||
accept::{AcceptMethod, ToDeviceKeyVerificationAcceptEventContent},
|
||||
@@ -1195,12 +1199,12 @@ mod test {
|
||||
(alice_sas, bob_sas)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn create_sas() {
|
||||
let (_, _) = get_sas_pair().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_accept() {
|
||||
let (alice, bob) = get_sas_pair().await;
|
||||
let content = bob.as_content();
|
||||
@@ -1209,7 +1213,7 @@ mod test {
|
||||
alice.into_accepted(bob.user_id(), &content).unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_key_share() {
|
||||
let (alice, bob) = get_sas_pair().await;
|
||||
|
||||
@@ -1231,7 +1235,7 @@ mod test {
|
||||
assert_eq!(alice.get_emoji(), bob.get_emoji());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_full() {
|
||||
let (alice, bob) = get_sas_pair().await;
|
||||
|
||||
@@ -1272,7 +1276,7 @@ mod test {
|
||||
assert!(alice.verified_devices().contains(&alice.other_device()));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_invalid_commitment() {
|
||||
let (alice, bob) = get_sas_pair().await;
|
||||
|
||||
@@ -1301,7 +1305,7 @@ mod test {
|
||||
.expect_err("Didn't cancel on invalid commitment");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_invalid_sender() {
|
||||
let (alice, bob) = get_sas_pair().await;
|
||||
|
||||
@@ -1311,7 +1315,7 @@ mod test {
|
||||
alice.into_accepted(&sender, &content).expect_err("Didn't cancel on a invalid sender");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_unknown_sas_method() {
|
||||
let (alice, bob) = get_sas_pair().await;
|
||||
|
||||
@@ -1332,7 +1336,7 @@ mod test {
|
||||
.expect_err("Didn't cancel on an invalid SAS method");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_unknown_method() {
|
||||
let (alice, bob) = get_sas_pair().await;
|
||||
|
||||
@@ -1351,7 +1355,7 @@ mod test {
|
||||
.expect_err("Didn't cancel on an unknown SAS method");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[async_test]
|
||||
async fn sas_from_start_unknown_method() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
||||
Reference in New Issue
Block a user