mirror of
https://github.com/LemmyNet/activitypub-federation-rust
synced 2024-12-12 13:02:28 +00:00
Revert change to take payload in inbox, it wasnt necessary.
This commit is contained in:
parent
8ee52826a1
commit
05ad7b2f3a
4 changed files with 11 additions and 19 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "activitypub_federation"
|
name = "activitypub_federation"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitystreams-kinds",
|
"activitystreams-kinds",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
|
|
|
@ -16,7 +16,7 @@ use activitypub_federation::{
|
||||||
UrlVerifier,
|
UrlVerifier,
|
||||||
APUB_JSON_CONTENT_TYPE,
|
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 async_trait::async_trait;
|
||||||
use http_signature_normalization_actix::prelude::VerifyDigest;
|
use http_signature_normalization_actix::prelude::VerifyDigest;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
@ -124,13 +124,14 @@ async fn http_get_user(
|
||||||
/// Handles messages received in user inbox
|
/// Handles messages received in user inbox
|
||||||
async fn http_post_user_inbox(
|
async fn http_post_user_inbox(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
payload: Payload,
|
payload: String,
|
||||||
data: web::Data<InstanceHandle>,
|
data: web::Data<InstanceHandle>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let data: InstanceHandle = data.into_inner().deref().clone();
|
let data: InstanceHandle = data.into_inner().deref().clone();
|
||||||
|
let activity = serde_json::from_str(&payload)?;
|
||||||
receive_activity::<WithContext<PersonAcceptedActivities>, MyUser, InstanceHandle>(
|
receive_activity::<WithContext<PersonAcceptedActivities>, MyUser, InstanceHandle>(
|
||||||
request,
|
request,
|
||||||
payload.into_inner(),
|
activity,
|
||||||
&data.clone().local_instance,
|
&data.clone().local_instance,
|
||||||
&Data::new(data),
|
&Data::new(data),
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,16 +6,15 @@ use crate::{
|
||||||
Error,
|
Error,
|
||||||
LocalInstance,
|
LocalInstance,
|
||||||
};
|
};
|
||||||
use actix_web::{dev::Payload, web::Bytes, FromRequest, HttpRequest, HttpResponse};
|
use actix_web::{dev::Payload, FromRequest, HttpRequest, HttpResponse};
|
||||||
use anyhow::anyhow;
|
|
||||||
use http_signature_normalization_actix::prelude::DigestVerified;
|
use http_signature_normalization_actix::prelude::DigestVerified;
|
||||||
use serde::de::DeserializeOwned;
|
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.
|
/// Receive an activity and perform some basic checks, including HTTP signature verification.
|
||||||
pub async fn receive_activity<Activity, ActorT, Datatype>(
|
pub async fn receive_activity<Activity, ActorT, Datatype>(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
mut payload: Payload,
|
activity: Activity,
|
||||||
local_instance: &LocalInstance,
|
local_instance: &LocalInstance,
|
||||||
data: &Data<Datatype>,
|
data: &Data<Datatype>,
|
||||||
) -> Result<HttpResponse, <Activity as ActivityHandler>::Error>
|
) -> Result<HttpResponse, <Activity as ActivityHandler>::Error>
|
||||||
|
@ -31,15 +30,7 @@ where
|
||||||
<ActorT as ApubObject>::Error: From<Error> + From<anyhow::Error>,
|
<ActorT as ApubObject>::Error: From<Error> + From<anyhow::Error>,
|
||||||
{
|
{
|
||||||
// ensure that payload hash was checked against digest header by middleware
|
// ensure that payload hash was checked against digest header by middleware
|
||||||
DigestVerified::from_request(&request, &mut payload).await?;
|
DigestVerified::from_request(&request, &mut Payload::None).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)?;
|
|
||||||
|
|
||||||
verify_domains_match(activity.id(), activity.actor())?;
|
verify_domains_match(activity.id(), activity.actor())?;
|
||||||
verify_url_valid(activity.id(), &local_instance.settings).await?;
|
verify_url_valid(activity.id(), &local_instance.settings).await?;
|
||||||
|
|
|
@ -55,7 +55,7 @@ where
|
||||||
data: &Data<Self::DataType>,
|
data: &Data<Self::DataType>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
self.verify(data, request_counter).await
|
self.deref().verify(data, request_counter).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn receive(
|
async fn receive(
|
||||||
|
@ -63,7 +63,7 @@ where
|
||||||
data: &Data<Self::DataType>,
|
data: &Data<Self::DataType>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
self.receive(data, request_counter).await
|
(*self).receive(data, request_counter).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue