Return an error when signing an event fails

Prevents the server from crashing/become unresponsive when overly long
messages are sent
This commit is contained in:
Zeyphros 2022-04-08 22:05:13 +02:00
parent 6e106b5732
commit 07a3a6fa9a
No known key found for this signature in database
GPG key ID: AD4D831FBD76C521

View file

@ -1938,13 +1938,25 @@ impl Rooms {
CanonicalJsonValue::String(db.globals.server_name().as_ref().to_owned()),
);
ruma::signatures::hash_and_sign_event(
match ruma::signatures::hash_and_sign_event(
db.globals.server_name().as_str(),
db.globals.keypair(),
&mut pdu_json,
&room_version_id,
)
.expect("event is valid, we just created it");
) {
Ok(_) => {}
Err(e) => {
return match e {
ruma::signatures::Error::PduSize => {
Err(Error::BadRequest(ErrorKind::TooLarge, "Message is to long"))
}
_ => Err(Error::BadRequest(
ErrorKind::Unknown,
"Signing event failed",
)),
}
}
}
// Generate event id
pdu.event_id = EventId::parse_arc(format!(