From ca4d6db2e9efecbb8e08bd725459d3f5c5bd4a2b Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Thu, 23 May 2024 11:38:41 -0400 Subject: [PATCH] update print statements for clearer device logs --- library/src/cache/signing.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/library/src/cache/signing.rs b/library/src/cache/signing.rs index f2b06962..a50f98f5 100644 --- a/library/src/cache/signing.rs +++ b/library/src/cache/signing.rs @@ -4,7 +4,7 @@ use ring::signature; use std::path::Path; // https://stackoverflow.com/questions/67087597/is-it-possible-to-use-rusts-log-info-for-tests #[cfg(test)] -use std::println as info; // Workaround to use println! for logs. +use std::{println as info, println as debug}; // Workaround to use println! for logs. /// Reads the file at `path` and returns the SHA-256 hash of its contents as a String. pub fn hash_file>(path: P) -> Result { @@ -25,15 +25,17 @@ pub fn hash_file>(path: P) -> Result { /// -outform DER \ /// -out public_key.der pub fn check_signature(message: &str, signature: &str, public_key: &str) -> Result<()> { - // public.pem + debug!("Message is {}", message); + debug!("Public key is {:?}", public_key); + debug!("Signature is {}", signature); + + // public.der let public_key_bytes = base64::prelude::BASE64_STANDARD .decode(public_key) .with_context(|| format!("Failed to decode public_key: {}", public_key))?; let public_key = signature::UnparsedPublicKey::new(&signature::RSA_PKCS1_2048_8192_SHA256, public_key_bytes); - info!("Public key is {:?}", public_key); - info!("Signature is {}", signature); let decoded_sig = match base64::prelude::BASE64_STANDARD.decode(signature) { Ok(sig) => sig, Err(e) => { @@ -41,16 +43,16 @@ pub fn check_signature(message: &str, signature: &str, public_key: &str) -> Resu } }; - info!("Verifying signature..."); + info!("Verifying patch signature..."); match public_key.verify(message.as_bytes(), &decoded_sig) { Ok(_) => { - info!("Signature is valid"); + info!("Patch signature is valid"); Ok(()) } Err(_) => { // The error provided by `verify` is (by design) not helpful, so we ignore it. // See https://docs.rs/ring/latest/ring/error/struct.Unspecified.html - bail!("Signature is invalid") + bail!("Patch signature is invalid") } } }