Instrument with tracing
This commit is contained in:
+10
-21
@@ -1,15 +1,18 @@
|
||||
use actix_web::{
|
||||
dev::{Payload, Service, ServiceRequest, Transform},
|
||||
http::{Method, StatusCode},
|
||||
http::Method,
|
||||
web::BytesMut,
|
||||
HttpMessage, HttpResponse, ResponseError,
|
||||
HttpMessage,
|
||||
};
|
||||
use futures::{
|
||||
future::{ok, LocalBoxFuture, Ready, TryFutureExt},
|
||||
use futures_util::{
|
||||
future::{LocalBoxFuture, TryFutureExt},
|
||||
stream::{once, TryStreamExt},
|
||||
};
|
||||
use log::{error, info};
|
||||
use std::task::{Context, Poll};
|
||||
use std::{
|
||||
future::{ready, Ready},
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct DebugPayload(pub bool);
|
||||
@@ -18,20 +21,6 @@ pub(crate) struct DebugPayload(pub bool);
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct DebugPayloadMiddleware<S>(bool, S);
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
#[error("Failed to read payload")]
|
||||
pub(crate) struct DebugError;
|
||||
|
||||
impl ResponseError for DebugError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
StatusCode::BAD_REQUEST
|
||||
}
|
||||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::new(self.status_code())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Transform<S, ServiceRequest> for DebugPayload
|
||||
where
|
||||
S: Service<ServiceRequest, Error = actix_web::Error>,
|
||||
@@ -45,7 +34,7 @@ where
|
||||
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
||||
|
||||
fn new_transform(&self, service: S) -> Self::Future {
|
||||
ok(DebugPayloadMiddleware(self.0, service))
|
||||
ready(Ok(DebugPayloadMiddleware(self.0, service)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-14
@@ -1,28 +1,28 @@
|
||||
use crate::{
|
||||
apub::AcceptedActors,
|
||||
data::{ActorCache, State},
|
||||
error::MyError,
|
||||
error::{Error, ErrorKind},
|
||||
requests::Requests,
|
||||
};
|
||||
use activitystreams::{base::BaseExt, uri, url::Url};
|
||||
use actix_web::web;
|
||||
use http_signature_normalization_actix::{prelude::*, verify::DeprecatedAlgorithm};
|
||||
use log::error;
|
||||
use rsa::{hash::Hash, padding::PaddingScheme, pkcs8::FromPublicKey, PublicKey, RsaPublicKey};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct MyVerify(pub Requests, pub ActorCache, pub State);
|
||||
|
||||
impl MyVerify {
|
||||
#[tracing::instrument("Verify signature")]
|
||||
async fn verify(
|
||||
&self,
|
||||
algorithm: Option<Algorithm>,
|
||||
key_id: String,
|
||||
signature: String,
|
||||
signing_string: String,
|
||||
) -> Result<bool, MyError> {
|
||||
) -> Result<bool, Error> {
|
||||
let public_key_id = uri!(key_id);
|
||||
|
||||
let actor_id = if let Some(mut actor_id) = self
|
||||
@@ -32,7 +32,7 @@ impl MyVerify {
|
||||
.await?
|
||||
{
|
||||
if !self.2.db.is_allowed(actor_id.clone()).await? {
|
||||
return Err(MyError::NotAllowed(key_id));
|
||||
return Err(ErrorKind::NotAllowed(key_id).into());
|
||||
}
|
||||
|
||||
actor_id.set_fragment(None);
|
||||
@@ -44,7 +44,7 @@ impl MyVerify {
|
||||
Some(Algorithm::Hs2019) => (),
|
||||
Some(Algorithm::Deprecated(DeprecatedAlgorithm::RsaSha256)) => (),
|
||||
Some(other) => {
|
||||
return Err(MyError::Algorithm(other.to_string()));
|
||||
return Err(ErrorKind::Algorithm(other.to_string()).into());
|
||||
}
|
||||
None => (),
|
||||
};
|
||||
@@ -65,7 +65,7 @@ impl MyVerify {
|
||||
.fetch::<PublicKeyResponse>(public_key_id.as_str())
|
||||
.await?
|
||||
.actor_id()
|
||||
.ok_or_else(|| MyError::MissingId)?
|
||||
.ok_or_else(|| ErrorKind::MissingId)?
|
||||
};
|
||||
|
||||
// Previously we verified the sig from an actor's local cache
|
||||
@@ -106,7 +106,7 @@ async fn do_verify(
|
||||
public_key: &str,
|
||||
signature: String,
|
||||
signing_string: String,
|
||||
) -> Result<(), MyError> {
|
||||
) -> Result<(), Error> {
|
||||
let public_key = RsaPublicKey::from_public_key_pem(public_key)?;
|
||||
|
||||
web::block(move || {
|
||||
@@ -121,7 +121,7 @@ async fn do_verify(
|
||||
&decoded,
|
||||
)?;
|
||||
|
||||
Ok(()) as Result<(), MyError>
|
||||
Ok(()) as Result<(), Error>
|
||||
})
|
||||
.await??;
|
||||
|
||||
@@ -129,7 +129,7 @@ async fn do_verify(
|
||||
}
|
||||
|
||||
impl SignatureVerify for MyVerify {
|
||||
type Error = MyError;
|
||||
type Error = Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<bool, Self::Error>>>>;
|
||||
|
||||
fn signature_verify(
|
||||
@@ -144,10 +144,6 @@ impl SignatureVerify for MyVerify {
|
||||
Box::pin(async move {
|
||||
this.verify(algorithm, key_id, signature, signing_string)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("Failed to verify, {}", e);
|
||||
e
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::{
|
||||
};
|
||||
use actix_web::web::Data;
|
||||
use actix_webfinger::{Resolver, Webfinger};
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
use rsa_magic_public_key::AsMagicPublicKey;
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
pub(crate) struct RelayResolver;
|
||||
|
||||
@@ -13,8 +13,6 @@ pub(crate) struct RelayResolver;
|
||||
#[error("Error resolving webfinger data")]
|
||||
pub(crate) struct RelayError;
|
||||
|
||||
type FutResult<T, E> = dyn Future<Output = Result<T, E>>;
|
||||
|
||||
impl Resolver for RelayResolver {
|
||||
type State = (Data<State>, Data<Config>);
|
||||
type Error = RelayError;
|
||||
@@ -23,7 +21,7 @@ impl Resolver for RelayResolver {
|
||||
account: &str,
|
||||
domain: &str,
|
||||
(state, config): Self::State,
|
||||
) -> Pin<Box<FutResult<Option<Webfinger>, Self::Error>>> {
|
||||
) -> LocalBoxFuture<'static, Result<Option<Webfinger>, Self::Error>> {
|
||||
let domain = domain.to_owned();
|
||||
let account = account.to_owned();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user