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 CFAAE6082D for ; Tue, 17 Nov 2020 18:58:40 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CB13113CAC for ; Tue, 17 Nov 2020 18:58:10 +0100 (CET) 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 F365213BA7 for ; Tue, 17 Nov 2020 18:58:09 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id BC779437EB for ; Tue, 17 Nov 2020 18:58:09 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Tue, 17 Nov 2020 18:57:23 +0100 Message-Id: <20201117175725.3634238-6-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201117175725.3634238-1-f.gruenbichler@proxmox.com> References: <20201117175725.3634238-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.023 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [manifest.rs] Subject: [pbs-devel] [PATCH proxmox-backup 5/7] add key fingerprint to manifest 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: Tue, 17 Nov 2020 17:58:40 -0000 if the manifest is signed/the contained archives/blobs are encrypted. stored in 'unprotected' area, since there is already a strong binding between key and manifest via the signature, and this avoids breaking backwards compatibility for a simple usability improvement. Signed-off-by: Fabian Grünbichler --- src/backup/manifest.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/backup/manifest.rs b/src/backup/manifest.rs index 51980a07..5922144d 100644 --- a/src/backup/manifest.rs +++ b/src/backup/manifest.rs @@ -223,12 +223,40 @@ impl BackupManifest { if let Some(crypt_config) = crypt_config { let sig = self.signature(crypt_config)?; manifest["signature"] = proxmox::tools::digest_to_hex(&sig).into(); + let fingerprint = crate::tools::format::as_fingerprint(&crypt_config.fingerprint()); + manifest["unprotected"]["key-fingerprint"] = fingerprint.into(); } let manifest = serde_json::to_string_pretty(&manifest).unwrap().into(); Ok(manifest) } + fn check_fingerprint_value(value: &Value, crypt_config: &CryptConfig) -> Result<(), Error> { + let config_fp = crate::tools::format::as_fingerprint(&crypt_config.fingerprint()); + if *value == config_fp { + Ok(()) + } else { + bail!("wrong key - manifest fingerprint {} does not match key fingerprint '{}'", + value, + config_fp) + } + } + + /// Checks if a BackupManifest and a CryptConfig share a valid fingerprint combination. + /// + /// An unsigned manifest is valid with any or no CryptConfig. + /// A signed manifest is only valid with a matching CryptConfig. + pub fn check_fingerprint(&self, crypt_config: Option<&CryptConfig>) -> Result<(), Error> { + match (&self.unprotected["key-fingerprint"], crypt_config) { + (Value::Null, _) => Ok(()), + (manifest_fp, None) => bail!("missing key - manifest was created with key {}", + manifest_fp), + (manifest_fp, Some(crypt_config)) => { + BackupManifest::check_fingerprint_value(manifest_fp, crypt_config) + }, + } + } + /// Try to read the manifest. This verifies the signature if there is a crypt_config. pub fn from_data(data: &[u8], crypt_config: Option<&CryptConfig>) -> Result { let json: Value = serde_json::from_slice(data)?; -- 2.20.1