aboutsummaryrefslogtreecommitdiff
path: root/src/api/signature/mod.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-03-01 12:35:08 +0100
committerAlex Auvolat <alex@adnab.me>2024-03-01 13:21:23 +0100
commit610af71e36d58ea1ca66b98c75f105aecf92af2b (patch)
tree8181bda3e5837a1a17302aa692c2f1722de99ad5 /src/api/signature/mod.rs
parentf01883794e475f5dae3d2d4f621b020e1134fa47 (diff)
downloadgarage-610af71e36d58ea1ca66b98c75f105aecf92af2b.tar.gz
garage-610af71e36d58ea1ca66b98c75f105aecf92af2b.zip
[backport-735-v0.8.x] backport AWS signature verification refactoring
Diffstat (limited to 'src/api/signature/mod.rs')
-rw-r--r--src/api/signature/mod.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/api/signature/mod.rs b/src/api/signature/mod.rs
index 4b8b990f..e189aeca 100644
--- a/src/api/signature/mod.rs
+++ b/src/api/signature/mod.rs
@@ -2,6 +2,10 @@ use chrono::{DateTime, Utc};
use hmac::{Hmac, Mac};
use sha2::Sha256;
+use hyper::{body::Body, Request};
+
+use garage_model::garage::Garage;
+use garage_model::key_table::Key;
use garage_util::data::{sha256sum, Hash};
pub mod error;
@@ -15,6 +19,27 @@ pub const LONG_DATETIME: &str = "%Y%m%dT%H%M%SZ";
type HmacSha256 = Hmac<Sha256>;
+pub async fn verify_request(
+ garage: &Garage,
+ mut req: Request<Body>,
+ service: &'static str,
+) -> Result<(Request<Body>, Key, Option<Hash>), Error> {
+ let (api_key, mut content_sha256) =
+ payload::check_payload_signature(&garage, &mut req, service).await?;
+ let api_key =
+ api_key.ok_or_else(|| Error::forbidden("Garage does not support anonymous access yet"))?;
+
+ let req = streaming::parse_streaming_body(
+ &api_key,
+ req,
+ &mut content_sha256,
+ &garage.config.s3_api.s3_region,
+ service,
+ )?;
+
+ Ok((req, api_key, content_sha256))
+}
+
pub fn verify_signed_content(expected_sha256: Hash, body: &[u8]) -> Result<(), Error> {
if expected_sha256 != sha256sum(body) {
return Err(Error::bad_request(