|
|
|
@ -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( |
|
|
|
)? { |
|
|
|
|
|
|
|
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.", |
|
|
|
"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.",); |
|
|
|
|