Almost call with the PDU

Need to figure out why signing is sad

(cherry picked from commit 6134b971633c9981871c1c9d060a677588714141)
This commit is contained in:
nexy7574 2025-06-19 22:13:40 +01:00
parent ea2d508e47
commit 33fbc43f76
No known key found for this signature in database
GPG key ID: 0FA334385D0B689F
4 changed files with 45 additions and 28 deletions

22
Cargo.lock generated
View file

@ -3695,7 +3695,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.10.1" 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 = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -3715,7 +3715,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.10.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3727,7 +3727,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.18.0" 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 = [ dependencies = [
"as_variant", "as_variant",
"assign", "assign",
@ -3750,7 +3750,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.13.0" 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 = [ dependencies = [
"as_variant", "as_variant",
"base64 0.22.1", "base64 0.22.1",
@ -3782,7 +3782,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.28.1" 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 = [ dependencies = [
"as_variant", "as_variant",
"indexmap 2.9.0", "indexmap 2.9.0",
@ -3807,7 +3807,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.9.0" 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 = [ dependencies = [
"bytes", "bytes",
"headers", "headers",
@ -3829,7 +3829,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.9.5" 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 = [ dependencies = [
"js_int", "js_int",
"thiserror 2.0.12", "thiserror 2.0.12",
@ -3838,7 +3838,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.9.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3848,7 +3848,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-macros" name = "ruma-macros"
version = "0.13.0" 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 = [ dependencies = [
"cfg-if", "cfg-if",
"proc-macro-crate", "proc-macro-crate",
@ -3863,7 +3863,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.9.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3875,7 +3875,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.15.0" 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 = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"ed25519-dalek", "ed25519-dalek",

View file

@ -350,7 +350,7 @@ version = "0.1.2"
[workspace.dependencies.ruma] [workspace.dependencies.ruma]
git = "https://forgejo.ellis.link/continuwuation/ruwuma" git = "https://forgejo.ellis.link/continuwuation/ruwuma"
#branch = "conduwuit-changes" #branch = "conduwuit-changes"
rev = "781606d1fafbf2daa220fd354d9ad0479a308cd1" rev = "1faaf474b122159a04518214e8248b465dae06c9"
features = [ features = [
"compat", "compat",
"rand", "rand",

View file

@ -1,21 +1,18 @@
use conduwuit::{Err, Result, debug, implement, trace, warn}; use conduwuit::{
use ruma::{ Err, Event, PduEvent, Result, debug, implement, utils::to_canonical_object, warn,
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 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 /// Returns Ok if the policy server allows the event
#[implement(super::Service)] #[implement(super::Service)]
#[tracing::instrument(skip_all, level = "debug")] #[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 let Ok(policyserver) = self
.services .services
.state_accessor .state_accessor
@ -33,10 +30,27 @@ pub async fn policyserv_check(&self, event_id: &EventId, room_id: &RoomId) -> Re
return Ok(()); 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 let response = self
.services .services
.sending .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; .await;
let response = match response { let response = match response {
| Ok(response) => 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" { 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"))); return Err!(Request(Forbidden("Event was marked as spam by policy server")));
}; };

View file

@ -220,7 +220,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu(
&& incoming_pdu.sender().server_name() != self.services.globals.server_name() && incoming_pdu.sender().server_name() != self.services.globals.server_name()
{ {
debug!("Checking policy server for event {}", incoming_pdu.event_id); 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 { if let Err(e) = policy.await {
warn!("Policy server check failed for event {}: {e}", incoming_pdu.event_id); warn!("Policy server check failed for event {}: {e}", incoming_pdu.event_id);
if !soft_fail { if !soft_fail {