From bdc06d8135c8f3d63300df623e7dcc5b20a94efc Mon Sep 17 00:00:00 2001 From: timedout Date: Sun, 1 Nov 2026 04:54:07 +0000 Subject: [PATCH] feat: Remove useless debug PDU commands --- src/admin/debug/commands.rs | 78 +------------------------------------ src/admin/debug/mod.rs | 25 ------------ 2 files changed, 1 insertion(+), 102 deletions(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 7befb08e0..93575ba11 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -2,7 +2,6 @@ use std::{collections::HashMap, time::SystemTime}; use conduwuit::{ Err, Result, - matrix::pdu::PduEvent, utils, utils::{ stream::{IterStream, ReadyExt}, @@ -16,7 +15,7 @@ use resolvematrix::{ server::{MatrixResolver, MatrixResolverBuilder}, }; use ruma::{ - CanonicalJsonObject, EventId, OwnedEventId, OwnedRoomId, OwnedServerName, RoomVersionId, + OwnedRoomId, OwnedServerName, }; use tracing_subscriber::EnvFilter; @@ -28,34 +27,6 @@ impl crate::Context<'_> { self.write_str(&message).await } - pub(super) async fn parse_pdu(&self) -> Result { - if self.body.len() < 2 - || !self.body[0].trim().starts_with("```") - || self.body.last().unwrap_or(&EMPTY).trim() != "```" - { - return Err!("Expected code block in command body. Add --help for details."); - } - - let string = self.body[1..self.body.len().saturating_sub(1)].join("\n"); - let room_version_rules = RoomVersionId::V12.rules().unwrap(); - - match serde_json::from_str(&string) { - | Err(e) => return Err!("Invalid json in command body: {e}"), - | Ok(value) => match ruma::signatures::reference_hash(&value, &room_version_rules) { - | Err(e) => return Err!("Could not parse PDU JSON: {e:?}"), - | Ok(hash) => { - let event_id = EventId::parse(format!("${hash}")); - match serde_json::from_value::(serde_json::to_value(value)?) { - | Err(e) => - return Err!("EventId: {event_id:?}\nCould not parse event: {e}"), - | Ok(pdu) => write!(self, "EventId: {event_id:?}\n{pdu:#?}"), - } - }, - }, - } - .await - } - pub(super) async fn force_device_list_updates(&self) -> Result { // Force E2EE device list updates for all users self.services @@ -120,53 +91,6 @@ impl crate::Context<'_> { Err!("No log level was specified.") } - pub(super) async fn verify_json(&self) -> Result { - if self.body.len() < 2 - || !self.body[0].trim().starts_with("```") - || self.body.last().unwrap_or(&"").trim() != "```" - { - return Err!("Expected code block in command body. Add --help for details."); - } - - let string = self.body[1..self.body.len().checked_sub(1).unwrap()].join("\n"); - let room_version_rules = RoomVersionId::V12.rules().unwrap(); - - match serde_json::from_str::(&string) { - | Err(e) => return Err!("Invalid json: {e}"), - | Ok(value) => match self - .services - .server_keys - .verify_event_json(&value, &room_version_rules) - .await - { - | Err(e) => return Err!("Signature verification failed: {e}"), - | Ok(_) => write!(self, "Signature correct"), - }, - } - .await - } - - pub(super) async fn verify_pdu(&self, event_id: OwnedEventId) -> Result { - use ruma::signatures::Verified; - - let mut event = self.services.rooms.timeline.get_pdu_json(&event_id).await?; - let room_version_rules = RoomVersionId::V12.rules().unwrap(); - - event.remove("event_id"); - let msg = match self - .services - .server_keys - .verify_event_json(&event, &room_version_rules) - .await - { - | Err(e) => return Err(e), - | Ok(Verified::Signatures) => "signatures OK, but content hash failed (redaction).", - | Ok(Verified::All) => "signatures and hashes OK.", - }; - - self.write_str(msg).await - } - pub(super) async fn resolve_true_destination( &self, server_name: OwnedServerName, diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 0337d9359..dcea15fcb 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -16,15 +16,6 @@ pub enum DebugCommand { message: Vec, }, - /// Parse and print a PDU from a JSON - /// - /// The PDU event is only checked for validity and is not added to the - /// database. - /// - /// This command needs a JSON blob provided in a Markdown code block below - /// the command. - ParsePdu, - /// Forces device lists for all local and remote users to be updated (as /// having new keys available) ForceDeviceListUpdates, @@ -41,19 +32,6 @@ pub enum DebugCommand { reset: bool, }, - /// Verify JSON signatures - /// - /// This command needs a JSON blob provided in a Markdown code block below - /// the command. - VerifyJson, - - /// Verify PDU - /// - /// This re-verifies a PDU existing in the database found by ID. - VerifyPdu { - event_id: OwnedEventId, - }, - /// Runs a server name through Continuwuity's true destination resolution /// process /// @@ -81,9 +59,6 @@ pub enum DebugCommand { /// invocation. RuntimeInterval, - /// Print the current time - Time, - /// Get database statistics DatabaseStats { property: Option,