From 078cd431b63192c06fd58c8b190e9b993f69e46f Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 2 Feb 2024 13:12:23 +0100 Subject: [PATCH] WIP - remove debugging features --- core/embed/rust/src/translations/blob.rs | 42 +++++++------------ .../rust/src/translations/public_keys.rs | 7 ++-- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/core/embed/rust/src/translations/blob.rs b/core/embed/rust/src/translations/blob.rs index 626d51384..63129011a 100644 --- a/core/embed/rust/src/translations/blob.rs +++ b/core/embed/rust/src/translations/blob.rs @@ -37,11 +37,11 @@ fn validate_offset_table( mut iter: impl Iterator, ) -> Result<(), Error> { // every offset table must have at least the sentinel - let mut prev = iter.next().ok_or(value_error!("offset table too short"))?; + let mut prev = iter.next().ok_or(INVALID_TRANSLATIONS_BLOB)?; for next in iter { // offsets must be in ascending order if prev > next { - return Err(value_error!("offsets not in ascending order")); + return Err(INVALID_TRANSLATIONS_BLOB); } prev = next; } @@ -49,7 +49,7 @@ fn validate_offset_table( // data_len let sentinel = prev as usize; if sentinel < data_len - MAX_TABLE_PADDING || sentinel > data_len { - return Err(value_error!("invalid sentinel offset")); + return Err(INVALID_TRANSLATIONS_BLOB); } Ok(()) } @@ -63,7 +63,7 @@ impl<'a> Table<'a> { // a valid OffsetEntry value. let (_prefix, offsets, _suffix) = unsafe { offsets_data.align_to::() }; if !_prefix.is_empty() || !_suffix.is_empty() { - return Err(value_error!("misaligned offsets table")); + return Err(INVALID_TRANSLATIONS_BLOB); } Ok(Self { @@ -78,7 +78,7 @@ impl<'a> Table<'a> { self.offsets.iter().last().map(|it| it.id), Some(SENTINEL_ID) ) { - return Err(value_error!("invalid sentinel id")); + return Err(INVALID_TRANSLATIONS_BLOB); } Ok(()) } @@ -136,7 +136,7 @@ impl<'a> Translations<'a> { let payload_digest = sha256::digest(payload_bytes); if payload_digest != header.data_hash { - return Err(value_error!("hash mismatch")); + return Err(INVALID_TRANSLATIONS_BLOB); } let mut payload_reader = InputStream::new(payload_bytes); @@ -145,7 +145,7 @@ impl<'a> Translations<'a> { let fonts_reader = read_u16_prefixed_block(&mut payload_reader)?; if payload_reader.remaining() > 0 { - return Err(value_error!("Trailing data in translations blob")); + return Err(INVALID_TRANSLATIONS_BLOB); } // construct translations data @@ -157,7 +157,7 @@ impl<'a> Translations<'a> { let (_prefix, translations_offsets, _suffix) = unsafe { translations_offsets_bytes.align_to::() }; if !_prefix.is_empty() || !_suffix.is_empty() { - return Err(value_error!("Invalid translations table")); + return Err(INVALID_TRANSLATIONS_BLOB); } let translations = translations_reader.rest(); validate_offset_table(translations.len(), translations_offsets.iter().copied())?; @@ -239,7 +239,7 @@ pub struct TranslationsHeader<'a> { fn read_fixedsize_str<'a>(reader: &mut InputStream<'a>, len: usize) -> Result<&'a str, Error> { let bytes = reader.read(len)?; - core::str::from_utf8(bytes).map_err(|_| value_error!("invalid fixedsize string")) + core::str::from_utf8(bytes).map_err(|_| INVALID_TRANSLATIONS_BLOB) } fn read_pascal_str<'a>(reader: &mut InputStream<'a>) -> Result<&'a str, Error> { @@ -269,7 +269,7 @@ impl<'a> TranslationsHeader<'a> { // let magic = reader.read(Self::BLOB_MAGIC.len())?; if magic != Self::BLOB_MAGIC { - return Err(value_error!("invalid header magic")); + return Err(INVALID_TRANSLATIONS_BLOB); } // read length of contained data @@ -287,7 +287,7 @@ impl<'a> TranslationsHeader<'a> { let magic = header_reader.read(Self::HEADER_MAGIC.len())?; if magic != Self::HEADER_MAGIC { - return Err(value_error!("bad header magic")); + return Err(INVALID_TRANSLATIONS_BLOB); } let model = read_fixedsize_str(&mut header_reader, 4)?; @@ -305,7 +305,7 @@ impl<'a> TranslationsHeader<'a> { let language = read_pascal_str(&mut header_reader)?; if language.len() > 8 { - return Err(value_error!("invalid language")); + return Err(INVALID_TRANSLATIONS_BLOB); } let change_language_title = read_pascal_str(&mut header_reader)?; let change_language_prompt = read_pascal_str(&mut header_reader)?; @@ -326,7 +326,7 @@ impl<'a> TranslationsHeader<'a> { // SAFETY: sha256::Digest is a plain array of u8, so any bytes are valid let (_prefix, merkle_proof, _suffix) = unsafe { proof_bytes.align_to::() }; if !_prefix.is_empty() || !_suffix.is_empty() { - return Err(value_error!("misaligned proof table")); + return Err(INVALID_TRANSLATIONS_BLOB); } let signature = cosi::Signature::new( proof_reader.read_byte()?, @@ -335,24 +335,12 @@ impl<'a> TranslationsHeader<'a> { // check that there is no trailing data in the proof section if proof_reader.remaining() > 0 { - return Err(value_error!("trailing data in proof")); + return Err(INVALID_TRANSLATIONS_BLOB); } // check that the declared data section length matches the container size if container_length - reader.tell() != data_len { - println!( - "container length: ", - heapless::String::<10>::from(container_length as u32).as_str() - ); - println!( - "reader pos: ", - heapless::String::<10>::from(reader.tell() as u32).as_str() - ); - println!( - "data_len: ", - heapless::String::<10>::from(data_len as u32).as_str() - ); - return Err(value_error!("data length mismatch")); + return Err(INVALID_TRANSLATIONS_BLOB); } let new = Self { diff --git a/core/embed/rust/src/translations/public_keys.rs b/core/embed/rust/src/translations/public_keys.rs index 7ee9aa67a..130fd5a05 100644 --- a/core/embed/rust/src/translations/public_keys.rs +++ b/core/embed/rust/src/translations/public_keys.rs @@ -8,7 +8,8 @@ pub const PUBLIC_KEYS_DEVEL: [ed25519::PublicKey; 3] = [ ]; pub const PUBLIC_KEYS: [ed25519::PublicKey; 3] = [ - *b"\x43\x34\x99\x63\x43\x62\x3e\x46\x2f\x0f\xc9\x33\x11\xfe\xf1\x48\x4c\xa2\x3d\x2f\xf1\xee\xc6\xdf\x1f\xa8\xeb\x7e\x35\x73\xb3\xdb", - *b"\xa9\xa2\x2c\xc2\x65\xa0\xcb\x1d\x6c\xb3\x29\xbc\x0e\x60\xbc\x45\xdf\x76\xb9\xab\x28\xfb\x87\xb6\x11\x36\xfe\xaf\x8d\x8f\xdc\x96", - *b"\xb8\xd2\xb2\x1d\xe2\x71\x24\xf0\x51\x1f\x90\x3a\xe7\xe6\x0e\x07\x96\x18\x10\xa0\xb8\xf2\x8e\xa7\x55\xfa\x50\x36\x7a\x8a\x2b\x8b", + // TODO replace with production keys + *b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + *b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + *b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", ];