update
This commit is contained in:
parent
00dd6e6b8d
commit
7b4a30f30a
8 changed files with 24 additions and 19 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -11,3 +11,5 @@ flamegraph.svg
|
||||||
# nix flake
|
# nix flake
|
||||||
/flake.nix
|
/flake.nix
|
||||||
/flake.lock
|
/flake.lock
|
||||||
|
|
||||||
|
.vscode
|
||||||
14
Cargo.toml
14
Cargo.toml
|
|
@ -47,7 +47,7 @@ tracing = "0.1.40"
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rsa = "0.9.6"
|
rsa = "0.9.6"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.20.1"
|
||||||
http = "1.1.0"
|
http = "1.1.0"
|
||||||
sha2 = { version = "0.10.8", features = ["oid"] }
|
sha2 = { version = "0.10.8", features = ["oid"] }
|
||||||
thiserror = "1.0.63"
|
thiserror = "1.0.63"
|
||||||
|
|
@ -63,15 +63,15 @@ http-signature-normalization-reqwest = { version = "0.12.0", default-features =
|
||||||
"default-spawner",
|
"default-spawner",
|
||||||
] }
|
] }
|
||||||
http-signature-normalization = "0.7.0"
|
http-signature-normalization = "0.7.0"
|
||||||
bytes = "1.6.1"
|
bytes = "1.7.2"
|
||||||
futures-core = { version = "0.3.30", default-features = false }
|
futures-core = { version = "0.3.30", default-features = false }
|
||||||
pin-project-lite = "0.2.14"
|
pin-project-lite = "0.2.14"
|
||||||
activitystreams-kinds = "0.3.0"
|
activitystreams-kinds = "0.3.0"
|
||||||
regex = { version = "1.10.5", default-features = false, features = [
|
regex = { version = "1.11.0", default-features = false, features = [
|
||||||
"std",
|
"std",
|
||||||
"unicode",
|
"unicode",
|
||||||
] }
|
] }
|
||||||
tokio = { version = "1.38.0", features = [
|
tokio = { version = "1.40.0", features = [
|
||||||
"sync",
|
"sync",
|
||||||
"rt",
|
"rt",
|
||||||
"rt-multi-thread",
|
"rt-multi-thread",
|
||||||
|
|
@ -90,21 +90,21 @@ actix-web = { version = "4.8.0", default-features = false, optional = true }
|
||||||
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
|
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
|
||||||
"json",
|
"json",
|
||||||
], default-features = false, optional = true }
|
], default-features = false, optional = true }
|
||||||
tower = { version = "0.4.13", optional = true }
|
tower = { version = "0.5.1", optional = true }
|
||||||
hyper = { version = "1.4.1", optional = true }
|
hyper = { version = "1.4.1", optional = true }
|
||||||
http-body-util = { version = "0.1.2", optional = true }
|
http-body-util = { version = "0.1.2", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11.3"
|
||||||
tower-http = { version = "0.5.2", features = ["map-request-body", "util"] }
|
tower-http = { version = "0.6.1", features = ["map-request-body", "util"] }
|
||||||
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
|
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
|
||||||
"http1",
|
"http1",
|
||||||
"tokio",
|
"tokio",
|
||||||
"query",
|
"query",
|
||||||
], default-features = false }
|
], default-features = false }
|
||||||
axum-macros = { git = "https://github.com/tokio-rs/axum.git" }
|
axum-macros = { git = "https://github.com/tokio-rs/axum.git" }
|
||||||
tokio = { version = "1.38.1", features = ["full"] }
|
tokio = { version = "1.40.0", features = ["full"] }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,16 @@ where
|
||||||
.headers()
|
.headers()
|
||||||
.get("Digest")
|
.get("Digest")
|
||||||
.map(|v| reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()))
|
.map(|v| reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()))
|
||||||
.and_then(|v| v.ok());
|
.and_then(std::result::Result::ok);
|
||||||
verify_body_hash(header_value.as_ref(), &body)?;
|
verify_body_hash(header_value.as_ref(), &body)?;
|
||||||
|
|
||||||
let (activity, actor) = parse_received_activity::<Activity, ActorT, _>(&body, data).await?;
|
let (activity, actor) = parse_received_activity::<Activity, ActorT, _>(&body, data).await?;
|
||||||
|
|
||||||
let mut vec = Vec::<(_, _)>::with_capacity(request.headers().len());
|
let mut vec = Vec::<(_, _)>::with_capacity(request.headers().len());
|
||||||
request.headers().iter().for_each(|(k, v)| {
|
request.headers().iter().for_each(|(k, v)| {
|
||||||
let k = reqwest::header::HeaderName::from_str(k.as_str()).unwrap();
|
let k = reqwest::header::HeaderName::from_str(k.as_str()).expect("Failed to parse header");
|
||||||
let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()).unwrap();
|
let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default())
|
||||||
|
.expect("Failed to parse header");
|
||||||
vec.push((k, v));
|
vec.push((k, v));
|
||||||
});
|
});
|
||||||
let headers = vec.iter().map(|(k, v)| (k, v)).collect::<Vec<(_, _)>>();
|
let headers = vec.iter().map(|(k, v)| (k, v)).collect::<Vec<(_, _)>>();
|
||||||
|
|
@ -49,7 +50,8 @@ where
|
||||||
headers,
|
headers,
|
||||||
&reqwest::Method::from_str(request.method().as_str())
|
&reqwest::Method::from_str(request.method().as_str())
|
||||||
.map_err(|err| Error::Other(err.to_string()))?,
|
.map_err(|err| Error::Other(err.to_string()))?,
|
||||||
&http::Uri::from_str(&request.uri().to_string()).unwrap(),
|
&http::Uri::from_str(&request.uri().to_string())
|
||||||
|
.map_err(|err| Error::Other(err.to_string()))?,
|
||||||
actor.public_key_pem(),
|
actor.public_key_pem(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,14 @@ where
|
||||||
.headers()
|
.headers()
|
||||||
.get("Digest")
|
.get("Digest")
|
||||||
.map(|v| reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()))
|
.map(|v| reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()))
|
||||||
.and_then(|v| v.ok());
|
.and_then(std::result::Result::ok);
|
||||||
verify_body_hash(header_value.as_ref(), &body.unwrap_or_default())?;
|
verify_body_hash(header_value.as_ref(), &body.unwrap_or_default())?;
|
||||||
|
|
||||||
let mut vec = Vec::<(_, _)>::with_capacity(request.headers().len());
|
let mut vec = Vec::<(_, _)>::with_capacity(request.headers().len());
|
||||||
request.headers().iter().for_each(|(k, v)| {
|
request.headers().iter().for_each(|(k, v)| {
|
||||||
let k = reqwest::header::HeaderName::from_str(k.as_str()).unwrap();
|
let k = reqwest::header::HeaderName::from_str(k.as_str()).expect("Failed to parse header");
|
||||||
let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()).unwrap();
|
let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default())
|
||||||
|
.expect("Failed to parse header");
|
||||||
vec.push((k, v));
|
vec.push((k, v));
|
||||||
});
|
});
|
||||||
let headers = vec.iter().map(|(k, v)| (k, v)).collect::<Vec<(_, _)>>();
|
let headers = vec.iter().map(|(k, v)| (k, v)).collect::<Vec<(_, _)>>();
|
||||||
|
|
@ -45,7 +46,8 @@ where
|
||||||
headers,
|
headers,
|
||||||
&reqwest::Method::from_str(request.method().as_str())
|
&reqwest::Method::from_str(request.method().as_str())
|
||||||
.map_err(|err| Error::Other(err.to_string()))?,
|
.map_err(|err| Error::Other(err.to_string()))?,
|
||||||
&http::Uri::from_str(&request.uri().to_string()).unwrap(),
|
&http::Uri::from_str(&request.uri().to_string())
|
||||||
|
.map_err(|err| Error::Other(err.to_string()))?,
|
||||||
data,
|
data,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ use crate::{
|
||||||
traits::{ActivityHandler, Actor, Object},
|
traits::{ActivityHandler, Actor, Object},
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
async_trait,
|
|
||||||
extract::{FromRequest, Request},
|
extract::{FromRequest, Request},
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
|
|
@ -58,7 +57,6 @@ pub struct ActivityData {
|
||||||
body: Vec<u8>,
|
body: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl<S> FromRequest<S> for ActivityData
|
impl<S> FromRequest<S> for ActivityData
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::config::{Data, FederationConfig, FederationMiddleware};
|
use crate::config::{Data, FederationConfig, FederationMiddleware};
|
||||||
use axum::{async_trait, body::Body, extract::FromRequestParts, http::Request, response::Response};
|
use axum::{body::Body, extract::FromRequestParts, http::Request, response::Response};
|
||||||
use http::{request::Parts, StatusCode};
|
use http::{request::Parts, StatusCode};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tower::{Layer, Service};
|
use tower::{Layer, Service};
|
||||||
|
|
@ -43,7 +43,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl<S, T: Clone + 'static> FromRequestParts<S> for Data<T>
|
impl<S, T: Clone + 'static> FromRequestParts<S> for Data<T>
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,7 @@ const _IMPL_DIESEL_NEW_TYPE_FOR_OBJECT_ID: () = {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(clippy::unwrap_used)]
|
#[allow(clippy::unwrap_used)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::traits::tests::DbUser;
|
use crate::traits::tests::DbUser;
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,7 @@ pub(crate) fn verify_body_hash(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(clippy::unwrap_used)]
|
#[allow(clippy::unwrap_used)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub mod test {
|
pub mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::activity_sending::generate_request_headers;
|
use crate::activity_sending::generate_request_headers;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue