aboutsummaryrefslogtreecommitdiff
path: root/src/api/signature
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-02-05 18:49:54 +0100
committerAlex Auvolat <alex@adnab.me>2024-02-05 18:49:54 +0100
commit0bb5b77530ad432e4c77f13b395fe74613812337 (patch)
tree9734470cff2ba2ce848abc0fdb9b0032c37420b8 /src/api/signature
parent6e69a1fffc715c752a399750c1e26aa46683dbb2 (diff)
downloadgarage-0bb5b77530ad432e4c77f13b395fe74613812337.tar.gz
garage-0bb5b77530ad432e4c77f13b395fe74613812337.zip
[dep-upgrade-202402] wip: port to http/hyper crates v1
Diffstat (limited to 'src/api/signature')
-rw-r--r--src/api/signature/payload.rs4
-rw-r--r--src/api/signature/streaming.rs32
2 files changed, 19 insertions, 17 deletions
diff --git a/src/api/signature/payload.rs b/src/api/signature/payload.rs
index b50fb3bb..652c606e 100644
--- a/src/api/signature/payload.rs
+++ b/src/api/signature/payload.rs
@@ -2,7 +2,7 @@ use std::collections::HashMap;
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
use hmac::Mac;
-use hyper::{Body, Method, Request};
+use hyper::{body::Incoming as IncomingBody, Method, Request};
use sha2::{Digest, Sha256};
use garage_table::*;
@@ -20,7 +20,7 @@ use crate::signature::error::*;
pub async fn check_payload_signature(
garage: &Garage,
service: &'static str,
- request: &Request<Body>,
+ request: &Request<IncomingBody>,
) -> Result<(Option<Key>, Option<Hash>), Error> {
let mut headers = HashMap::new();
for (key, val) in request.headers() {
diff --git a/src/api/signature/streaming.rs b/src/api/signature/streaming.rs
index c8358c4f..8fb0c4ef 100644
--- a/src/api/signature/streaming.rs
+++ b/src/api/signature/streaming.rs
@@ -5,22 +5,26 @@ use futures::prelude::*;
use futures::task;
use garage_model::key_table::Key;
use hmac::Mac;
-use hyper::body::Bytes;
-use hyper::{Body, Request};
+use http_body_util::{BodyStream, StreamBody};
+use hyper::body::{Bytes, Incoming as IncomingBody};
+use hyper::Request;
use garage_util::data::Hash;
use super::{compute_scope, sha256sum, HmacSha256, LONG_DATETIME};
+use crate::helpers::*;
use crate::signature::error::*;
+pub type ReqBody = BoxBody<Error>;
+
pub fn parse_streaming_body(
api_key: &Key,
- req: Request<Body>,
+ req: Request<IncomingBody>,
content_sha256: &mut Option<Hash>,
region: &str,
service: &str,
-) -> Result<Request<Body>, Error> {
+) -> Result<Request<ReqBody>, Error> {
match req.headers().get("x-amz-content-sha256") {
Some(header) if header == "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" => {
let signature = content_sha256
@@ -47,19 +51,17 @@ pub fn parse_streaming_body(
.ok_or_internal_error("Unable to build signing HMAC")?;
Ok(req.map(move |body| {
- Body::wrap_stream(
- SignedPayloadStream::new(
- body.map_err(Error::from),
- signing_hmac,
- date,
- &scope,
- signature,
- )
- .map_err(Error::from),
- )
+ let body_stream = BodyStream::new(body)
+ .map(|x| x.map(|f| f.into_data().unwrap())) //TODO remove unwrap
+ .map_err(Error::from);
+ let signed_payload_stream =
+ SignedPayloadStream::new(body_stream, signing_hmac, date, &scope, signature)
+ .map(|x| x.map(hyper::body::Frame::data))
+ .map_err(Error::from);
+ ReqBody::new(StreamBody::new(signed_payload_stream))
}))
}
- _ => Ok(req),
+ _ => Ok(req.map(|body| ReqBody::new(http_body_util::BodyExt::map_err(body, Error::from)))),
}
}