diff --git a/src/client_server.rs b/src/client_server.rs index 01ec7a36..3620a00b 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -56,7 +56,7 @@ use ruma::{ room::{canonical_alias, guest_access, history_visibility, join_rules, member, redaction}, EventJson, EventType, }, - identifiers::{DeviceId, RoomAliasId, RoomId, RoomVersionId, UserId}, + identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId}, }; use serde_json::{json, value::RawValue}; @@ -2841,13 +2841,15 @@ pub fn get_devices_route( MatrixResult(Ok(get_devices::Response { devices })) } -#[get("/_matrix/client/r0/devices/", data = "")] +#[get("/_matrix/client/r0/devices/<_device_id>", data = "")] pub fn get_device_route( db: State<'_, Database>, body: Ruma, - device_id: DeviceId, + _device_id: String, ) -> MatrixResult { let user_id = body.user_id.as_ref().expect("user is authenticated"); + let device_id = body.device_id.as_ref().expect("user is authenticated"); + let device = db.users.get_device_metadata(&user_id, &device_id).unwrap(); match device { @@ -2860,13 +2862,15 @@ pub fn get_device_route( } } -#[put("/_matrix/client/r0/devices/", data = "")] +#[put("/_matrix/client/r0/devices/<_device_id>", data = "")] pub fn update_device_route( db: State<'_, Database>, body: Ruma, - device_id: DeviceId, + _device_id: String, ) -> MatrixResult { let user_id = body.user_id.as_ref().expect("user is authenticated"); + let device_id = body.device_id.as_ref().expect("user is authenticated"); + let device = db.users.get_device_metadata(&user_id, &device_id).unwrap(); match device { @@ -2887,13 +2891,14 @@ pub fn update_device_route( } } -#[delete("/_matrix/client/r0/devices/", data = "")] +#[delete("/_matrix/client/r0/devices/<_device_id>", data = "")] pub fn delete_device_route( db: State<'_, Database>, body: Ruma, - device_id: DeviceId, + _device_id: String, ) -> MatrixResult { let user_id = body.user_id.as_ref().expect("user is authenticated"); + let device_id = body.device_id.as_ref().expect("user is authenticated"); // UIAA let uiaainfo = UiaaInfo { diff --git a/src/database/uiaa.rs b/src/database/uiaa.rs index f1de4766..6cd25b99 100644 --- a/src/database/uiaa.rs +++ b/src/database/uiaa.rs @@ -11,7 +11,7 @@ use ruma::{ }, }, events::{to_device::AnyToDeviceEvent, EventJson, EventType}, - identifiers::{DeviceId, UserId}, + identifiers::UserId, }; use serde_json::value::RawValue; use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime}; @@ -29,7 +29,7 @@ impl Uiaa { pub fn try_auth( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, auth: &AuthData, uiaainfo: &UiaaInfo, users: &super::users::Users, diff --git a/src/database/users.rs b/src/database/users.rs index 8893b102..5c474556 100644 --- a/src/database/users.rs +++ b/src/database/users.rs @@ -6,7 +6,7 @@ use ruma::{ keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey}, }, events::{to_device::AnyToDeviceEvent, EventJson, EventType}, - identifiers::{DeviceId, UserId}, + identifiers::UserId, }; use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime}; @@ -113,7 +113,7 @@ impl Users { pub fn create_device( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, token: &str, initial_device_display_name: Option, ) -> Result<()> { @@ -130,7 +130,7 @@ impl Users { self.userdeviceid_metadata.insert( userdeviceid, serde_json::to_string(&Device { - device_id: device_id.clone(), + device_id: device_id.to_owned(), display_name: initial_device_display_name, last_seen_ip: None, // TODO last_seen_ts: Some(SystemTime::now()), @@ -144,7 +144,7 @@ impl Users { } /// Removes a device from a user. - pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { + pub fn remove_device(&self, user_id: &UserId, device_id: &str) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); userdeviceid.extend_from_slice(device_id.as_bytes()); @@ -173,7 +173,7 @@ impl Users { } /// Returns an iterator over all device ids of this user. - pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator> { + pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator> { let mut prefix = user_id.to_string().as_bytes().to_vec(); prefix.push(0xff); // All devices have metadata @@ -191,7 +191,7 @@ impl Users { } /// Replaces the access token of one device. - pub fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> { + pub fn set_token(&self, user_id: &UserId, device_id: &str, token: &str) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); userdeviceid.extend_from_slice(device_id.as_bytes()); @@ -219,7 +219,7 @@ impl Users { pub fn add_one_time_key( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, one_time_key_key: &AlgorithmAndDeviceId, one_time_key_value: &OneTimeKey, ) -> Result<()> { @@ -248,7 +248,7 @@ impl Users { pub fn take_one_time_key( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, key_algorithm: &KeyAlgorithm, ) -> Result> { let mut prefix = user_id.to_string().as_bytes().to_vec(); @@ -282,7 +282,7 @@ impl Users { pub fn count_one_time_keys( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, ) -> Result> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); @@ -315,7 +315,7 @@ impl Users { pub fn add_device_keys( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, device_keys: &DeviceKeys, globals: &super::globals::Globals, ) -> Result<()> { @@ -335,7 +335,7 @@ impl Users { pub fn get_device_keys( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, ) -> impl Iterator> { let mut key = user_id.to_string().as_bytes().to_vec(); key.push(0xff); @@ -376,7 +376,7 @@ impl Users { &self, sender: &UserId, target_user_id: &UserId, - target_device_id: &DeviceId, + target_device_id: &str, event_type: &EventType, content: serde_json::Value, globals: &super::globals::Globals, @@ -401,7 +401,7 @@ impl Users { pub fn take_to_device_events( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, max: usize, ) -> Result>> { let mut events = Vec::new(); @@ -423,7 +423,7 @@ impl Users { pub fn update_device_metadata( &self, user_id: &UserId, - device_id: &DeviceId, + device_id: &str, device: &Device, ) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); @@ -441,11 +441,7 @@ impl Users { } /// Get device metadata. - pub fn get_device_metadata( - &self, - user_id: &UserId, - device_id: &DeviceId, - ) -> Result> { + pub fn get_device_metadata(&self, user_id: &UserId, device_id: &str) -> Result> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); userdeviceid.extend_from_slice(device_id.as_bytes()); diff --git a/sytest/sytest-whitelist b/sytest/sytest-whitelist index bf9059c7..a13d30fb 100644 --- a/sytest/sytest-whitelist +++ b/sytest/sytest-whitelist @@ -43,7 +43,6 @@ GET /profile/:user_id/displayname publicly accessible GET /device/{deviceId} gives a 404 for unknown devices PUT /device/{deviceId} gives a 404 for unknown devices After deactivating account, can't log in with an email -Can create filter Should reject keys claiming to belong to a different user Can add account data Checking local federation server