mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-24 09:27:38 +00:00
Merge branch 'main' into nex/feat/notary-server
# Conflicts: # src/api/server/key.rs # src/service/server_keys/mod.rs # src/service/server_keys/request.rs # src/service/server_keys/verify.rs
This commit is contained in:
335 files changed
+9944
-6292
No files matched your search
@@ -1,7 +1,10 @@
|
||||
use std::{borrow::Borrow, iter::once};
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, Event, Result, info, utils::stream::ReadyExt};
|
||||
use conduwuit::{
|
||||
Err, Event, Result, info,
|
||||
utils::stream::{BroadbandExt, ReadyExt},
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use ruma::api::federation::authorization::get_event_authorization;
|
||||
|
||||
@@ -64,7 +67,9 @@ pub(crate) async fn get_event_authorization_route(
|
||||
.auth_chain
|
||||
.event_ids_iter(&body.room_id, once(body.event_id.borrow()))
|
||||
.ready_filter_map(Result::ok)
|
||||
.filter_map(|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() })
|
||||
.broad_filter_map(
|
||||
|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() },
|
||||
)
|
||||
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, Event, Result, debug, info, trace, utils::to_canonical_object, warn};
|
||||
use conduwuit::{Err, Event, Result, debug, debug_warn, info, trace, utils::to_canonical_object};
|
||||
use ruma::{OwnedEventId, api::federation::event::get_missing_events};
|
||||
use serde_json::value::RawValue;
|
||||
use service::rooms::event_handler::GET_MISSING_EVENTS_MAX_BATCH_SIZE;
|
||||
@@ -44,6 +44,10 @@ pub(crate) async fn get_missing_events_route(
|
||||
.unwrap_or(10)
|
||||
.min(GET_MISSING_EVENTS_MAX_BATCH_SIZE);
|
||||
|
||||
if body.latest_events.len() > limit {
|
||||
return Err!(Request(InvalidParam("Too many latest_events")));
|
||||
}
|
||||
|
||||
let room_version = services.rooms.state.get_room_version(&body.room_id).await?;
|
||||
|
||||
let mut queue: VecDeque<OwnedEventId> = VecDeque::from(body.latest_events.clone());
|
||||
@@ -64,7 +68,9 @@ pub(crate) async fn get_missing_events_route(
|
||||
let mut pdu = match services.rooms.timeline.get_pdu(&next_event_id).await {
|
||||
| Ok(pdu) => pdu,
|
||||
| Err(e) => {
|
||||
warn!("could not find event {next_event_id} while walking missing events: {e}");
|
||||
debug_warn!(
|
||||
"could not find event {next_event_id} while walking missing events: {e}"
|
||||
);
|
||||
continue;
|
||||
},
|
||||
};
|
||||
@@ -74,6 +80,10 @@ pub(crate) async fn get_missing_events_route(
|
||||
body.room_id
|
||||
)));
|
||||
}
|
||||
if pdu.depth < body.min_depth {
|
||||
debug!(%next_event_id, %pdu.depth, %body.min_depth, "event is below minimum depth, not traversing");
|
||||
continue;
|
||||
}
|
||||
if services
|
||||
.rooms
|
||||
.pdu_metadata
|
||||
|
||||
+27
-24
@@ -209,31 +209,35 @@ async fn create_invite(
|
||||
|
||||
services.sync.wake(&recipient_user).await;
|
||||
|
||||
for appservice in services.appservice.read().await.values() {
|
||||
if appservice.is_user_match(&recipient_user) {
|
||||
let transaction_id = general_purpose::URL_SAFE_NO_PAD
|
||||
.encode(sha256::hash(pdu.event_id.as_bytes()))
|
||||
.into();
|
||||
let matching_appservices: Vec<_> = services
|
||||
.appservice
|
||||
.read()
|
||||
.values()
|
||||
.filter(|appservice| appservice.is_user_match(&recipient_user))
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
let request = ruma::api::appservice::event::push_events::v1::Request::new(
|
||||
transaction_id,
|
||||
vec![pdu.to_format()],
|
||||
);
|
||||
for appservice in matching_appservices {
|
||||
let transaction_id = general_purpose::URL_SAFE_NO_PAD
|
||||
.encode(sha256::hash(pdu.event_id.as_bytes()))
|
||||
.into();
|
||||
|
||||
services
|
||||
.sending
|
||||
.send_appservice_request(appservice.registration.clone(), request)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"failed to notify appservice {} about incoming invite: {e}",
|
||||
appservice.registration.id
|
||||
);
|
||||
err!(BadServerResponse(
|
||||
"Failed to notify appservice about incoming invite."
|
||||
))
|
||||
})?;
|
||||
}
|
||||
let request = ruma::api::appservice::event::push_events::v1::Request::new(
|
||||
transaction_id,
|
||||
vec![pdu.to_format()],
|
||||
);
|
||||
|
||||
services
|
||||
.sending
|
||||
.send_appservice_request(appservice.registration.clone(), request)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"failed to notify appservice {} about incoming invite: {e}",
|
||||
appservice.registration.id
|
||||
);
|
||||
err!(BadServerResponse("Failed to notify appservice about incoming invite."))
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +421,6 @@ async fn validate_invite_create_event(
|
||||
if !state_res::auth_check(
|
||||
room_version_rules,
|
||||
pdu,
|
||||
None,
|
||||
|_, _| async {
|
||||
unreachable!("No state should be fetched when processing a lone create event");
|
||||
},
|
||||
|
||||
@@ -212,15 +212,15 @@ async fn acquire_keys_as_notary(
|
||||
if server_keys.notary_may_contact_origin(&remote) {
|
||||
debug_info!("Asking remote directly for verify keys");
|
||||
if let Ok(res) = server_keys.origin_request(remote.clone(), start).await
|
||||
&& let Ok(ssk) = sign_ssk(&server_keys, res.clone(), &remote, &my_name).await
|
||||
&& let Ok(ssk) = sign_ssk(&server_keys, res.parsed.clone(), &remote, &my_name).await
|
||||
{
|
||||
let index = results.len();
|
||||
results.push(ssk);
|
||||
for key_id in res.verify_keys.keys().chain(res.old_verify_keys.keys()) {
|
||||
for key_id in res.parsed.verify_keys.keys().chain(res.parsed.old_verify_keys.keys()) {
|
||||
if fetch_all
|
||||
|| queries.get(key_id).is_some_and(|c| {
|
||||
c.minimum_valid_until_ts
|
||||
.is_none_or(|m| res.valid_until_ts >= m)
|
||||
.is_none_or(|m| res.parsed.valid_until_ts >= m)
|
||||
}) {
|
||||
queries.remove(key_id);
|
||||
keymap.insert(key_id.to_owned(), index);
|
||||
@@ -241,11 +241,11 @@ async fn acquire_keys_as_notary(
|
||||
let my_name = &my_name;
|
||||
let server_keys = &server_keys;
|
||||
async move {
|
||||
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < start {
|
||||
if ssk.parsed.valid_until_ts > in_one_week() || ssk.valid_until_ts < start {
|
||||
return None;
|
||||
}
|
||||
|
||||
sign_ssk(server_keys, ssk.clone(), server_name, my_name)
|
||||
sign_ssk(server_keys, ssk.parsed.clone(), server_name, my_name)
|
||||
.await
|
||||
.map(|signed_ssk| (ssk, signed_ssk))
|
||||
.ok()
|
||||
@@ -254,7 +254,7 @@ async fn acquire_keys_as_notary(
|
||||
.ready_for_each(|(ssk, signed_ssk)| {
|
||||
let idx = results.len();
|
||||
results.push(signed_ssk);
|
||||
for key_id in ssk.verify_keys.keys().chain(ssk.old_verify_keys.keys()) {
|
||||
for key_id in ssk.parsed.verify_keys.keys().chain(ssk.old_verify_keys.keys()) {
|
||||
keymap.insert(key_id.to_owned(), idx);
|
||||
}
|
||||
})
|
||||
@@ -346,7 +346,7 @@ pub(crate) async fn get_remote_server_keys_route(
|
||||
{
|
||||
return sign_ssk(
|
||||
&services.server_keys,
|
||||
response,
|
||||
response.parsed,
|
||||
&body.server_name,
|
||||
services.globals.server_name(),
|
||||
)
|
||||
@@ -360,13 +360,13 @@ pub(crate) async fn get_remote_server_keys_route(
|
||||
.broad_filter_map(|ssk| {
|
||||
let server_name = body.server_name.clone();
|
||||
async move {
|
||||
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < min_valid_ts {
|
||||
if ssk.parsed.valid_until_ts > in_one_week() || ssk.parsed.valid_until_ts < min_valid_ts {
|
||||
return None;
|
||||
}
|
||||
|
||||
sign_ssk(
|
||||
&services.server_keys,
|
||||
ssk,
|
||||
ssk.parsed,
|
||||
server_name.as_ref(),
|
||||
services.globals.server_name(),
|
||||
)
|
||||
|
||||
+67
-185
@@ -1,29 +1,19 @@
|
||||
use std::{borrow::ToOwned, pin::pin};
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Error, Result, debug, debug_info, info, matrix::pdu::PartialPdu, utils, warn,
|
||||
};
|
||||
use conduwuit_service::Services;
|
||||
use futures::StreamExt;
|
||||
use conduwuit::{Err, Error, Result, info, matrix::pdu::PartialPdu, utils};
|
||||
use ruma::{
|
||||
OwnedUserId, RoomId, UserId,
|
||||
OwnedUserId,
|
||||
api::{
|
||||
error::{ErrorKind, IncompatibleRoomVersionErrorData},
|
||||
federation::membership::prepare_join_event,
|
||||
},
|
||||
assign,
|
||||
events::{
|
||||
StateEventType,
|
||||
room::{
|
||||
join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
events::room::{
|
||||
join_rules::JoinRule,
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use service::rooms::state::RoomMutexGuard;
|
||||
use tokio::join;
|
||||
use service::rooms::membership::{JoinConditionEntity, JoinConditionResult};
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
@@ -35,9 +25,6 @@ pub(crate) async fn create_join_event_template_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<prepare_join_event::v1::Request>,
|
||||
) -> Result<prepare_join_event::v1::Response> {
|
||||
if !services.rooms.metadata.exists(&body.room_id).await {
|
||||
return Err!(Request(NotFound("Room is unknown to this server.")));
|
||||
}
|
||||
if !services
|
||||
.rooms
|
||||
.state_cache
|
||||
@@ -63,18 +50,6 @@ pub(crate) async fn create_join_event_template_route(
|
||||
.acl_check(&body.identity, &body.room_id)
|
||||
.await?;
|
||||
|
||||
if services
|
||||
.moderation
|
||||
.is_remote_server_forbidden(&body.identity)
|
||||
{
|
||||
warn!(
|
||||
"Server {} for remote user {} tried joining room ID {} which has a server name that \
|
||||
is globally forbidden. Rejecting.",
|
||||
body.identity, &body.user_id, &body.room_id,
|
||||
);
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
let room_version = services.rooms.state.get_room_version(&body.room_id).await?;
|
||||
let room_version_rules = room_version.rules().unwrap();
|
||||
if !body.ver.contains(&room_version) {
|
||||
@@ -87,41 +62,78 @@ pub(crate) async fn create_join_event_template_route(
|
||||
}
|
||||
|
||||
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
||||
let (is_invited, is_joined) = join!(
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_invited(&body.user_id, &body.room_id),
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_joined(&body.user_id, &body.room_id)
|
||||
);
|
||||
|
||||
let current_membership = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.get_member(&body.room_id, &body.user_id)
|
||||
.await
|
||||
.ok()
|
||||
.map_or(MembershipState::Leave, |content| content.membership);
|
||||
|
||||
let join_authorized_via_users_server: Option<OwnedUserId> = {
|
||||
if is_joined || is_invited {
|
||||
// User is already joined or invited and consequently does not need
|
||||
// an authorising user
|
||||
if matches!(
|
||||
current_membership,
|
||||
MembershipState::Join | MembershipState::Invite | MembershipState::Knock
|
||||
) {
|
||||
// User is already joined, invited, or knocked, and consequently
|
||||
// does not need an authorising user
|
||||
None
|
||||
} else if !room_version_rules.authorization.restricted_join_rule {
|
||||
// room version does not support restricted join rules
|
||||
// Room version does not support restricted join rules
|
||||
None
|
||||
} else if user_can_perform_restricted_join(&services, &body.user_id, &body.room_id)
|
||||
.await?
|
||||
{
|
||||
Some(
|
||||
select_authorising_user(&services, &body.room_id, &body.user_id, &state_lock)
|
||||
.await?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
let join_rules = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.get_join_rules(&body.room_id)
|
||||
.await;
|
||||
|
||||
if let JoinRule::Restricted(conditions) | JoinRule::KnockRestricted(conditions) =
|
||||
join_rules
|
||||
{
|
||||
match services
|
||||
.rooms
|
||||
.membership
|
||||
.evaluate_join_conditions(
|
||||
&body.room_id,
|
||||
JoinConditionEntity::User(&body.user_id),
|
||||
&conditions,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| JoinConditionResult::Satisfied => {
|
||||
// Try to find an authorizing user
|
||||
services
|
||||
.rooms
|
||||
.membership
|
||||
.select_authorizing_user(&body.room_id, &body.user_id, &state_lock)
|
||||
.await
|
||||
.map(Some)?
|
||||
},
|
||||
| JoinConditionResult::Unsatisfied => {
|
||||
return Err!(Request(Forbidden(
|
||||
"You do not satisfy this room's join conditions."
|
||||
)));
|
||||
},
|
||||
| JoinConditionResult::UnableToAuthorizeJoin => {
|
||||
return Err!(Request(UnableToAuthorizeJoin(
|
||||
"This server cannot check this room's join conditions."
|
||||
)));
|
||||
},
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
if services.antispam.check_all_joins() && join_authorized_via_users_server.is_none() {
|
||||
|
||||
if services.antispam.check_all_joins() {
|
||||
if services
|
||||
.antispam
|
||||
.meowlnir_accept_make_join(body.room_id.clone(), body.user_id.clone())
|
||||
.await
|
||||
.is_err()
|
||||
!= JoinConditionResult::Satisfied
|
||||
{
|
||||
return Err!(Request(Forbidden("Antispam rejected join request.")));
|
||||
}
|
||||
@@ -153,133 +165,3 @@ pub(crate) async fn create_join_event_template_route(
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
/// Attempts to find a user who is able to issue an invite in the target room.
|
||||
pub(crate) async fn select_authorising_user<'a>(
|
||||
services: &Services,
|
||||
room_id: &'a RoomId,
|
||||
user_id: &'a UserId,
|
||||
state_lock: &'a RoomMutexGuard,
|
||||
) -> Result<OwnedUserId> {
|
||||
let candidates = services.rooms.state_cache.local_users_in_room(room_id);
|
||||
|
||||
let mut candidates = pin!(candidates);
|
||||
|
||||
while let Some(candidate) = candidates.next().await {
|
||||
if services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.user_can_invite(room_id, &candidate, user_id, state_lock)
|
||||
.await
|
||||
{
|
||||
return Ok(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
Err!(Request(UnableToGrantJoin(
|
||||
"No user on this server is able to assist in joining."
|
||||
)))
|
||||
}
|
||||
|
||||
/// Checks whether the given user can join the given room via a restricted join.
|
||||
pub(crate) async fn user_can_perform_restricted_join(
|
||||
services: &Services,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
) -> Result<bool> {
|
||||
let Ok(join_rules_event_content) = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get_content::<RoomJoinRulesEventContent>(
|
||||
room_id,
|
||||
&StateEventType::RoomJoinRules,
|
||||
"",
|
||||
)
|
||||
.await
|
||||
else {
|
||||
// No join rules means there's nothing to authorise (defaults to invite)
|
||||
return Ok(false);
|
||||
};
|
||||
|
||||
let (JoinRule::Restricted(r) | JoinRule::KnockRestricted(r)) =
|
||||
join_rules_event_content.join_rule
|
||||
else {
|
||||
// This is not a restricted room
|
||||
return Ok(false);
|
||||
};
|
||||
|
||||
if r.allow.is_empty() {
|
||||
// This will never be authorisable, return forbidden.
|
||||
return Err!(Request(Forbidden("You are not invited to this room.")));
|
||||
}
|
||||
|
||||
let mut could_satisfy = true;
|
||||
for allow_rule in &r.allow {
|
||||
match allow_rule {
|
||||
| AllowRule::RoomMembership(membership) => {
|
||||
if !services
|
||||
.rooms
|
||||
.state_cache
|
||||
.server_in_room(services.globals.server_name(), &membership.room_id)
|
||||
.await
|
||||
{
|
||||
// Since we can't check this room, mark could_satisfy as
|
||||
// false so that we can return
|
||||
// M_UNABLE_TO_AUTHORIZE_JOIN later.
|
||||
could_satisfy = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if services
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_joined(user_id, &membership.room_id)
|
||||
.await
|
||||
{
|
||||
debug!(
|
||||
"User {} is allowed to join room {} via membership in room {}",
|
||||
user_id, room_id, membership.room_id
|
||||
);
|
||||
return Ok(true);
|
||||
}
|
||||
},
|
||||
| other if other.rule_type() == "fi.mau.spam_checker" =>
|
||||
return match services
|
||||
.antispam
|
||||
.meowlnir_accept_make_join(room_id.to_owned(), user_id.to_owned())
|
||||
.await
|
||||
{
|
||||
| Ok(()) => Ok(true),
|
||||
| Err(_) => Err!(Request(Forbidden("Antispam rejected join request."))),
|
||||
},
|
||||
| _ => {
|
||||
// We don't recognise this join rule, so we cannot satisfy the
|
||||
// request.
|
||||
could_satisfy = false;
|
||||
debug_info!(
|
||||
"Unsupported allow rule in restricted join for room {}: {:?}",
|
||||
room_id,
|
||||
allow_rule
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if could_satisfy {
|
||||
// We were able to check all the restrictions and can be certain that
|
||||
// the prospective member is not permitted to join.
|
||||
Err!(Request(Forbidden(
|
||||
"You do not belong to any of the rooms or spaces required to join this room."
|
||||
)))
|
||||
} else {
|
||||
// We were unable to check all the restrictions. This usually means we
|
||||
// aren't in one of the rooms this one is restricted to, ergo can't
|
||||
// check its state for the user's membership, and consequently the
|
||||
// user *might* be able to join if they ask another server.
|
||||
Err!(Request(UnableToAuthorizeJoin(
|
||||
"You do not belong to any of the recognised rooms or spaces required to join this \
|
||||
room, but this server is unable to verify every requirement. You may be able to \
|
||||
join via another server."
|
||||
)))
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ pub(super) mod send_knock;
|
||||
pub(super) mod send_leave;
|
||||
pub(super) mod state;
|
||||
pub(super) mod state_ids;
|
||||
pub(super) mod stripped_state;
|
||||
pub(super) mod user;
|
||||
pub(super) mod version;
|
||||
pub(super) mod well_known;
|
||||
@@ -42,6 +43,7 @@ pub(super) use send_knock::*;
|
||||
pub(super) use send_leave::*;
|
||||
pub(super) use state::*;
|
||||
pub(super) use state_ids::*;
|
||||
pub(super) use stripped_state::*;
|
||||
pub(super) use user::*;
|
||||
pub(super) use version::*;
|
||||
pub(super) use well_known::*;
|
||||
|
||||
+16
-23
@@ -332,6 +332,7 @@ async fn handle_room(
|
||||
room_id: OwnedRoomId,
|
||||
pdus: impl Iterator<Item = Pdu> + Send,
|
||||
) -> std::result::Result<Vec<(OwnedEventId, Result)>, TransactionError> {
|
||||
let arrived = millis_since_unix_epoch();
|
||||
let _room_lock = services
|
||||
.rooms
|
||||
.event_handler
|
||||
@@ -392,7 +393,7 @@ async fn handle_room(
|
||||
.federation_incoming_pdu_duration
|
||||
.record(start.elapsed().as_secs_f64(), std::slice::from_ref(&outcome));
|
||||
if let (Ok(()), Some(ts)) = (&result, origin_server_ts) {
|
||||
let lag = millis_since_unix_epoch().saturating_sub(ts);
|
||||
let lag = arrived.saturating_sub(ts);
|
||||
instruments
|
||||
.federation_incoming_pdu_lag
|
||||
.record(Duration::from_millis(lag).as_secs_f64(), &[]);
|
||||
@@ -581,28 +582,20 @@ async fn handle_edu_receipt_room_user(
|
||||
}
|
||||
|
||||
let data = &user_updates.data;
|
||||
user_updates
|
||||
.event_ids
|
||||
.into_iter()
|
||||
.stream()
|
||||
.for_each_concurrent(automatic_width(), |event_id| async move {
|
||||
let user_data = [(user_id.to_owned(), data.clone())];
|
||||
let receipts = [(ReceiptType::Read, BTreeMap::from(user_data))];
|
||||
let content = [(event_id.clone(), BTreeMap::from(receipts))];
|
||||
services
|
||||
.rooms
|
||||
.read_receipt
|
||||
.readreceipt_update(
|
||||
user_id,
|
||||
room_id,
|
||||
ReceiptEvent::new(
|
||||
room_id.to_owned(),
|
||||
ReceiptEventContent::from_iter(content),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
})
|
||||
.await;
|
||||
for event_id in user_updates.event_ids {
|
||||
let user_data = [(user_id.to_owned(), data.clone())];
|
||||
let receipts = [(ReceiptType::Read, BTreeMap::from(user_data))];
|
||||
let content = [(event_id, BTreeMap::from(receipts))];
|
||||
services
|
||||
.rooms
|
||||
.read_receipt
|
||||
.readreceipt_update(
|
||||
user_id,
|
||||
room_id,
|
||||
ReceiptEvent::new(room_id.to_owned(), ReceiptEventContent::from_iter(content)),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_edu_typing(services: &Services, origin: &ServerName, typing: TypingContent) {
|
||||
|
||||
+50
-10
@@ -16,9 +16,11 @@ use ruma::{
|
||||
TimelineEventType,
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
room::JoinRule,
|
||||
room_version_rules::RoomVersionRules,
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use service::rooms::membership::{JoinConditionEntity, JoinConditionResult};
|
||||
|
||||
use crate::{Ruma, server::utils::validate_any_membership_event};
|
||||
|
||||
@@ -108,18 +110,56 @@ async fn create_join_event(
|
||||
they cannot authorise your join."
|
||||
)));
|
||||
}
|
||||
if !super::user_can_perform_restricted_join(services, &sender, room_id).await? {
|
||||
return Err!(Request(UnableToAuthorizeJoin(
|
||||
"Joining user did not pass restricted room's rules."
|
||||
|
||||
// If the user is invited or joined we don't need to check the join
|
||||
// conditions, but in that case the requesting server shouldn't
|
||||
// have set `join_authorized_via_users_server` in the first place.
|
||||
|
||||
let join_rules = services.rooms.state_accessor.get_join_rules(room_id).await;
|
||||
|
||||
if let JoinRule::Restricted(conditions) | JoinRule::KnockRestricted(conditions) =
|
||||
join_rules
|
||||
{
|
||||
match services
|
||||
.rooms
|
||||
.membership
|
||||
.evaluate_join_conditions(
|
||||
room_id,
|
||||
JoinConditionEntity::User(&sender),
|
||||
&conditions,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| JoinConditionResult::Satisfied => {
|
||||
// Sign the join to prove that we checked the conditions.
|
||||
|
||||
services
|
||||
.server_keys
|
||||
.hash_and_sign_event(&mut pdu, room_version_rules)
|
||||
.map_err(|e| {
|
||||
err!(Request(InvalidParam(warn!(
|
||||
"Failed to sign send_join event: {e}"
|
||||
))))
|
||||
})?;
|
||||
},
|
||||
| JoinConditionResult::Unsatisfied => {
|
||||
return Err!(Request(Forbidden(
|
||||
"You do not satisfy this room's join conditions."
|
||||
)));
|
||||
},
|
||||
| JoinConditionResult::UnableToAuthorizeJoin => {
|
||||
return Err!(Request(UnableToAuthorizeJoin(
|
||||
"This server cannot check this room's join conditions."
|
||||
)));
|
||||
},
|
||||
}
|
||||
} else {
|
||||
// We can't sign this, and if we don't sign it our event will fail
|
||||
// the auth check, so we have to bail out here.
|
||||
return Err!(Request(InvalidParam(
|
||||
"join_authorized_via_users_server was supplied for a room that is not restricted"
|
||||
)));
|
||||
}
|
||||
|
||||
services
|
||||
.server_keys
|
||||
.hash_and_sign_event(&mut pdu, room_version_rules)
|
||||
.map_err(|e| {
|
||||
err!(Request(InvalidParam(warn!("Failed to sign send_join event: {e}"))))
|
||||
})?;
|
||||
}
|
||||
|
||||
let mutex_lock = services
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, Result};
|
||||
use ruma::{
|
||||
api::federation::event::get_stripped_state, assign, events::ALLOWED_STRIPPED_STATE_EVENTS,
|
||||
};
|
||||
use service::rooms::summary::{Accessibility, RoomStrippedState};
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
/// # `POST /_matrix/federation/unstable/org.continuwuity.msc4560.stripped_state/{room_id}` ([MSC4560])
|
||||
///
|
||||
/// Returns a room's stripped state.
|
||||
///
|
||||
/// [MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
|
||||
pub(crate) async fn get_stripped_state_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_stripped_state::msc4560::Request>,
|
||||
) -> Result<get_stripped_state::msc4560::Response> {
|
||||
if let Some(forbidden_type) = body
|
||||
.state
|
||||
.iter()
|
||||
.find(|event_type| !ALLOWED_STRIPPED_STATE_EVENTS.contains(event_type))
|
||||
{
|
||||
return Err!(Request(InvalidParam(
|
||||
"Event type {forbidden_type} may not be requested as stripped state."
|
||||
)));
|
||||
}
|
||||
|
||||
if services.rooms.metadata.is_banned(&body.room_id).await {
|
||||
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
match services
|
||||
.rooms
|
||||
.summary
|
||||
.get_local_stripped_state_for_server(
|
||||
&body.identity,
|
||||
&body.room_id,
|
||||
&body.state,
|
||||
body.num_joined_members,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| Accessibility::Accessible(RoomStrippedState { state, num_joined_members, .. }) => Ok(
|
||||
assign!(get_stripped_state::msc4560::Response::default(), { state, num_joined_members }),
|
||||
),
|
||||
| Accessibility::Inaccessible => {
|
||||
Err!(Request(Forbidden("You may not access this room's stripped state.")))
|
||||
},
|
||||
| Accessibility::NotFound => {
|
||||
Err!(Request(NotFound("This room is not known to this server.")))
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user