Merge branch 'up-ruma' into 'master'

Bump ruma

See merge request famedly/conduit!70
next
Timo Kösters 2021-04-28 09:44:04 +00:00
commit d35ad69af1
7 changed files with 85 additions and 99 deletions

36
Cargo.lock generated
View File

@ -1634,7 +1634,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.0.3" version = "0.0.3"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -1654,7 +1654,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.17.0-alpha.4" version = "0.17.0-alpha.4"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"bytes", "bytes",
"http", "http",
@ -1670,7 +1670,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.17.0-alpha.4" version = "0.17.0-alpha.4"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1681,7 +1681,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.2.0-alpha.3" version = "0.2.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1695,7 +1695,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.10.0-alpha.3" version = "0.10.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"assign", "assign",
"bytes", "bytes",
@ -1715,7 +1715,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"js_int", "js_int",
@ -1731,7 +1731,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.22.0-alpha.3" version = "0.22.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -1745,7 +1745,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.22.0-alpha.3" version = "0.22.0-alpha.3"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1756,7 +1756,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.1.0-alpha.2" version = "0.1.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1771,7 +1771,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.19.0" version = "0.19.0"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"paste", "paste",
"rand", "rand",
@ -1785,7 +1785,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.19.0" version = "0.19.0"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1796,12 +1796,12 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1814,7 +1814,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1829,7 +1829,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.3.1" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"bytes", "bytes",
"form_urlencoded", "form_urlencoded",
@ -1843,7 +1843,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde-macros" name = "ruma-serde-macros"
version = "0.3.1" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1854,7 +1854,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/ruma/ruma?rev=12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88#12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88" source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"ring", "ring",
@ -2167,7 +2167,7 @@ dependencies = [
[[package]] [[package]]
name = "state-res" name = "state-res"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/ruma/state-res?rev=1dd252d1c97a38def74bc097c197a33179ed8fbb#1dd252d1c97a38def74bc097c197a33179ed8fbb" source = "git+https://github.com/ruma/state-res?rev=ce665d213fffeaa47e146d01c6b87f9eb9feaa52#ce665d213fffeaa47e146d01c6b87f9eb9feaa52"
dependencies = [ dependencies = [
"itertools 0.10.0", "itertools 0.10.0",
"log", "log",

View File

@ -18,12 +18,12 @@ rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5
#rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } #rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
ruma = { git = "https://github.com/ruma/ruma", rev = "12ec0fb1680ebc4fec4fbefbbd0890ae4eaf3a88", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } ruma = { git = "https://github.com/ruma/ruma", rev = "d27584ae3bdc035529e7389f1c392d4c96f9f8eb", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { git = "https://github.com/timokoesters/ruma", rev = "220d5b4a76b3b781f7f8297fbe6b14473b04214b", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "220d5b4a76b3b781f7f8297fbe6b14473b04214b", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { path = "../ruma/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] }
# Used when doing state resolution # Used when doing state resolution
state-res = { git = "https://github.com/ruma/state-res", rev = "1dd252d1c97a38def74bc097c197a33179ed8fbb", features = ["unstable-pre-spec"] } state-res = { git = "https://github.com/ruma/state-res", rev = "ce665d213fffeaa47e146d01c6b87f9eb9feaa52", features = ["unstable-pre-spec"] }
#state-res = { path = "../state-res", features = ["unstable-pre-spec"] } #state-res = { path = "../state-res", features = ["unstable-pre-spec"] }
# Used for long polling and federation sender, should be the same as rocket::tokio # Used for long polling and federation sender, should be the same as rocket::tokio

View File

@ -24,7 +24,7 @@ use ruma::{
room::{create::CreateEventContent, member}, room::{create::CreateEventContent, member},
EventType, EventType,
}, },
serde::{to_canonical_value, CanonicalJsonObject, Raw}, serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw},
uint, EventId, RoomId, RoomVersionId, ServerName, UserId, uint, EventId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use state_res::EventMap; use state_res::EventMap;
@ -481,13 +481,15 @@ async fn join_room_by_id_helper(
// TODO: Is origin needed? // TODO: Is origin needed?
join_event_stub.insert( join_event_stub.insert(
"origin".to_owned(), "origin".to_owned(),
to_canonical_value(db.globals.server_name()) CanonicalJsonValue::String(db.globals.server_name().as_str().to_owned()),
.map_err(|_| Error::bad_database("Invalid server name found"))?,
); );
join_event_stub.insert( join_event_stub.insert(
"origin_server_ts".to_owned(), "origin_server_ts".to_owned(),
to_canonical_value(utils::millis_since_unix_epoch()) CanonicalJsonValue::Integer(
.expect("Timestamp is valid js_int value"), utils::millis_since_unix_epoch()
.try_into()
.expect("Timestamp is valid js_int value"),
),
); );
join_event_stub.insert( join_event_stub.insert(
"content".to_owned(), "content".to_owned(),
@ -524,7 +526,7 @@ async fn join_room_by_id_helper(
// Add event_id back // Add event_id back
join_event_stub.insert( join_event_stub.insert(
"event_id".to_owned(), "event_id".to_owned(),
to_canonical_value(&event_id).expect("EventId is a valid CanonicalJsonValue"), CanonicalJsonValue::String(event_id.as_str().to_owned()),
); );
// It has enough fields to be called a proper event now // It has enough fields to be called a proper event now
@ -717,8 +719,7 @@ async fn validate_and_add_event_id(
value.insert( value.insert(
"event_id".to_owned(), "event_id".to_owned(),
to_canonical_value(&event_id) CanonicalJsonValue::String(event_id.as_str().to_owned()),
.expect("a valid EventId can be converted to CanonicalJsonValue"),
); );
Ok((event_id, value)) Ok((event_id, value))

View File

@ -15,7 +15,7 @@ use ruma::{
AnyStrippedStateEvent, AnySyncStateEvent, EventType, AnyStrippedStateEvent, AnySyncStateEvent, EventType,
}, },
push::{self, Action, Tweak}, push::{self, Action, Tweak},
serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw}, serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
uint, EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, uint, EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use sled::IVec; use sled::IVec;
@ -372,9 +372,7 @@ impl Rooms {
for event_id in new_state.difference(&old_state) { for event_id in new_state.difference(&old_state) {
if let Some(pdu) = self.get_pdu_json(event_id)? { if let Some(pdu) = self.get_pdu_json(event_id)? {
if pdu.get("event_type") if pdu.get("event_type").and_then(|val| val.as_str()) == Some("m.room.member") {
== Some(&CanonicalJsonValue::String("m.room.member".to_owned()))
{
if let Ok(pdu) = serde_json::from_value::<PduEvent>( if let Ok(pdu) = serde_json::from_value::<PduEvent>(
serde_json::to_value(&pdu).expect("CanonicalJsonObj is a valid JsonValue"), serde_json::to_value(&pdu).expect("CanonicalJsonObj is a valid JsonValue"),
) { ) {
@ -1321,8 +1319,7 @@ impl Rooms {
// Add origin because synapse likes that (and it's required in the spec) // Add origin because synapse likes that (and it's required in the spec)
pdu_json.insert( pdu_json.insert(
"origin".to_owned(), "origin".to_owned(),
to_canonical_value(db.globals.server_name()) CanonicalJsonValue::String(db.globals.server_name().as_ref().to_owned()),
.expect("server name is a valid CanonicalJsonValue"),
); );
ruma::signatures::hash_and_sign_event( ruma::signatures::hash_and_sign_event(
@ -1343,7 +1340,7 @@ impl Rooms {
pdu_json.insert( pdu_json.insert(
"event_id".to_owned(), "event_id".to_owned(),
to_canonical_value(&pdu.event_id).expect("EventId is a valid CanonicalJsonValue"), CanonicalJsonValue::String(pdu.event_id.as_str().to_owned()),
); );
// Increment the last index and use that // Increment the last index and use that
@ -1885,13 +1882,15 @@ impl Rooms {
// TODO: Is origin needed? // TODO: Is origin needed?
leave_event_stub.insert( leave_event_stub.insert(
"origin".to_owned(), "origin".to_owned(),
to_canonical_value(db.globals.server_name()) CanonicalJsonValue::String(db.globals.server_name().as_str().to_owned()),
.map_err(|_| Error::bad_database("Invalid server name found"))?,
); );
leave_event_stub.insert( leave_event_stub.insert(
"origin_server_ts".to_owned(), "origin_server_ts".to_owned(),
to_canonical_value(utils::millis_since_unix_epoch()) CanonicalJsonValue::Integer(
.expect("Timestamp is valid js_int value"), utils::millis_since_unix_epoch()
.try_into()
.expect("Timestamp is valid js_int value"),
),
); );
// We don't leave the event id in the pdu because that's only allowed in v1 or v2 rooms // We don't leave the event id in the pdu because that's only allowed in v1 or v2 rooms
leave_event_stub.remove("event_id"); leave_event_stub.remove("event_id");
@ -1916,7 +1915,7 @@ impl Rooms {
// Add event_id back // Add event_id back
leave_event_stub.insert( leave_event_stub.insert(
"event_id".to_owned(), "event_id".to_owned(),
to_canonical_value(&event_id).expect("EventId is a valid CanonicalJsonValue"), CanonicalJsonValue::String(event_id.as_str().to_owned()),
); );
// It has enough fields to be called a proper event now // It has enough fields to be called a proper event now

View File

@ -31,7 +31,7 @@ use tracing::span;
use tracing_subscriber::{prelude::*, Registry}; use tracing_subscriber::{prelude::*, Registry};
fn setup_rocket(config: Figment, data: Database) -> rocket::Rocket<rocket::Build> { fn setup_rocket(config: Figment, data: Database) -> rocket::Rocket<rocket::Build> {
let rocket = rocket::custom(config) rocket::custom(config)
.manage(data) .manage(data)
.mount( .mount(
"/", "/",
@ -167,9 +167,7 @@ fn setup_rocket(config: Figment, data: Database) -> rocket::Rocket<rocket::Build
missing_token_catcher, missing_token_catcher,
bad_json_catcher bad_json_catcher
], ],
); )
rocket
} }
#[rocket::main] #[rocket::main]

View File

@ -5,7 +5,7 @@ use ruma::{
pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent, pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent,
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
}, },
serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw}, serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -238,7 +238,7 @@ impl PduEvent {
) -> Result<Self, serde_json::Error> { ) -> Result<Self, serde_json::Error> {
json.insert( json.insert(
"event_id".to_string(), "event_id".to_string(),
to_canonical_value(event_id).expect("event_id is a valid Value"), CanonicalJsonValue::String(event_id.as_str().to_owned()),
); );
serde_json::from_value(serde_json::to_value(json).expect("valid JSON")) serde_json::from_value(serde_json::to_value(json).expect("valid JSON"))

View File

@ -33,7 +33,7 @@ use ruma::{
}, },
EventType, EventType,
}, },
serde::{to_canonical_value, Raw}, serde::Raw,
signatures::{CanonicalJsonObject, CanonicalJsonValue}, signatures::{CanonicalJsonObject, CanonicalJsonValue},
uint, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId, uint, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
}; };
@ -709,11 +709,7 @@ pub fn handle_incoming_pdu<'a>(
// 1. Check the server is in the room // 1. Check the server is in the room
let room_id = match value let room_id = match value
.get("room_id") .get("room_id")
.map(|id| match id { .and_then(|id| RoomId::try_from(id.as_str()?).ok())
CanonicalJsonValue::String(id) => RoomId::try_from(id.as_str()).ok(),
_ => None,
})
.flatten()
{ {
Some(id) => id, Some(id) => id,
None => { None => {
@ -776,7 +772,7 @@ pub fn handle_incoming_pdu<'a>(
// to our PduEvent type // to our PduEvent type
val.insert( val.insert(
"event_id".to_owned(), "event_id".to_owned(),
to_canonical_value(&event_id).expect("EventId is a valid CanonicalJsonValue"), CanonicalJsonValue::String(event_id.as_str().to_owned()),
); );
let incoming_pdu = serde_json::from_value::<PduEvent>( let incoming_pdu = serde_json::from_value::<PduEvent>(
serde_json::to_value(&val).expect("CanonicalJsonObj is a valid JsonValue"), serde_json::to_value(&val).expect("CanonicalJsonObj is a valid JsonValue"),
@ -1306,8 +1302,7 @@ pub(crate) fn fetch_and_handle_events<'a>(
Ok(_) => { Ok(_) => {
value.insert( value.insert(
"event_id".to_owned(), "event_id".to_owned(),
to_canonical_value(&event_id) CanonicalJsonValue::String(event_id.into()),
.expect("EventId is a valid CanonicalJsonValue"),
); );
Arc::new(serde_json::from_value( Arc::new(serde_json::from_value(
@ -1805,8 +1800,7 @@ pub fn create_join_event_template_route<'a>(
// Add origin because synapse likes that (and it's required in the spec) // Add origin because synapse likes that (and it's required in the spec)
pdu_json.insert( pdu_json.insert(
"origin".to_owned(), "origin".to_owned(),
to_canonical_value(db.globals.server_name()) CanonicalJsonValue::String(db.globals.server_name().as_str().to_owned()),
.expect("server name is a valid CanonicalJsonValue"),
); );
Ok(create_join_event_template::v1::Response { Ok(create_join_event_template::v1::Response {
@ -1979,33 +1973,30 @@ pub async fn create_invite_route<'a>(
// Add event_id back // Add event_id back
signed_event.insert( signed_event.insert(
"event_id".to_owned(), "event_id".to_owned(),
to_canonical_value(&event_id).expect("EventId is a valid CanonicalJsonValue"), CanonicalJsonValue::String(event_id.into()),
); );
let sender = serde_json::from_value( let sender = serde_json::from_value(
serde_json::to_value( signed_event
signed_event .get("sender")
.get("sender") .ok_or(Error::BadRequest(
.ok_or(Error::BadRequest( ErrorKind::InvalidParam,
ErrorKind::InvalidParam, "Event had no sender field.",
"Event had no sender field.", ))?
))? .clone()
.clone(), .into(),
)
.expect("CanonicalJsonValue to serde_json::Value always works"),
) )
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "sender is not a user id."))?; .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "sender is not a user id."))?;
let invited_user = serde_json::from_value( let invited_user = serde_json::from_value(
serde_json::to_value( signed_event
signed_event .get("state_key")
.get("state_key") .ok_or(Error::BadRequest(
.ok_or(Error::BadRequest( ErrorKind::InvalidParam,
ErrorKind::InvalidParam, "Event had no state_key field.",
"Event had no state_key field.", ))?
))? .clone()
.clone(), .into(),
)
.expect("CanonicalJsonValue to serde_json::Value always works"),
) )
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "state_key is not a user id."))?; .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "state_key is not a user id."))?;
@ -2150,39 +2141,36 @@ pub async fn fetch_required_signing_keys(
pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, String>>>, pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, String>>>,
db: &Database, db: &Database,
) -> Result<()> { ) -> Result<()> {
let signatures = event
.get("signatures")
.ok_or(Error::BadServerResponse(
"No signatures in server response pdu.",
))?
.as_object()
.ok_or(Error::BadServerResponse(
"Invalid signatures object in server response pdu.",
))?;
// We go through all the signatures we see on the value and fetch the corresponding signing // We go through all the signatures we see on the value and fetch the corresponding signing
// keys // keys
for (signature_server, signature) in match event.get("signatures").ok_or( for (signature_server, signature) in signatures {
Error::BadServerResponse("No signatures in server response pdu."), let signature_object = signature.as_object().ok_or(Error::BadServerResponse(
)? { "Invalid signatures content object in server response pdu.",
CanonicalJsonValue::Object(map) => map, ))?;
_ => {
return Err(Error::BadServerResponse(
"Invalid signatures object in server response pdu.",
))
}
} {
let signature_object = match signature {
CanonicalJsonValue::Object(map) => map,
_ => {
return Err(Error::BadServerResponse(
"Invalid signatures content object in server response pdu.",
))
}
};
let signature_ids = signature_object.keys().collect::<Vec<_>>(); let signature_ids = signature_object.keys().collect::<Vec<_>>();
debug!("Fetching signing keys for {}", signature_server); debug!("Fetching signing keys for {}", signature_server);
let keys = match fetch_signing_keys( let fetch_res = fetch_signing_keys(
db, db,
&Box::<ServerName>::try_from(&**signature_server).map_err(|_| { &Box::<ServerName>::try_from(&**signature_server).map_err(|_| {
Error::BadServerResponse("Invalid servername in signatures of server response pdu.") Error::BadServerResponse("Invalid servername in signatures of server response pdu.")
})?, })?,
signature_ids, signature_ids,
) )
.await .await;
{
let keys = match fetch_res {
Ok(keys) => keys, Ok(keys) => keys,
Err(_) => { Err(_) => {
warn!("Signature verification failed: Could not fetch signing key.",); warn!("Signature verification failed: Could not fetch signing key.",);