From 86fb7bbba5aefc797f359bd84676637f0232b709 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 8 Jul 2020 13:33:02 +0200 Subject: [PATCH] Apply cargo fmt; add trace output when request signature is bad --- src/api/api_server.rs | 5 +---- src/api/s3_delete.rs | 4 +--- src/api/s3_get.rs | 10 ++++------ src/api/signature.rs | 3 +++ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/api/api_server.rs b/src/api/api_server.rs index 92a9f2a6..8ace2b52 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -67,10 +67,7 @@ async fn handler( } } -async fn handler_inner( - garage: Arc, - req: Request, -) -> Result, Error> { +async fn handler_inner(garage: Arc, req: Request) -> Result, Error> { let path = req.uri().path().to_string(); let path = percent_encoding::percent_decode_str(&path).decode_utf8()?; diff --git a/src/api/s3_delete.rs b/src/api/s3_delete.rs index 91e5e20d..949ad6a1 100644 --- a/src/api/s3_delete.rs +++ b/src/api/s3_delete.rs @@ -129,9 +129,7 @@ pub async fn handle_delete_objects( writeln!(&mut retxml, "").unwrap(); - Ok(Response::new(Body::from( - retxml.into_bytes(), - ))) + Ok(Response::new(Body::from(retxml.into_bytes()))) } struct DeleteRequest { diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs index 5f2151b5..42cf55d1 100644 --- a/src/api/s3_get.rs +++ b/src/api/s3_get.rs @@ -146,7 +146,7 @@ pub async fn handle_get( }) .buffered(2); //let body: Body = Box::new(StreamBody::new(Box::pin(body_stream))); - let body = hyper::body::Body::wrap_stream(body_stream); + let body = hyper::body::Body::wrap_stream(body_stream); Ok(resp_builder.body(body)?) } } @@ -176,9 +176,7 @@ pub async fn handle_get_range( ObjectVersionData::DeleteMarker => Err(Error::NotFound), ObjectVersionData::Inline(bytes) => { if end as usize <= bytes.len() { - let body: Body = Body::from( - bytes[begin as usize..end as usize].to_vec(), - ); + let body: Body = Body::from(bytes[begin as usize..end as usize].to_vec()); Ok(resp_builder.body(body)?) } else { Err(Error::Message(format!("Internal error: requested range not present in inline bytes when it should have been"))) @@ -213,14 +211,14 @@ pub async fn handle_get_range( } else { end - block.offset }; - Result::::Ok(Bytes::from( + Result::::Ok(Bytes::from( data[start_in_block as usize..end_in_block as usize].to_vec(), )) } }) .buffered(2); //let body: Body = Box::new(StreamBody::new(Box::pin(body_stream))); - let body = hyper::body::Body::wrap_stream(body_stream); + let body = hyper::body::Body::wrap_stream(body_stream); Ok(resp_builder.body(body)?) } } diff --git a/src/api/signature.rs b/src/api/signature.rs index 65f31f21..798ba7fb 100644 --- a/src/api/signature.rs +++ b/src/api/signature.rs @@ -91,6 +91,9 @@ pub async fn check_signature(garage: &Garage, request: &Request) -> Result let signature = hex::encode(hmac.result().code()); if authorization.signature != signature { + trace!("Canonical request: ``{}``", canonical_request); + trace!("String to sign: ``{}``", string_to_sign); + trace!("Expected: {}, got: {}", signature, authorization.signature); return Err(Error::Forbidden(format!("Invalid signature"))); }