diff options
author | Timo Kösters <timo@koesters.xyz> | 2023-08-07 16:11:11 +0000 |
---|---|---|
committer | Timo Kösters <timo@koesters.xyz> | 2023-08-07 16:11:11 +0000 |
commit | 3e518773e20849bb712c7942fcc2d0a5147f7868 (patch) | |
tree | a03cf969c97996ba985add37c40a0e863bb643c1 | |
parent | 888f7e44035d88f4b07d52092cf9b93eb90b5b08 (diff) | |
parent | d82c26f0a9a92d0193924ddc3d81b7b0a152862b (diff) | |
download | conduit-3e518773e20849bb712c7942fcc2d0a5147f7868.zip |
Merge branch 'improvements' into 'next'
cross signing fixes
See merge request famedly/conduit!532
-rw-r--r-- | Cargo.lock | 29 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/api/client_server/keys.rs | 5 | ||||
-rw-r--r-- | src/api/client_server/sync.rs | 89 | ||||
-rw-r--r-- | src/api/server_server.rs | 3 | ||||
-rw-r--r-- | src/database/key_value/users.rs | 5 | ||||
-rw-r--r-- | src/service/rooms/state_accessor/mod.rs | 12 | ||||
-rw-r--r-- | src/service/rooms/state_cache/mod.rs | 17 | ||||
-rw-r--r-- | src/service/users/data.rs | 1 | ||||
-rw-r--r-- | src/service/users/mod.rs | 16 |
10 files changed, 115 insertions, 64 deletions
@@ -1296,7 +1296,6 @@ checksum = "1d9a8bb6c7c71d151b25936b03e012a4c00daea99e3a3797c6ead66b0a0d55e2" dependencies = [ "const_panic", "konst_kernel", - "konst_proc_macros", "typewit", ] @@ -1310,12 +1309,6 @@ dependencies = [ ] [[package]] -name = "konst_proc_macros" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e28ab1dc35e09d60c2b8c90d12a9a8d9666c876c10a3739a3196db0103b6043" - -[[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2146,7 +2139,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.8.2" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "assign", "js_int", @@ -2164,7 +2157,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.8.1" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "js_int", "ruma-common", @@ -2175,7 +2168,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.16.2" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "assign", "bytes", @@ -2192,7 +2185,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.11.3" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "base64 0.21.2", "bytes", @@ -2220,7 +2213,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.7.1" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "js_int", "ruma-common", @@ -2231,7 +2224,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.1" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "js_int", "thiserror", @@ -2240,7 +2233,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.7.1" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "js_int", "ruma-common", @@ -2250,7 +2243,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.11.3" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "once_cell", "proc-macro-crate", @@ -2265,7 +2258,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.7.1" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "js_int", "ruma-common", @@ -2276,7 +2269,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.13.1" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "base64 0.21.2", "ed25519-dalek", @@ -2292,7 +2285,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.9.1" -source = "git+https://github.com/ruma/ruma?rev=07bc06038fded40d4e9180637f056d256f9a1fbc#07bc06038fded40d4e9180637f056d256f9a1fbc" +source = "git+https://github.com/ruma/ruma?rev=3bd58e3c899457c2d55c45268dcb8a65ae682d54#3bd58e3c899457c2d55c45268dcb8a65ae682d54" dependencies = [ "itertools", "js_int", @@ -26,7 +26,7 @@ tower-http = { version = "0.4.1", features = ["add-extension", "cors", "sensitiv # Used for matrix spec type definitions and helpers #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } -ruma = { git = "https://github.com/ruma/ruma", rev = "07bc06038fded40d4e9180637f056d256f9a1fbc", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } +ruma = { git = "https://github.com/ruma/ruma", rev = "3bd58e3c899457c2d55c45268dcb8a65ae682d54", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "4ec9c69bb7e09391add2382b3ebac97b6e8f4c64", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-msc3575", "unstable-exhaustive-types", "ring-compat", "unstable-unspecified" ] } diff --git a/src/api/client_server/keys.rs b/src/api/client_server/keys.rs index 3e03221..b847301 100644 --- a/src/api/client_server/keys.rs +++ b/src/api/client_server/keys.rs @@ -132,6 +132,7 @@ pub async fn upload_signing_keys_route( master_key, &body.self_signing_key, &body.user_signing_key, + true, // notify so that other users see the new keys )?; } @@ -375,6 +376,10 @@ pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>( } let json = serde_json::to_value(master_key).expect("to_value always works"); let raw = serde_json::from_value(json).expect("Raw::from_value always works"); + services().users.add_cross_signing_keys( + &user, &raw, &None, &None, + false, // Dont notify. A notification would trigger another key request resulting in an endless loop + )?; master_keys.insert(user, raw); } diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 7c6002e..a0edc43 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -20,9 +20,8 @@ use ruma::{ StateEventType, TimelineEventType, }, serde::Raw, - uint, DeviceId, OwnedDeviceId, OwnedEventId, OwnedUserId, RoomId, UInt, UserId, + uint, DeviceId, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId, }; -use serde::Deserialize; use std::{ collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet}, sync::Arc, @@ -1559,6 +1558,56 @@ pub async fn sync_events_v4_route( .map(|state| state.to_sync_state_event()) .collect(); + // Heroes + let heroes = services() + .rooms + .state_cache + .room_members(&room_id) + .filter_map(|r| r.ok()) + .filter(|member| member != &sender_user) + .map(|member| { + Ok::<_, Error>( + services() + .rooms + .state_accessor + .get_member(&room_id, &member)? + .map(|memberevent| { + ( + memberevent + .displayname + .unwrap_or_else(|| member.to_string()), + memberevent.avatar_url, + ) + }), + ) + }) + .filter_map(|r| r.ok()) + .filter_map(|o| o) + .take(5) + .collect::<Vec<_>>(); + let name = if heroes.len() > 1 { + let last = heroes[0].0.clone(); + Some( + heroes[1..] + .iter() + .map(|h| h.0.clone()) + .collect::<Vec<_>>() + .join(", ") + + " and " + + &last, + ) + } else if heroes.len() == 1 { + Some(heroes[0].0.clone()) + } else { + None + }; + + let avatar = if heroes.len() == 1 { + heroes[0].1.clone() + } else { + None + }; + rooms.insert( room_id.clone(), sync_events::v4::SlidingSyncRoom { @@ -1566,36 +1615,12 @@ pub async fn sync_events_v4_route( .rooms .state_accessor .get_name(&room_id)? - .or_else(|| { - // Heroes - let mut names = services() - .rooms - .state_cache - .room_members(&room_id) - .filter_map(|r| r.ok()) - .filter(|member| member != &sender_user) - .map(|member| { - Ok::<_, Error>( - services() - .rooms - .state_accessor - .get_member(&room_id, &member)? - .and_then(|memberevent| memberevent.displayname) - .unwrap_or(member.to_string()), - ) - }) - .filter_map(|r| r.ok()) - .take(5) - .collect::<Vec<_>>(); - if names.len() > 1 { - let last = names.pop().unwrap(); - Some(names.join(", ") + " and " + &last) - } else if names.len() == 1 { - Some(names.pop().unwrap()) - } else { - None - } - }), + .or_else(|| name), + avatar: services() + .rooms + .state_accessor + .get_avatar(&room_id)? + .map_or(avatar, |a| a.url), initial: Some(!known), is_dm: None, invite_state: None, diff --git a/src/api/server_server.rs b/src/api/server_server.rs index e04d63d..bb92405 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -55,7 +55,7 @@ use std::{ time::{Duration, Instant, SystemTime}, }; -use tracing::{debug, error, info, warn}; +use tracing::{debug, error, warn}; /// Wraps either an literal IP address plus port, or a hostname plus complement /// (colon-plus-port if it was specified). @@ -917,6 +917,7 @@ pub async fn send_transaction_message_route( &master_key, &self_signing_key, &None, + true, )?; } } diff --git a/src/database/key_value/users.rs b/src/database/key_value/users.rs index 0301cda..2b09d68 100644 --- a/src/database/key_value/users.rs +++ b/src/database/key_value/users.rs @@ -449,6 +449,7 @@ impl service::users::Data for KeyValueDatabase { master_key: &Raw<CrossSigningKey>, self_signing_key: &Option<Raw<CrossSigningKey>>, user_signing_key: &Option<Raw<CrossSigningKey>>, + notify: bool, ) -> Result<()> { // TODO: Check signatures let mut prefix = user_id.as_bytes().to_vec(); @@ -530,7 +531,9 @@ impl service::users::Data for KeyValueDatabase { .insert(user_id.as_bytes(), &user_signing_key_key)?; } - self.mark_device_key_update(user_id)?; + if notify { + self.mark_device_key_update(user_id)?; + } Ok(()) } diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index 435f4df..a4a62fe 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -9,6 +9,7 @@ use lru_cache::LruCache; use ruma::{ events::{ room::{ + avatar::RoomAvatarEventContent, history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, member::{MembershipState, RoomMemberEventContent}, name::RoomNameEventContent, @@ -283,6 +284,17 @@ impl Service { }) } + pub fn get_avatar(&self, room_id: &RoomId) -> Result<Option<RoomAvatarEventContent>> { + services() + .rooms + .state_accessor + .room_state_get(&room_id, &StateEventType::RoomAvatar, "")? + .map_or(Ok(None), |s| { + serde_json::from_str(s.content.get()) + .map_err(|_| Error::bad_database("Invalid room avatar event in database.")) + }) + } + pub fn get_member( &self, room_id: &RoomId, diff --git a/src/service/rooms/state_cache/mod.rs b/src/service/rooms/state_cache/mod.rs index 32afdd4..ef1ad61 100644 --- a/src/service/rooms/state_cache/mod.rs +++ b/src/service/rooms/state_cache/mod.rs @@ -14,6 +14,7 @@ use ruma::{ serde::Raw, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; +use tracing::warn; use crate::{services, Error, Result}; @@ -88,8 +89,9 @@ impl Service { RoomAccountDataEventType::Tag, )? .map(|event| { - serde_json::from_str(event.get()).map_err(|_| { - Error::bad_database("Invalid account data event in db.") + serde_json::from_str(event.get()).map_err(|e| { + warn!("Invalid account data event in db: {e:?}"); + Error::BadDatabase("Invalid account data event in db.") }) }) { @@ -113,8 +115,9 @@ impl Service { GlobalAccountDataEventType::Direct.to_string().into(), )? .map(|event| { - serde_json::from_str::<DirectEvent>(event.get()).map_err(|_| { - Error::bad_database("Invalid account data event in db.") + serde_json::from_str::<DirectEvent>(event.get()).map_err(|e| { + warn!("Invalid account data event in db: {e:?}"); + Error::BadDatabase("Invalid account data event in db.") }) }) { @@ -155,8 +158,10 @@ impl Service { .into(), )? .map(|event| { - serde_json::from_str::<IgnoredUserListEvent>(event.get()) - .map_err(|_| Error::bad_database("Invalid account data event in db.")) + serde_json::from_str::<IgnoredUserListEvent>(event.get()).map_err(|e| { + warn!("Invalid account data event in db: {e:?}"); + Error::BadDatabase("Invalid account data event in db.") + }) }) .transpose()? .map_or(false, |ignored| { diff --git a/src/service/users/data.rs b/src/service/users/data.rs index d01e070..ddf941e 100644 --- a/src/service/users/data.rs +++ b/src/service/users/data.rs @@ -111,6 +111,7 @@ pub trait Data: Send + Sync { master_key: &Raw<CrossSigningKey>, self_signing_key: &Option<Raw<CrossSigningKey>>, user_signing_key: &Option<Raw<CrossSigningKey>>, + notify: bool, ) -> Result<()>; fn sign_key( diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 38aca80..c345e56 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -66,7 +66,7 @@ impl Service { return BTreeMap::new(); }; - let cache = &mut self.connections.lock().unwrap(); + let mut cache = self.connections.lock().unwrap(); let cached = Arc::clone( cache .entry((user_id, device_id, conn_id)) @@ -185,7 +185,7 @@ impl Service { conn_id: String, subscriptions: BTreeMap<OwnedRoomId, sync_events::v4::RoomSubscription>, ) { - let cache = &mut self.connections.lock().unwrap(); + let mut cache = self.connections.lock().unwrap(); let cached = Arc::clone( cache .entry((user_id, device_id, conn_id)) @@ -212,7 +212,7 @@ impl Service { list_id: String, new_cached_rooms: BTreeMap<OwnedRoomId, bool>, ) { - let cache = &mut self.connections.lock().unwrap(); + let mut cache = self.connections.lock().unwrap(); let cached = Arc::clone( cache .entry((user_id, device_id, conn_id)) @@ -398,9 +398,15 @@ impl Service { master_key: &Raw<CrossSigningKey>, self_signing_key: &Option<Raw<CrossSigningKey>>, user_signing_key: &Option<Raw<CrossSigningKey>>, + notify: bool, ) -> Result<()> { - self.db - .add_cross_signing_keys(user_id, master_key, self_signing_key, user_signing_key) + self.db.add_cross_signing_keys( + user_id, + master_key, + self_signing_key, + user_signing_key, + notify, + ) } pub fn sign_key( |