aboutsummaryrefslogtreecommitdiff
path: root/src/api/common/signature/body.rs
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-02-18 13:59:43 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-02-18 15:33:42 +0100
commit730bfee753c4f22cd0595d9195222de334ec36f9 (patch)
tree10cae28065967f82adcb145e027c15c38b9502be /src/api/common/signature/body.rs
parentccab0e4ae5c083d0a06ad2b3ef5fe62481da3c2c (diff)
downloadgarage-730bfee753c4f22cd0595d9195222de334ec36f9.tar.gz
garage-730bfee753c4f22cd0595d9195222de334ec36f9.zip
api: validate trailing checksum + add test for unsigned-paylad-trailer
Diffstat (limited to 'src/api/common/signature/body.rs')
-rw-r--r--src/api/common/signature/body.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/api/common/signature/body.rs b/src/api/common/signature/body.rs
index 512d02b3..4279d7b5 100644
--- a/src/api/common/signature/body.rs
+++ b/src/api/common/signature/body.rs
@@ -17,6 +17,7 @@ pub struct ReqBody {
pub(crate) stream: Mutex<BoxStream<'static, Result<Frame<Bytes>, Error>>>,
pub(crate) checksummer: Checksummer,
pub(crate) expected_checksums: ExpectedChecksums,
+ pub(crate) trailer_algorithm: Option<ChecksumAlgorithm>,
}
pub type StreamingChecksumReceiver = task::JoinHandle<Result<Checksums, Error>>;
@@ -74,6 +75,7 @@ impl ReqBody {
stream,
mut checksummer,
mut expected_checksums,
+ trailer_algorithm,
} = self;
let (frame_tx, mut frame_rx) = mpsc::channel::<Frame<Bytes>>(1);
@@ -91,18 +93,21 @@ impl ReqBody {
}
Err(frame) => {
let trailers = frame.into_trailers().unwrap();
- if let Some(cv) = request_checksum_value(&trailers)? {
- expected_checksums.extra = Some(cv);
- }
+ let algo = trailer_algorithm.unwrap();
+ expected_checksums.extra = Some(extract_checksum_value(&trailers, algo)?);
break;
}
}
}
+ if trailer_algorithm.is_some() && expected_checksums.extra.is_none() {
+ return Err(Error::bad_request("trailing checksum was not sent"));
+ }
+
let checksums = checksummer.finalize();
checksums.verify(&expected_checksums)?;
- return Ok(checksums);
+ Ok(checksums)
});
let stream: BoxStream<_> = stream.into_inner().unwrap();