fix: make "other" error actually transparent (#51)
* fix: make "other" error actually transparent * cargo fmt
This commit is contained in:
parent
93b7aa7979
commit
b64f4a8f3f
11 changed files with 34 additions and 36 deletions
|
@ -56,7 +56,6 @@ axum = { version = "0.6.18", features = [
|
||||||
], default-features = false, optional = true }
|
], default-features = false, optional = true }
|
||||||
tower = { version = "0.4.13", optional = true }
|
tower = { version = "0.4.13", optional = true }
|
||||||
hyper = { version = "0.14", optional = true }
|
hyper = { version = "0.14", optional = true }
|
||||||
displaydoc = "0.2.4"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["actix-web", "axum"]
|
default = ["actix-web", "axum"]
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::create_post::CreatePost,
|
activities::create_post::CreatePost, database::DatabaseHandle, error::Error,
|
||||||
database::DatabaseHandle,
|
generate_object_id, objects::person::DbUser,
|
||||||
error::Error,
|
|
||||||
generate_object_id,
|
|
||||||
objects::person::DbUser,
|
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::{activities::follow::Follow, instance::DatabaseHandle, objects::person::DbUser};
|
use crate::{activities::follow::Follow, instance::DatabaseHandle, objects::person::DbUser};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data, fetch::object_id::ObjectId, kinds::activity::AcceptType, traits::ActivityHandler,
|
||||||
fetch::object_id::ObjectId,
|
|
||||||
kinds::activity::AcceptType,
|
|
||||||
traits::ActivityHandler,
|
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::accept::Accept,
|
activities::accept::Accept, generate_object_id, instance::DatabaseHandle,
|
||||||
generate_object_id,
|
|
||||||
instance::DatabaseHandle,
|
|
||||||
objects::person::DbUser,
|
objects::person::DbUser,
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
|
|
|
@ -17,8 +17,7 @@ use axum::{
|
||||||
extract::{Path, Query},
|
extract::{Path, Query},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
Json,
|
Json, Router,
|
||||||
Router,
|
|
||||||
};
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
traits::{ActivityHandler, Actor},
|
traits::{ActivityHandler, Actor},
|
||||||
FEDERATION_CONTENT_TYPE,
|
FEDERATION_CONTENT_TYPE,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::{anyhow, Context};
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::Future;
|
use futures_core::Future;
|
||||||
|
@ -77,14 +77,14 @@ where
|
||||||
.unique()
|
.unique()
|
||||||
.filter(|i| !config.is_local_url(i))
|
.filter(|i| !config.is_local_url(i))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// This field is only optional to make builder work, its always present at this point
|
// This field is only optional to make builder work, its always present at this point
|
||||||
let activity_queue = config
|
let activity_queue = config
|
||||||
.activity_queue
|
.activity_queue
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("Config has activity queue");
|
.expect("Config has activity queue");
|
||||||
for inbox in inboxes {
|
for inbox in inboxes {
|
||||||
if config.verify_url_valid(&inbox).await.is_err() {
|
if let Err(err) = config.verify_url_valid(&inbox).await {
|
||||||
|
debug!("inbox url invalid, skipping: {inbox}: {err}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,8 @@ async fn sign_and_send(
|
||||||
task.private_key.clone(),
|
task.private_key.clone(),
|
||||||
task.http_signature_compat,
|
task.http_signature_compat,
|
||||||
)
|
)
|
||||||
.await?;
|
.await
|
||||||
|
.context("signing request")?;
|
||||||
|
|
||||||
retry(
|
retry(
|
||||||
|| {
|
|| {
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
traits::{ActivityHandler, Actor, Object},
|
traits::{ActivityHandler, Actor, Object},
|
||||||
};
|
};
|
||||||
use actix_web::{web::Bytes, HttpRequest, HttpResponse};
|
use actix_web::{web::Bytes, HttpRequest, HttpResponse};
|
||||||
|
use anyhow::Context;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
@ -32,7 +33,8 @@ where
|
||||||
{
|
{
|
||||||
verify_body_hash(request.headers().get("Digest"), &body)?;
|
verify_body_hash(request.headers().get("Digest"), &body)?;
|
||||||
|
|
||||||
let activity: Activity = serde_json::from_slice(&body)?;
|
let activity: Activity = serde_json::from_slice(&body)
|
||||||
|
.with_context(|| format!("deserializing body: {}", String::from_utf8_lossy(&body)))?;
|
||||||
data.config.verify_url_and_domain(&activity).await?;
|
data.config.verify_url_and_domain(&activity).await?;
|
||||||
let actor = ObjectId::<ActorT>::from(activity.actor().clone())
|
let actor = ObjectId::<ActorT>::from(activity.actor().clone())
|
||||||
.dereference(data)
|
.dereference(data)
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
use crate::config::{Data, FederationConfig, FederationMiddleware};
|
use crate::config::{Data, FederationConfig, FederationMiddleware};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
dev::{forward_ready, Payload, Service, ServiceRequest, ServiceResponse, Transform},
|
dev::{forward_ready, Payload, Service, ServiceRequest, ServiceResponse, Transform},
|
||||||
Error,
|
Error, FromRequest, HttpMessage, HttpRequest,
|
||||||
FromRequest,
|
|
||||||
HttpMessage,
|
|
||||||
HttpRequest,
|
|
||||||
};
|
};
|
||||||
use std::future::{ready, Ready};
|
use std::future::{ready, Ready};
|
||||||
|
|
||||||
|
|
16
src/error.rs
16
src/error.rs
|
@ -1,27 +1,33 @@
|
||||||
//! Error messages returned by this library
|
//! Error messages returned by this library
|
||||||
|
|
||||||
use displaydoc::Display;
|
|
||||||
|
|
||||||
/// Error messages returned by this library
|
/// Error messages returned by this library
|
||||||
#[derive(thiserror::Error, Debug, Display)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Object was not found in local database
|
/// Object was not found in local database
|
||||||
|
#[error("Object was not found in local database")]
|
||||||
NotFound,
|
NotFound,
|
||||||
/// Request limit was reached during fetch
|
/// Request limit was reached during fetch
|
||||||
|
#[error("Request limit was reached during fetch")]
|
||||||
RequestLimit,
|
RequestLimit,
|
||||||
/// Response body limit was reached during fetch
|
/// Response body limit was reached during fetch
|
||||||
|
#[error("Response body limit was reached during fetch")]
|
||||||
ResponseBodyLimit,
|
ResponseBodyLimit,
|
||||||
/// Object to be fetched was deleted
|
/// Object to be fetched was deleted
|
||||||
|
#[error("Object to be fetched was deleted")]
|
||||||
ObjectDeleted,
|
ObjectDeleted,
|
||||||
/// {0}
|
/// url verification error
|
||||||
|
#[error("{0}")]
|
||||||
UrlVerificationError(&'static str),
|
UrlVerificationError(&'static str),
|
||||||
/// Incoming activity has invalid digest for body
|
/// Incoming activity has invalid digest for body
|
||||||
|
#[error("Incoming activity has invalid digest for body")]
|
||||||
ActivityBodyDigestInvalid,
|
ActivityBodyDigestInvalid,
|
||||||
/// Incoming activity has invalid signature
|
/// Incoming activity has invalid signature
|
||||||
|
#[error("Incoming activity has invalid signature")]
|
||||||
ActivitySignatureInvalid,
|
ActivitySignatureInvalid,
|
||||||
/// Failed to resolve actor via webfinger
|
/// Failed to resolve actor via webfinger
|
||||||
|
#[error("Failed to resolve actor via webfinger")]
|
||||||
WebfingerResolveFailed,
|
WebfingerResolveFailed,
|
||||||
/// Other errors which are not explicitly handled
|
/// other error
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Other(#[from] anyhow::Error),
|
Other(#[from] anyhow::Error),
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,7 @@
|
||||||
#![doc = include_str!("../../docs/07_fetching_data.md")]
|
#![doc = include_str!("../../docs/07_fetching_data.md")]
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Data,
|
config::Data, error::Error, http_signatures::sign_request, reqwest_shim::ResponseExt,
|
||||||
error::Error,
|
|
||||||
http_signatures::sign_request,
|
|
||||||
reqwest_shim::ResponseExt,
|
|
||||||
FEDERATION_CONTENT_TYPE,
|
FEDERATION_CONTENT_TYPE,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
protocol::public_key::main_key_id,
|
protocol::public_key::main_key_id,
|
||||||
traits::{Actor, Object},
|
traits::{Actor, Object},
|
||||||
};
|
};
|
||||||
|
use anyhow::Context;
|
||||||
use base64::{engine::general_purpose::STANDARD as Base64, Engine};
|
use base64::{engine::general_purpose::STANDARD as Base64, Engine};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use http::{header::HeaderName, uri::PathAndQuery, HeaderValue, Method, Uri};
|
use http::{header::HeaderName, uri::PathAndQuery, HeaderValue, Method, Uri};
|
||||||
|
@ -102,10 +103,14 @@ pub(crate) async fn sign_request(
|
||||||
Sha256::new(),
|
Sha256::new(),
|
||||||
activity,
|
activity,
|
||||||
move |signing_string| {
|
move |signing_string| {
|
||||||
let mut signer = Signer::new(MessageDigest::sha256(), &private_key)?;
|
let mut signer = Signer::new(MessageDigest::sha256(), &private_key)
|
||||||
signer.update(signing_string.as_bytes())?;
|
.context("instantiating signer")?;
|
||||||
|
signer
|
||||||
|
.update(signing_string.as_bytes())
|
||||||
|
.context("updating signer")?;
|
||||||
|
|
||||||
Ok(Base64.encode(signer.sign_to_vec()?)) as Result<_, anyhow::Error>
|
Ok(Base64.encode(signer.sign_to_vec().context("sign to vec")?))
|
||||||
|
as Result<_, anyhow::Error>
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue