fix(crypto): K-02 — format v3 chunk replay protection with generation aad
This commit is contained in:
+7
-6
@@ -301,6 +301,7 @@ pub fn verify_container(
|
||||
&record.nonce,
|
||||
&record.tag,
|
||||
format_version,
|
||||
record.generation,
|
||||
) {
|
||||
Ok(plaintext) => {
|
||||
report.total_bytes_decrypted += plaintext.len() as u64;
|
||||
@@ -373,12 +374,12 @@ mod tests {
|
||||
|
||||
// 2 Chunks schreiben
|
||||
let chunk0_data = b"Sample JPEG data header and pixels";
|
||||
let (ct0, n0, t0) = encrypt_chunk(&dek, file.id, 0, chunk0_data, FORMAT_VERSION).unwrap();
|
||||
db.write_chunk(file.id, 0, &n0, &t0, &ct0).unwrap();
|
||||
let (ct0, n0, t0) = encrypt_chunk(&dek, file.id, 0, chunk0_data, FORMAT_VERSION, 0).unwrap();
|
||||
db.write_chunk(file.id, 0, 0, &n0, &t0, &ct0).unwrap();
|
||||
|
||||
let chunk1_data = b"Additional payload data bytes";
|
||||
let (ct1, n1, t1) = encrypt_chunk(&dek, file.id, 1, chunk1_data, FORMAT_VERSION).unwrap();
|
||||
db.write_chunk(file.id, 1, &n1, &t1, &ct1).unwrap();
|
||||
let (ct1, n1, t1) = encrypt_chunk(&dek, file.id, 1, chunk1_data, FORMAT_VERSION, 0).unwrap();
|
||||
db.write_chunk(file.id, 1, 0, &n1, &t1, &ct1).unwrap();
|
||||
|
||||
db.update_node_size_and_time(
|
||||
file.id,
|
||||
@@ -432,8 +433,8 @@ mod tests {
|
||||
|
||||
let file = db.create_node(1, "document.pdf", false).unwrap();
|
||||
let chunk_data = b"Vital documents that must not be corrupted";
|
||||
let (ct, n, t) = encrypt_chunk(&dek, file.id, 0, chunk_data, FORMAT_VERSION).unwrap();
|
||||
db.write_chunk(file.id, 0, &n, &t, &ct).unwrap();
|
||||
let (ct, n, t) = encrypt_chunk(&dek, file.id, 0, chunk_data, FORMAT_VERSION, 0).unwrap();
|
||||
db.write_chunk(file.id, 0, 0, &n, &t, &ct).unwrap();
|
||||
db.checkpoint().unwrap();
|
||||
drop(db);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user