From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 8695E68EB2 for ; Mon, 3 Aug 2020 14:10:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8423B2DB56 for ; Mon, 3 Aug 2020 14:10:59 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id ECA762DB4C for ; Mon, 3 Aug 2020 14:10:58 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B985D43390 for ; Mon, 3 Aug 2020 14:10:58 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Mon, 3 Aug 2020 14:10:44 +0200 Message-Id: <20200803121046.3623216-3-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200803121046.3623216-1-f.gruenbichler@proxmox.com> References: <20200803121046.3623216-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.044 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 2/4] sync: verify chunk size and digest, if possible X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Aug 2020 12:10:59 -0000 for encrypted chunks this is currently not possible, as we need the key to decode the chunk. Signed-off-by: Fabian Grünbichler --- src/client/pull.rs | 10 ++++++---- src/client/remote_chunk_reader.rs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/client/pull.rs b/src/client/pull.rs index fc193a8d..629e8266 100644 --- a/src/client/pull.rs +++ b/src/client/pull.rs @@ -27,16 +27,18 @@ async fn pull_index_chunks( for pos in 0..index.index_count() { - let digest = index.index_digest(pos).unwrap(); - let chunk_exists = target.cond_touch_chunk(digest, false)?; + let info = index.chunk_info(pos).unwrap(); + let chunk_exists = target.cond_touch_chunk(&info.digest, false)?; if chunk_exists { //worker.log(format!("chunk {} exists {}", pos, proxmox::tools::digest_to_hex(digest))); continue; } //worker.log(format!("sync {} chunk {}", pos, proxmox::tools::digest_to_hex(digest))); - let chunk = chunk_reader.read_raw_chunk(&digest).await?; + let chunk = chunk_reader.read_raw_chunk(&info.digest).await?; - target.insert_chunk(&chunk, &digest)?; + chunk.verify_unencrypted(info.size() as usize, &info.digest)?; + + target.insert_chunk(&chunk, &info.digest)?; } Ok(()) diff --git a/src/client/remote_chunk_reader.rs b/src/client/remote_chunk_reader.rs index 4db11477..b30d0567 100644 --- a/src/client/remote_chunk_reader.rs +++ b/src/client/remote_chunk_reader.rs @@ -35,6 +35,8 @@ impl RemoteChunkReader { } } + /// Downloads raw chunk. This only verifies the (untrusted) CRC32, use + /// DataBlob::verify_unencrypted or DataBlob::decode before storing/processing further. pub async fn read_raw_chunk(&self, digest: &[u8; 32]) -> Result { let mut chunk_data = Vec::with_capacity(4 * 1024 * 1024); @@ -43,8 +45,6 @@ impl RemoteChunkReader { .await?; let chunk = DataBlob::load_from_reader(&mut &chunk_data[..])?; - - // fixme: verify digest? Ok(chunk) } -- 2.20.1