mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-26 08:34:20 +01:00
fix(membership): fallback to locally signed event if the join wasn't a restricted one on send_join response
This commit is contained in:
parent
47aadcea1d
commit
ec8dfc283c
1 changed files with 22 additions and 31 deletions
|
@ -981,6 +981,8 @@ async fn join_room_by_id_helper(
|
||||||
.as_str()
|
.as_str()
|
||||||
})
|
})
|
||||||
.and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok());
|
.and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok());
|
||||||
|
let restricted_join = join_authorized_via_users_server.is_some();
|
||||||
|
|
||||||
// TODO: Is origin needed?
|
// TODO: Is origin needed?
|
||||||
join_event_stub.insert(
|
join_event_stub.insert(
|
||||||
"origin".to_owned(),
|
"origin".to_owned(),
|
||||||
|
@ -1027,7 +1029,7 @@ async fn join_room_by_id_helper(
|
||||||
ruma::signatures::reference_hash(&join_event_stub, &room_version_id)
|
ruma::signatures::reference_hash(&join_event_stub, &room_version_id)
|
||||||
.expect("ruma can calculate reference hashes")
|
.expect("ruma can calculate reference hashes")
|
||||||
);
|
);
|
||||||
let event_id = <&EventId>::try_from(event_id.as_str())
|
let event_id = OwnedEventId::try_from(event_id)
|
||||||
.expect("ruma's reference hashes are valid event ids");
|
.expect("ruma's reference hashes are valid event ids");
|
||||||
|
|
||||||
// Add event_id back
|
// Add event_id back
|
||||||
|
@ -1052,43 +1054,32 @@ async fn join_room_by_id_helper(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(signed_raw) = send_join_response.room_state.event {
|
let pdu = if let Some(signed_raw) = send_join_response.room_state.event {
|
||||||
let (signed_event_id, signed_value) =
|
let (signed_event_id, signed_pdu) =
|
||||||
match gen_event_id_canonical_json(&signed_raw, &room_version_id) {
|
gen_event_id_canonical_json(&signed_raw, &room_version_id)?;
|
||||||
Ok(t) => t,
|
|
||||||
Err(_) => {
|
|
||||||
// Event could not be converted to canonical json
|
|
||||||
return Err(Error::BadRequest(
|
|
||||||
ErrorKind::InvalidParam,
|
|
||||||
"Could not convert event to canonical json.",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if signed_event_id != event_id {
|
if signed_event_id != event_id {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadServerResponse(
|
||||||
ErrorKind::InvalidParam,
|
|
||||||
"Server sent event with wrong event id",
|
"Server sent event with wrong event id",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(state_lock);
|
signed_pdu
|
||||||
let pub_key_map = RwLock::new(BTreeMap::new());
|
} else if restricted_join {
|
||||||
services()
|
return Err(Error::BadServerResponse(
|
||||||
.rooms
|
"No signed event was returned, despite just performing a restricted join",
|
||||||
.event_handler
|
));
|
||||||
.handle_incoming_pdu(
|
|
||||||
&remote_server,
|
|
||||||
&signed_event_id,
|
|
||||||
room_id,
|
|
||||||
signed_value,
|
|
||||||
true,
|
|
||||||
&pub_key_map,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
} else {
|
||||||
return Err(error);
|
join_event
|
||||||
}
|
};
|
||||||
|
|
||||||
|
drop(state_lock);
|
||||||
|
let pub_key_map = RwLock::new(BTreeMap::new());
|
||||||
|
services()
|
||||||
|
.rooms
|
||||||
|
.event_handler
|
||||||
|
.handle_incoming_pdu(&remote_server, &event_id, room_id, pdu, true, &pub_key_map)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
return Err(error);
|
return Err(error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue