summaryrefslogtreecommitdiff
path: root/src/client.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-01-04 18:57:49 +0200
committerLars Wirzenius <liw@liw.fi>2021-01-04 20:02:06 +0200
commit8efabc60f87e5462b01f4832d575f68382929624 (patch)
tree422b3941b6867871486df2198aef0e431c6b95ac /src/client.rs
parent650b7cee5700eae9ab6c300fbdb816dead6f01f5 (diff)
downloadobnam2-8efabc60f87e5462b01f4832d575f68382929624.tar.gz
feat: verify checksum of chunks downloaded from server
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/client.rs b/src/client.rs
index 616ceef..6b1bb80 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -4,6 +4,7 @@ use crate::chunk::GenerationChunk;
use crate::chunker::Chunker;
use crate::chunkid::ChunkId;
use crate::chunkmeta::ChunkMeta;
+use crate::error::ObnamError;
use crate::fsentry::{FilesystemEntry, FilesystemKind};
use crate::generation::{FinishedGeneration, LocalGeneration};
use crate::genlist::GenerationList;
@@ -212,8 +213,24 @@ impl BackupClient {
return Err(ClientError::ChunkNotFound(chunk_id.to_string()).into());
}
+ let headers = res.headers();
+ let meta = headers.get("chunk-meta");
+ if meta.is_none() {
+ return Err(ObnamError::NoChunkMeta(chunk_id.to_string()).into());
+ }
+ let meta = meta.unwrap().to_str()?;
+ let meta: ChunkMeta = serde_json::from_str(meta)?;
+
let body = res.bytes()?;
- Ok(DataChunk::new(body.to_vec()))
+ let body = body.to_vec();
+ let actual = sha256(&body);
+ if actual != meta.sha256() {
+ return Err(ObnamError::WrongChecksum(chunk_id.to_string()).into());
+ }
+
+ let chunk: DataChunk = DataChunk::new(body);
+
+ Ok(chunk)
}
fn fetch_generation_chunk(&self, gen_id: &str) -> anyhow::Result<GenerationChunk> {