From 33fbc43f764aa2aca98e5538edb61d0b34372f51 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Thu, 19 Jun 2025 22:13:40 +0100 Subject: [PATCH] Almost call with the PDU Need to figure out why signing is sad (cherry picked from commit 6134b971633c9981871c1c9d060a677588714141) --- Cargo.lock | 22 ++++----- Cargo.toml | 2 +- .../rooms/event_handler/call_policyserv.rs | 47 +++++++++++++------ .../event_handler/upgrade_outlier_pdu.rs | 2 +- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44c210f1..49c45327 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3695,7 +3695,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "assign", "js_int", @@ -3715,7 +3715,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "js_int", "ruma-common", @@ -3727,7 +3727,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "as_variant", "assign", @@ -3750,7 +3750,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "as_variant", "base64 0.22.1", @@ -3782,7 +3782,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "as_variant", "indexmap 2.9.0", @@ -3807,7 +3807,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "bytes", "headers", @@ -3829,7 +3829,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3838,7 +3838,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "js_int", "ruma-common", @@ -3848,7 +3848,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3863,7 +3863,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "js_int", "ruma-common", @@ -3875,7 +3875,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=781606d1fafbf2daa220fd354d9ad0479a308cd1#781606d1fafbf2daa220fd354d9ad0479a308cd1" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=1faaf474b122159a04518214e8248b465dae06c9#1faaf474b122159a04518214e8248b465dae06c9" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 2ad5c1ca..40a8ea0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,7 +350,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "781606d1fafbf2daa220fd354d9ad0479a308cd1" +rev = "1faaf474b122159a04518214e8248b465dae06c9" features = [ "compat", "rand", diff --git a/src/service/rooms/event_handler/call_policyserv.rs b/src/service/rooms/event_handler/call_policyserv.rs index 548a0081..f40ec3c7 100644 --- a/src/service/rooms/event_handler/call_policyserv.rs +++ b/src/service/rooms/event_handler/call_policyserv.rs @@ -1,21 +1,18 @@ -use conduwuit::{Err, Result, debug, implement, trace, warn}; -use ruma::{ - EventId, OwnedEventId, OwnedServerName, RoomId, ServerName, - api::federation::room::policy::v1::{Request as PolicyRequest, Response as PolicyResponse}, - events::{ - StateEventType, - room::{ - policy::{PolicyServerResponseContent, RoomPolicyEventContent}, - server_acl::RoomServerAclEventContent, - }, - }, +use conduwuit::{ + Err, Event, PduEvent, Result, debug, implement, utils::to_canonical_object, warn, }; -use serde::{Deserialize, Serialize}; +use ruma::{ + RoomId, ServerName, + api::federation::room::policy::v1::Request as PolicyRequest, + events::StateEventType, + events::room::policy::RoomPolicyEventContent, +}; +use ruma::canonical_json::to_canonical_value; /// Returns Ok if the policy server allows the event #[implement(super::Service)] #[tracing::instrument(skip_all, level = "debug")] -pub async fn policyserv_check(&self, event_id: &EventId, room_id: &RoomId) -> Result { +pub async fn policyserv_check(&self, pdu: &PduEvent, room_id: &RoomId) -> Result { let Ok(policyserver) = self .services .state_accessor @@ -33,10 +30,27 @@ pub async fn policyserv_check(&self, event_id: &EventId, room_id: &RoomId) -> Re return Ok(()); }, }; + // TODO: dont do *this* + let pdu_json = self.services.timeline.get_pdu_json(pdu.event_id()).await?; + let outgoing = self.services + .sending + .convert_to_outgoing_federation_event(pdu_json) + .await; + // let s = match serde_json::to_string(outgoing.as_ref()) { + // | Ok(s) => s, + // | Err(e) => { + // warn!("Failed to convert pdu {} to outgoing federation event: {e}", pdu.event_id()); + // return Err!(Request(InvalidParam("Failed to convert PDU to outgoing event."))); + // }, + // }; let response = self .services .sending - .send_federation_request(via, PolicyRequest { event_id: event_id.to_owned() }) + .send_federation_request(via, PolicyRequest { + event_id: pdu.event_id().to_owned(), + // pdu: Some(outgoing), + pdu: None, // TODO: figure out why providing the PDU makes the signature invalid + }) .await; let response = match response { | Ok(response) => response, @@ -46,7 +60,10 @@ pub async fn policyserv_check(&self, event_id: &EventId, room_id: &RoomId) -> Re }, }; if response.recommendation == "spam" { - warn!("Event {event_id} in room {room_id} was marked as spam by policy server {via}"); + warn!( + "Event {} in room {room_id} was marked as spam by policy server {via}", + pdu.event_id().to_owned() + ); return Err!(Request(Forbidden("Event was marked as spam by policy server"))); }; diff --git a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs index 7b42b093..2c841b29 100644 --- a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs +++ b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs @@ -220,7 +220,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( && incoming_pdu.sender().server_name() != self.services.globals.server_name() { debug!("Checking policy server for event {}", incoming_pdu.event_id); - let policy = self.policyserv_check(&incoming_pdu.event_id, room_id); + let policy = self.policyserv_check(&incoming_pdu, room_id); if let Err(e) = policy.await { warn!("Policy server check failed for event {}: {e}", incoming_pdu.event_id); if !soft_fail {