diff options
author | Alex Auvolat <alex@adnab.me> | 2024-02-27 23:33:26 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-02-28 12:24:21 +0100 |
commit | 4c1d42cc5fcaa69818ec177f19577ad57952a117 (patch) | |
tree | c08428281155d411a7fb90439d83fc90714317e0 /src/api/signature/streaming.rs | |
parent | 2efa9c5a1a568e28e41af790750f224d334d4e3d (diff) | |
download | garage-4c1d42cc5fcaa69818ec177f19577ad57952a117.tar.gz garage-4c1d42cc5fcaa69818ec177f19577ad57952a117.zip |
[fix-presigned] add back anonymous request code path + refactoring
Diffstat (limited to 'src/api/signature/streaming.rs')
-rw-r--r-- | src/api/signature/streaming.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/api/signature/streaming.rs b/src/api/signature/streaming.rs index a2a71f6b..e223d1b1 100644 --- a/src/api/signature/streaming.rs +++ b/src/api/signature/streaming.rs @@ -15,6 +15,11 @@ use super::{compute_scope, sha256sum, HmacSha256, LONG_DATETIME}; use crate::helpers::*; use crate::signature::error::*; +use crate::signature::payload::{ + STREAMING_AWS4_HMAC_SHA256_PAYLOAD, X_AMZ_CONTENT_SH256, X_AMZ_DATE, +}; + +pub const AWS4_HMAC_SHA256_PAYLOAD: &str = "AWS4-HMAC-SHA256-PAYLOAD"; pub type ReqBody = BoxBody<Error>; @@ -25,8 +30,8 @@ pub fn parse_streaming_body( region: &str, service: &str, ) -> Result<Request<ReqBody>, Error> { - match req.headers().get("x-amz-content-sha256") { - Some(header) if header == "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" => { + match req.headers().get(X_AMZ_CONTENT_SH256) { + Some(header) if header == STREAMING_AWS4_HMAC_SHA256_PAYLOAD => { let signature = content_sha256 .take() .ok_or_bad_request("No signature provided")?; @@ -39,7 +44,7 @@ pub fn parse_streaming_body( let date = req .headers() - .get("x-amz-date") + .get(X_AMZ_DATE) .ok_or_bad_request("Missing X-Amz-Date field")? .to_str()?; let date: NaiveDateTime = NaiveDateTime::parse_from_str(date, LONG_DATETIME) @@ -75,7 +80,7 @@ fn compute_streaming_payload_signature( content_sha256: Hash, ) -> Result<Hash, Error> { let string_to_sign = [ - "AWS4-HMAC-SHA256-PAYLOAD", + AWS4_HMAC_SHA256_PAYLOAD, &date.format(LONG_DATETIME).to_string(), scope, &hex::encode(previous_signature), |