From 05ad7b2f3a12c5324b5d9400e095052676c917f1 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 15 Nov 2022 23:18:28 +0100 Subject: [PATCH] Revert change to take payload in inbox, it wasnt necessary. --- Cargo.lock | 2 +- examples/federation/instance.rs | 7 ++++--- src/core/inbox.rs | 17 ++++------------- src/traits.rs | 4 ++-- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aaf210f..4b1ad3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "activitypub_federation" -version = "0.3.0" +version = "0.3.1" dependencies = [ "activitystreams-kinds", "actix-rt", diff --git a/examples/federation/instance.rs b/examples/federation/instance.rs index b1c69f7..1e12ea2 100644 --- a/examples/federation/instance.rs +++ b/examples/federation/instance.rs @@ -16,7 +16,7 @@ use activitypub_federation::{ UrlVerifier, APUB_JSON_CONTENT_TYPE, }; -use actix_web::{web, web::Payload, App, HttpRequest, HttpResponse, HttpServer}; +use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer}; use async_trait::async_trait; use http_signature_normalization_actix::prelude::VerifyDigest; use reqwest::Client; @@ -124,13 +124,14 @@ async fn http_get_user( /// Handles messages received in user inbox async fn http_post_user_inbox( request: HttpRequest, - payload: Payload, + payload: String, data: web::Data, ) -> Result { let data: InstanceHandle = data.into_inner().deref().clone(); + let activity = serde_json::from_str(&payload)?; receive_activity::, MyUser, InstanceHandle>( request, - payload.into_inner(), + activity, &data.clone().local_instance, &Data::new(data), ) diff --git a/src/core/inbox.rs b/src/core/inbox.rs index dbf3509..5241f51 100644 --- a/src/core/inbox.rs +++ b/src/core/inbox.rs @@ -6,16 +6,15 @@ use crate::{ Error, LocalInstance, }; -use actix_web::{dev::Payload, web::Bytes, FromRequest, HttpRequest, HttpResponse}; -use anyhow::anyhow; +use actix_web::{dev::Payload, FromRequest, HttpRequest, HttpResponse}; use http_signature_normalization_actix::prelude::DigestVerified; use serde::de::DeserializeOwned; -use tracing::{log::debug, warn}; +use tracing::log::debug; /// Receive an activity and perform some basic checks, including HTTP signature verification. pub async fn receive_activity( request: HttpRequest, - mut payload: Payload, + activity: Activity, local_instance: &LocalInstance, data: &Data, ) -> Result::Error> @@ -31,15 +30,7 @@ where ::Error: From + From, { // ensure that payload hash was checked against digest header by middleware - DigestVerified::from_request(&request, &mut payload).await?; - - let bytes = Bytes::from_request(&request, &mut payload) - .await - .map_err(|e| { - warn!("{}", e); - anyhow!("Failed to parse request body") - })?; - let activity: Activity = serde_json::from_slice(&bytes)?; + DigestVerified::from_request(&request, &mut Payload::None).await?; verify_domains_match(activity.id(), activity.actor())?; verify_url_valid(activity.id(), &local_instance.settings).await?; diff --git a/src/traits.rs b/src/traits.rs index dd39d04..1ff9b67 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -55,7 +55,7 @@ where data: &Data, request_counter: &mut i32, ) -> Result<(), Self::Error> { - self.verify(data, request_counter).await + self.deref().verify(data, request_counter).await } async fn receive( @@ -63,7 +63,7 @@ where data: &Data, request_counter: &mut i32, ) -> Result<(), Self::Error> { - self.receive(data, request_counter).await + (*self).receive(data, request_counter).await } }