Merge branch 'olivia/bump-ruma' into 'main'

Draft: Bump ruma to latest main

See merge request matrix/grapevine!196
This commit is contained in:
Olivia Lee 2025-08-22 00:18:10 -07:00
commit 3cf518bb12
15 changed files with 187 additions and 126 deletions

53
Cargo.lock generated
View file

@ -369,9 +369,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.30"
version = "1.2.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7"
checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2"
dependencies = [
"jobserver",
"libc",
@ -2441,8 +2441,8 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.12.1"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
version = "0.12.3"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"assign",
"js_int",
@ -2460,8 +2460,8 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.12.1"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
version = "0.12.2"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"js_int",
"ruma-common",
@ -2472,8 +2472,8 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.20.1"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
version = "0.20.3"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"as_variant",
"assign",
@ -2495,8 +2495,8 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.15.1"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
version = "0.15.2"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"as_variant",
"base64",
@ -2526,8 +2526,8 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.30.1"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
version = "0.30.3"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"as_variant",
"indexmap 2.10.0",
@ -2549,8 +2549,8 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.11.0"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
version = "0.11.1"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"bytes",
"headers",
@ -2572,7 +2572,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.10.1"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"js_int",
"thiserror 2.0.12",
@ -2581,7 +2581,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.15.1"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"cfg-if",
"proc-macro-crate",
@ -2596,7 +2596,7 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.11.0"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"js_int",
"ruma-common",
@ -2607,8 +2607,8 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.17.0"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
version = "0.17.1"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"base64",
"ed25519-dalek",
@ -2624,11 +2624,12 @@ dependencies = [
[[package]]
name = "ruma-state-res"
version = "0.13.0"
source = "git+https://github.com/ruma/ruma.git?rev=e8b0876dda083433a7f9181d47d0aff5a5e05497#e8b0876dda083433a7f9181d47d0aff5a5e05497"
source = "git+https://github.com/ruma/ruma.git?rev=be19d07d850a69a5872dcc38f15a0bafb06828e5#be19d07d850a69a5872dcc38f15a0bafb06828e5"
dependencies = [
"js_int",
"ruma-common",
"ruma-events",
"ruma-signatures",
"serde",
"serde_json",
"thiserror 2.0.12",
@ -2866,9 +2867,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.141"
version = "1.0.142"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7"
dependencies = [
"itoa",
"memchr",
@ -3273,9 +3274,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.47.0"
version = "1.47.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35"
checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038"
dependencies = [
"backtrace",
"bytes",
@ -4295,9 +4296,9 @@ checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a"
[[package]]
name = "zune-jpeg"
version = "0.4.19"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c9e525af0a6a658e031e95f14b7f889976b74a11ba0eca5a5fc9ac8a1c43a6a"
checksum = "fc1f7e205ce79eb2da3cd71c5f55f3589785cb7c79f6a03d1c8d1491bda5d089"
dependencies = [
"zune-core",
]

View file

@ -145,7 +145,7 @@ xdg = "2.5.2"
[dependencies.ruma]
git = "https://github.com/ruma/ruma.git"
rev = "e8b0876dda083433a7f9181d47d0aff5a5e05497"
rev = "be19d07d850a69a5872dcc38f15a0bafb06828e5"
features = [
"compat-server-signing-key-version",
"compat-empty-string-null",

View file

@ -3,7 +3,7 @@ use std::{fmt::Debug, mem, time::Duration};
use bytes::BytesMut;
use ruma::api::{
appservice::Registration, IncomingResponse, MatrixVersion, OutgoingRequest,
SendAccessToken,
SendAccessToken, SupportedVersions,
};
use tracing::warn;
@ -31,7 +31,10 @@ where
.try_into_http_request::<BytesMut>(
&destination,
SendAccessToken::IfRequired(hs_token),
&[MatrixVersion::V1_0],
&SupportedVersions {
versions: [MatrixVersion::V1_0].into_iter().collect(),
features: vec![],
},
)
.unwrap()
.map(BytesMut::freeze);

View file

@ -165,7 +165,7 @@ pub(crate) async fn register_route(
stages: vec![AuthType::RegistrationToken],
}],
completed: Vec::new(),
params: Box::default(),
params: Some(Box::default()),
session: None,
auth_error: None,
};
@ -178,7 +178,7 @@ pub(crate) async fn register_route(
stages: vec![AuthType::Dummy],
}],
completed: Vec::new(),
params: Box::default(),
params: Some(Box::default()),
session: None,
auth_error: None,
};
@ -333,7 +333,7 @@ pub(crate) async fn change_password_route(
stages: vec![AuthType::Password],
}],
completed: Vec::new(),
params: Box::default(),
params: Some(Box::default()),
session: None,
auth_error: None,
};
@ -421,7 +421,7 @@ pub(crate) async fn deactivate_route(
stages: vec![AuthType::Password],
}],
completed: Vec::new(),
params: Box::default(),
params: Some(Box::default()),
session: None,
auth_error: None,
};

View file

@ -1,7 +1,8 @@
use std::collections::BTreeMap;
use ruma::api::client::discovery::get_capabilities::{
self, Capabilities, RoomVersionStability, RoomVersionsCapability,
self,
v3::{Capabilities, RoomVersionStability, RoomVersionsCapability},
};
use crate::{services, Ar, Ra, Result};

View file

@ -94,7 +94,7 @@ pub(crate) async fn delete_device_route(
stages: vec![AuthType::Password],
}],
completed: Vec::new(),
params: Box::default(),
params: Some(Box::default()),
session: None,
auth_error: None,
};
@ -148,7 +148,7 @@ pub(crate) async fn delete_devices_route(
stages: vec![AuthType::Password],
}],
completed: Vec::new(),
params: Box::default(),
params: Some(Box::default()),
session: None,
auth_error: None,
};

View file

@ -122,7 +122,7 @@ pub(crate) async fn upload_signing_keys_route(
stages: vec![AuthType::Password],
}],
completed: Vec::new(),
params: Box::default(),
params: Some(Box::default()),
session: None,
auth_error: None,
};

View file

@ -25,9 +25,10 @@ use ruma::{
},
StateEventType, TimelineEventType,
},
room_version_rules::RoomVersionRules,
state_res, CanonicalJsonObject, CanonicalJsonValue, EventId,
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName,
OwnedUserId, RoomId, RoomVersionId, UserId,
OwnedUserId, RoomId, UserId,
};
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use tokio::sync::RwLock;
@ -662,6 +663,10 @@ async fn join_room_by_id_helper(
))
}
};
let room_version_rules = room_version_id
.rules()
.expect("ruma should support all room versions we advertise");
let mut join_event_stub: CanonicalJsonObject = serde_json::from_str(
make_join_response.event.get(),
)
@ -716,7 +721,7 @@ async fn join_room_by_id_helper(
services().globals.server_name().as_str(),
services().globals.keypair(),
&mut join_event_stub,
&room_version_id,
&room_version_rules.redaction,
)
.expect("event is valid, we just created it");
@ -725,7 +730,7 @@ async fn join_room_by_id_helper(
"${}",
ruma::signatures::reference_hash(
&join_event_stub,
&room_version_id
&room_version_rules
)
.expect("ruma can calculate reference hashes")
);
@ -761,7 +766,7 @@ async fn join_room_by_id_helper(
};
let Ok((signed_event_id, signed_value)) =
gen_event_id_canonical_json(&signed_raw, &room_version_id)
gen_event_id_canonical_json(&signed_raw, &room_version_rules)
else {
// Event could not be converted to canonical json
return Err(Error::BadRequest(
@ -814,6 +819,9 @@ async fn join_room_by_id_helper(
))
}
};
let room_version_rules = room_version_id
.rules()
.expect("ruma should support all room versions we advertise");
let mut join_event_stub: CanonicalJsonObject = serde_json::from_str(
make_join_response.event.get(),
@ -871,7 +879,7 @@ async fn join_room_by_id_helper(
services().globals.server_name().as_str(),
services().globals.keypair(),
&mut join_event_stub,
&room_version_id,
&room_version_rules.redaction,
)
.expect("event is valid, we just created it");
@ -880,7 +888,7 @@ async fn join_room_by_id_helper(
"${}",
ruma::signatures::reference_hash(
&join_event_stub,
&room_version_id
&room_version_rules
)
.expect("ruma can calculate reference hashes")
);
@ -920,7 +928,7 @@ async fn join_room_by_id_helper(
restricted joins. Adding signature to our event"
);
let Ok((signed_event_id, signed_value)) =
gen_event_id_canonical_json(signed_raw, &room_version_id)
gen_event_id_canonical_json(signed_raw, &room_version_rules)
else {
// Event could not be converted to canonical json
return Err(Error::BadRequest(
@ -985,14 +993,14 @@ async fn join_room_by_id_helper(
.event_handler
.fetch_join_signing_keys(
&send_join_response,
&room_version_id,
&room_version_rules,
&pub_key_map,
)
.await?;
info!("Going through send_join response room_state");
for result in send_join_response.room_state.state.iter().map(|pdu| {
validate_and_add_event_id(pdu, &room_version_id, &pub_key_map)
validate_and_add_event_id(pdu, &room_version_rules, &pub_key_map)
}) {
let Ok((event_id, value)) = result.await else {
continue;
@ -1025,7 +1033,11 @@ async fn join_room_by_id_helper(
info!("Going through send_join response auth_chain");
for result in
send_join_response.room_state.auth_chain.iter().map(|pdu| {
validate_and_add_event_id(pdu, &room_version_id, &pub_key_map)
validate_and_add_event_id(
pdu,
&room_version_rules,
&pub_key_map,
)
})
{
let Ok((event_id, value)) = result.await else {
@ -1036,10 +1048,22 @@ async fn join_room_by_id_helper(
}
info!("Running send_join auth check");
state_res::event_auth::auth_check(
&state_res::RoomVersion::new(&room_version_id).map_err(|_| {
Error::UnsupportedRoomVersion(room_version_id.clone())
})?,
state_res::check_state_independent_auth_rules(
&room_version_rules.authorization,
&parsed_join_pdu,
|event_id|
services()
.rooms
.timeline
.get_pdu(event_id)
.ok()?
)
.map_err(|error| {
warn!(%error, "Auth check failed");
Error::BadRequest(ErrorKind::InvalidParam, "Auth check failed")
})?;
state_res::check_state_dependent_auth_rules(
&room_version_rules.authorization,
&parsed_join_pdu,
|k, s| {
services()
@ -1171,7 +1195,7 @@ async fn make_join_request(
async fn validate_and_add_event_id(
pdu: &RawJsonValue,
room_version: &RoomVersionId,
room_version_rules: &RoomVersionRules,
pub_key_map: &RwLock<BTreeMap<String, SigningKeys>>,
) -> Result<(OwnedEventId, CanonicalJsonObject)> {
let mut value: CanonicalJsonObject = serde_json::from_str(pdu.get())
@ -1181,7 +1205,7 @@ async fn validate_and_add_event_id(
})?;
let event_id = EventId::parse(format!(
"${}",
ruma::signatures::reference_hash(&value, room_version)
ruma::signatures::reference_hash(&value, room_version_rules)
.expect("ruma can calculate reference hashes")
))
.expect("ruma's reference hashes are valid event ids");
@ -1246,7 +1270,7 @@ async fn validate_and_add_event_id(
.filter_keys_server_map(unfiltered_keys, origin_server_ts);
if let Err(error) =
ruma::signatures::verify_event(&keys, &value, room_version)
ruma::signatures::verify_event(&keys, &value, room_version_rules)
{
warn!(
%event_id,
@ -1319,6 +1343,9 @@ pub(crate) async fn invite_helper(
.rooms
.state
.get_create_content::<ExtractVersion>(room_id)?;
let Some(room_version_rules) = room_version_id.rules() else {
return Err(Error::UnsupportedRoomVersion(room_version_id));
};
let response = services()
.sending
@ -1341,7 +1368,7 @@ pub(crate) async fn invite_helper(
// We do not add the event_id field to the pdu here because of signature
// and hashes checks
let Ok((event_id, value)) =
gen_event_id_canonical_json(&response.event, &room_version_id)
gen_event_id_canonical_json(&response.event, &room_version_rules)
else {
// Event could not be converted to canonical json
return Err(Error::BadRequest(
@ -1631,6 +1658,9 @@ async fn remote_leave_room(user_id: &UserId, room_id: &RoomId) -> Result<()> {
))
}
};
let room_version_rules = room_version_id
.rules()
.expect("ruma should support all room versions we advertise");
let mut leave_event_stub = serde_json::from_str::<CanonicalJsonObject>(
make_leave_response.event.get(),
@ -1666,15 +1696,18 @@ async fn remote_leave_room(user_id: &UserId, room_id: &RoomId) -> Result<()> {
services().globals.server_name().as_str(),
services().globals.keypair(),
&mut leave_event_stub,
&room_version_id,
&room_version_rules.redaction,
)
.expect("event is valid, we just created it");
// Generate event id
let event_id = EventId::parse(format!(
"${}",
ruma::signatures::reference_hash(&leave_event_stub, &room_version_id)
.expect("ruma can calculate reference hashes")
ruma::signatures::reference_hash(
&leave_event_stub,
&room_version_rules
)
.expect("ruma can calculate reference hashes")
))
.expect("ruma's reference hashes are valid event ids");

View file

@ -42,7 +42,7 @@ use ruma::{
},
},
EndpointError, IncomingResponse, MatrixVersion, OutgoingRequest,
OutgoingResponse, SendAccessToken,
OutgoingResponse, SendAccessToken, SupportedVersions,
},
directory::{Filter, RoomNetwork},
events::{
@ -199,7 +199,10 @@ where
.try_into_http_request::<Vec<u8>>(
&actual_destination_str,
SendAccessToken::IfRequired(""),
&[MatrixVersion::V1_11],
&SupportedVersions {
versions: [MatrixVersion::V1_11].into_iter().collect(),
features: vec![],
},
)
.map_err(|error| {
warn!(
@ -718,9 +721,12 @@ pub(crate) fn parse_incoming_pdu(
.rooms
.state
.get_create_content::<ExtractVersion>(&room_id)?;
let Some(room_version_rules) = room_version_id.rules() else {
return Err(Error::UnsupportedRoomVersion(room_version_id));
};
let Ok((event_id, value)) =
gen_event_id_canonical_json(pdu, &room_version_id)
gen_event_id_canonical_json(pdu, &room_version_rules)
else {
// Event could not be converted to canonical json
return Err(Error::BadRequest(
@ -1634,8 +1640,12 @@ async fn create_join_event(
// hashes checks
let room_version_id =
services().rooms.state.get_create_content::<ExtractVersion>(room_id)?;
let Some(room_version_rules) = room_version_id.rules() else {
return Err(Error::UnsupportedRoomVersion(room_version_id));
};
let Ok((event_id, value)) =
gen_event_id_canonical_json(pdu, &room_version_id)
gen_event_id_canonical_json(pdu, &room_version_rules)
else {
// Event could not be converted to canonical json
return Err(Error::BadRequest(
@ -1787,6 +1797,10 @@ pub(crate) async fn create_invite_route(
"Server does not support this room version.",
));
}
let room_version_rules = body
.room_version
.rules()
.expect("ruma should support all room versions we advertise");
let mut signed_event =
utils::to_canonical_object(&body.event).map_err(|_| {
@ -1800,7 +1814,7 @@ pub(crate) async fn create_invite_route(
services().globals.server_name().as_str(),
services().globals.keypair(),
&mut signed_event,
&body.room_version,
&room_version_rules.redaction,
)
.map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Failed to sign event.")
@ -1809,7 +1823,7 @@ pub(crate) async fn create_invite_route(
// Generate event id
let event_id = EventId::parse(format!(
"${}",
ruma::signatures::reference_hash(&signed_event, &body.room_version)
ruma::signatures::reference_hash(&signed_event, &room_version_rules)
.expect("ruma can calculate reference hashes")
))
.expect("ruma's reference hashes are valid event ids");

View file

@ -22,10 +22,11 @@ use ruma::{
},
TimelineEventType,
},
room_version_rules::RoomVersionRules,
serde::Raw,
signatures::verify_json,
EventId, MilliSecondsSinceUnixEpoch, OwnedMxcUri, OwnedRoomId,
OwnedServerName, RoomId, RoomVersionId, ServerName, UserId,
OwnedServerName, RoomId, ServerName, UserId,
};
use serde_json::value::to_raw_value;
use tokio::sync::{mpsc, Mutex, RwLock};
@ -592,7 +593,7 @@ impl Service {
Ok(value) => {
match ruma::signatures::reference_hash(
&value,
&RoomVersionId::V6,
&RoomVersionRules::V6,
) {
Ok(hash) => {
let event_id =

View file

@ -8,10 +8,11 @@ use ruma::{
AnyStateEvent, AnyStrippedStateEvent, AnySyncStateEvent,
AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, TimelineEventType,
},
room_version_rules::{RedactionRules, RoomVersionRules},
serde::Raw,
state_res, CanonicalJsonObject, CanonicalJsonValue, EventId,
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId,
RoomVersionId, UInt, UserId,
UInt, UserId,
};
use serde::{Deserialize, Serialize};
use serde_json::{
@ -59,7 +60,7 @@ impl PduEvent {
#[tracing::instrument(skip(self))]
pub(crate) fn redact(
&mut self,
room_version_id: &RoomVersionId,
rules: &RedactionRules,
reason: &PduEvent,
) -> crate::Result<()> {
self.unsigned = None;
@ -68,14 +69,10 @@ impl PduEvent {
serde_json::from_str(self.content.get()).map_err(|_| {
Error::bad_database("PDU in db has invalid content.")
})?;
redact_content_in_place(
&mut content,
room_version_id,
self.kind.to_string(),
)
.map_err(|e| {
Error::Redaction(self.sender.server_name().to_owned(), e)
})?;
redact_content_in_place(&mut content, rules, self.kind.to_string())
.map_err(|e| {
Error::Redaction(self.sender.server_name().to_owned(), e)
})?;
self.unsigned = Some(to_raw_value(&json!({
"redacted_because": serde_json::to_value(reason).expect("to_value(PduEvent) always works")
@ -489,7 +486,7 @@ impl Ord for PduEvent {
/// CanonicalJsonValue>`.
pub(crate) fn gen_event_id_canonical_json(
pdu: &RawJsonValue,
room_version_id: &RoomVersionId,
rules: &RoomVersionRules,
) -> crate::Result<(OwnedEventId, CanonicalJsonObject)> {
let value: CanonicalJsonObject =
serde_json::from_str(pdu.get()).map_err(|error| {
@ -500,7 +497,7 @@ pub(crate) fn gen_event_id_canonical_json(
let event_id = format!(
"${}",
// Anything higher than version3 behaves the same
ruma::signatures::reference_hash(&value, room_version_id)
ruma::signatures::reference_hash(&value, rules)
.expect("ruma can calculate reference hashes")
)
.try_into()

View file

@ -11,6 +11,7 @@ use ruma::{
},
},
IncomingResponse, MatrixVersion, OutgoingRequest, SendAccessToken,
SupportedVersions,
},
events::{
room::power_levels::RoomPowerLevelsEventContent, AnySyncTimelineEvent,
@ -78,7 +79,10 @@ impl Service {
.try_into_http_request::<BytesMut>(
&destination,
SendAccessToken::IfRequired(""),
&[MatrixVersion::V1_0],
&SupportedVersions {
versions: [MatrixVersion::V1_0].into_iter().collect(),
features: vec![],
},
)
.map_err(|error| {
warn!(%error, %destination, "Failed to find destination");

View file

@ -23,6 +23,7 @@ use ruma::{
TimelineEventType,
},
int,
room_version_rules::RoomVersionRules,
state_res::{self, StateMap},
uint, CanonicalJsonObject, CanonicalJsonValue, EventId,
MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId,
@ -121,13 +122,16 @@ impl Service {
.rooms
.state
.get_create_content::<ExtractVersion>(room_id)?;
let Some(room_version_rules) = room_version_id.rules() else {
return Err(Error::UnsupportedRoomVersion(room_version_id.clone()));
};
let (incoming_pdu, val) = self
.handle_outlier_pdu(
origin,
event_id,
room_id,
&room_version_id,
&room_version_rules,
value,
false,
pub_key_map,
@ -151,7 +155,7 @@ impl Service {
.fetch_unknown_prev_events(
origin,
room_id,
&room_version_id,
&room_version_rules,
pub_key_map,
incoming_pdu.prev_events.clone(),
)
@ -303,7 +307,7 @@ impl Service {
origin: &'a ServerName,
event_id: &'a EventId,
room_id: &'a RoomId,
room_version_id: &'a RoomVersionId,
room_version_rules: &'a RoomVersionRules,
mut value: CanonicalJsonObject,
auth_events_known: bool,
pub_key_map: &'a RwLock<BTreeMap<String, SigningKeys>>,
@ -315,11 +319,6 @@ impl Service {
// 2. Check signatures, otherwise drop
// 3. check content hash, redact if doesn't match
let ruma_room_version =
state_res::RoomVersion::new(room_version_id).map_err(|_| {
Error::UnsupportedRoomVersion(room_version_id.clone())
})?;
// TODO: For RoomVersion6 we must check that Raw<..> is canonical,
// do we anywhere?
//
@ -369,7 +368,7 @@ impl Service {
let mut val = match ruma::signatures::verify_event(
&filtered_keys,
&value,
room_version_id,
room_version_rules,
) {
Err(error) => {
// Drop
@ -384,7 +383,7 @@ impl Service {
warn!(%event_id, "Calculated hash does not match");
let Ok(obj) = ruma::canonical_json::redact(
value,
room_version_id,
&room_version_rules.redaction,
None,
) else {
return Err(Error::BadRequest(
@ -445,7 +444,7 @@ impl Service {
.map(|x| Arc::from(&**x))
.collect::<Vec<_>>(),
room_id,
room_version_id,
room_version_rules,
pub_key_map,
)
.await;
@ -502,7 +501,7 @@ impl Service {
}
state_res::event_auth::auth_check(
&ruma_room_version,
&room_version_rules.authorization,
&incoming_pdu,
|k, s| auth_events.get(&(k.to_string().into(), s.to_owned())),
)
@ -560,10 +559,9 @@ impl Service {
"Upgrading event to timeline pdu",
);
let ruma_room_version = state_res::RoomVersion::new(room_version_id)
.map_err(|_| {
Error::UnsupportedRoomVersion(room_version_id.clone())
})?;
let Some(room_version_rules) = room_version_id.rules() else {
return Err(Error::UnsupportedRoomVersion(room_version_id.clone()));
};
// 10. Fetch missing state and auth chain events by calling /state_ids
// at backwards extremities doing all the checks in this list
@ -710,7 +708,7 @@ impl Service {
let lock = services().globals.stateres_mutex.lock();
let result = state_res::resolve(
room_version_id,
&room_version_rules.authorization,
&fork_states,
auth_chain_sets,
|event_id| {
@ -779,7 +777,7 @@ impl Service {
origin,
&collect,
room_id,
room_version_id,
&room_version_rules,
pub_key_map,
)
.await;
@ -865,7 +863,7 @@ impl Service {
// 11. Check the auth of the event passes based on the state of the
// event
state_res::event_auth::auth_check(
&ruma_room_version,
&room_version_rules.authorization,
&incoming_pdu,
|k, s| {
services()
@ -895,6 +893,7 @@ impl Service {
// Soft fail check before doing state res
let auth_events = services().rooms.state.get_auth_events(
room_id,
&room_version_rules.authorization,
&incoming_pdu.kind,
&incoming_pdu.sender,
incoming_pdu.state_key.as_deref(),
@ -902,7 +901,7 @@ impl Service {
)?;
let auth_fail_against_current = state_res::event_auth::auth_check(
&ruma_room_version,
&room_version_rules.authorization,
&incoming_pdu,
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
)
@ -978,7 +977,7 @@ impl Service {
}
let new_room_state = self
.resolve_state(room_id, room_version_id, state_after)
.resolve_state(room_id, &room_version_rules, state_after)
.await?;
// Set the new room state to the resolved state
@ -1054,11 +1053,11 @@ impl Service {
Ok(pdu_id)
}
#[tracing::instrument(skip(self, room_version_id, incoming_state))]
#[tracing::instrument(skip(self, room_version_rules, incoming_state))]
async fn resolve_state(
&self,
room_id: &RoomId,
room_version_id: &RoomVersionId,
room_version_rules: &RoomVersionRules,
incoming_state: HashMap<ShortStateKey, Arc<EventId>>,
) -> Result<Arc<HashSet<CompressedStateEvent>>> {
debug!("Loading current room state ids");
@ -1120,7 +1119,7 @@ impl Service {
let lock = services().globals.stateres_mutex.lock();
let Ok(state) = state_res::resolve(
room_version_id,
&room_version_rules.authorization,
&fork_states,
auth_chain_sets,
fetch_event,
@ -1168,7 +1167,7 @@ impl Service {
origin: &'a ServerName,
events: &'a [Arc<EventId>],
room_id: &'a RoomId,
room_version_id: &'a RoomVersionId,
room_version_rules: &'a RoomVersionRules,
pub_key_map: &'a RwLock<BTreeMap<String, SigningKeys>>,
) -> BoxFuture<'a, Vec<(Arc<PduEvent>, Option<CanonicalJsonObject>)>> {
Box::pin(async move {
@ -1270,7 +1269,7 @@ impl Service {
let Ok((calculated_event_id, value)) =
pdu::gen_event_id_canonical_json(
&res.pdu,
room_version_id,
room_version_rules,
)
else {
back_off((*next_id).to_owned()).await;
@ -1343,7 +1342,7 @@ impl Service {
origin,
next_id,
room_id,
room_version_id,
room_version_rules,
value.clone(),
true,
pub_key_map,
@ -1376,7 +1375,7 @@ impl Service {
&self,
origin: &ServerName,
room_id: &RoomId,
room_version_id: &RoomVersionId,
room_version_rules: &RoomVersionRules,
pub_key_map: &RwLock<BTreeMap<String, SigningKeys>>,
initial_set: Vec<Arc<EventId>>,
) -> Result<(
@ -1400,7 +1399,7 @@ impl Service {
origin,
&[prev_event_id.clone()],
room_id,
room_version_id,
room_version_rules,
pub_key_map,
)
.await
@ -1533,7 +1532,7 @@ impl Service {
OwnedServerName,
BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
>,
room_version: &RoomVersionId,
room_version_rules: &RoomVersionRules,
pub_key_map: &mut RwLockWriteGuard<'_, BTreeMap<String, SigningKeys>>,
) -> Result<()> {
let value: CanonicalJsonObject = serde_json::from_str(pdu.get())
@ -1544,7 +1543,7 @@ impl Service {
let event_id = format!(
"${}",
ruma::signatures::reference_hash(&value, room_version)
ruma::signatures::reference_hash(&value, room_version_rules)
.expect("ruma can calculate reference hashes")
);
let event_id = <&EventId>::try_from(event_id.as_str())
@ -1648,7 +1647,7 @@ impl Service {
pub(crate) async fn fetch_join_signing_keys(
&self,
event: &create_join_event::v2::Response,
room_version: &RoomVersionId,
room_version_rules: &RoomVersionRules,
pub_key_map: &RwLock<BTreeMap<String, SigningKeys>>,
) -> Result<()> {
let mut servers: BTreeMap<
@ -1671,7 +1670,7 @@ impl Service {
.get_server_keys_from_cache(
pdu,
&mut servers,
room_version,
room_version_rules,
&mut pkm,
)
.await

View file

@ -11,6 +11,7 @@ use ruma::{
AnyStrippedStateEvent, StateEventType, TimelineEventType,
},
room::RoomType,
room_version_rules::AuthorizationRules,
serde::Raw,
state_res::{self, StateMap},
EventId, OwnedEventId, OwnedRoomId, RoomId, RoomVersionId, UserId,
@ -430,10 +431,11 @@ impl Service {
}
/// This fetches auth events from the current state.
#[tracing::instrument(skip(self))]
#[tracing::instrument(skip(self, rules))]
pub(crate) fn get_auth_events(
&self,
room_id: &RoomId,
rules: &AuthorizationRules,
kind: &TimelineEventType,
sender: &UserId,
state_key: Option<&str>,
@ -444,9 +446,10 @@ impl Service {
return Ok(HashMap::new());
};
let auth_events =
state_res::auth_types_for_event(kind, sender, state_key, content)
.expect("content is a valid JSON object");
let auth_events = state_res::auth_types_for_event(
kind, sender, state_key, content, rules,
)
.expect("content is a valid JSON object");
let mut sauthevents = auth_events
.into_iter()

View file

@ -770,13 +770,13 @@ impl Service {
}
})?;
let ruma_room_version = state_res::RoomVersion::new(&room_version_id)
.map_err(|_| {
Error::UnsupportedRoomVersion(room_version_id.clone())
})?;
let Some(room_version_rules) = room_version_id.rules() else {
return Err(Error::UnsupportedRoomVersion(room_version_id));
};
let auth_events = services().rooms.state.get_auth_events(
room_id,
&room_version_rules.authorization,
&event_type,
sender,
state_key.as_deref(),
@ -844,9 +844,11 @@ impl Service {
signatures: None,
};
state_res::auth_check(&ruma_room_version, &pdu, |k, s| {
auth_events.get(&(k.clone(), s.to_owned()))
})
state_res::auth_check(
&room_version_rules.authorization,
&pdu,
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
)
.map_err(|error| {
error!(%error, "Auth check failed");
Error::BadRequest(ErrorKind::InvalidParam, "Auth check failed.")
@ -869,7 +871,7 @@ impl Service {
services().globals.server_name().as_str(),
services().globals.keypair(),
&mut pdu_json,
&room_version_id,
&room_version_rules.redaction,
) {
Ok(()) => {}
Err(e) => {
@ -889,7 +891,7 @@ impl Service {
// Generate event id
pdu.event_id = EventId::parse_arc(format!(
"${}",
ruma::signatures::reference_hash(&pdu_json, &room_version_id)
ruma::signatures::reference_hash(&pdu_json, &room_version_rules)
.expect("ruma can calculate reference hashes")
))
.expect("ruma's reference hashes are valid event ids");
@ -1198,7 +1200,10 @@ impl Service {
.rooms
.state
.get_create_content::<ExtractVersion>(&pdu.room_id)?;
pdu.redact(&room_version_id, reason)?;
let Some(room_version_rules) = room_version_id.rules() else {
return Err(Error::UnsupportedRoomVersion(room_version_id));
};
pdu.redact(&room_version_rules.redaction, reason)?;
self.replace_pdu(
&pdu_id,