11use core:: convert:: TryInto ;
22
33use bao1x_api:: pubkeys:: { BOOT0_SELF_CHECK , BOOT0_TO_BOOT1 , BOOT1_TO_LOADER_OR_BAREMETAL } ;
4- use bao1x_api:: signatures:: { SignatureInFlash , UNSIGNED_LEN } ;
4+ use bao1x_api:: signatures:: { SIGBLOCK_LEN , SignatureInFlash , UNSIGNED_LEN } ;
55use bao1x_api:: * ;
66use bao1x_hal:: acram:: OneWayCounter ;
77use bao1x_hal:: sigcheck:: ERASE_VALUE ;
@@ -29,6 +29,18 @@ fn hash_region(region: &[u8], description: &str) {
2929 crate :: println!( "{}: {}" , description, hex_str) ;
3030}
3131
32+ fn report_toolchain ( sig : & SignatureInFlash , description : & str ) {
33+ let hash = sig. sealed_data . toolchain ;
34+ if hash == [ 0u8 ; 20 ] {
35+ crate :: println!( "{}: unspecified" , description) ;
36+ } else {
37+ let mut buffer = [ 0u8 ; 40 ] ;
38+ hex:: encode_to_slice ( & hash, & mut buffer) . unwrap ( ) ;
39+ let hex_str = core:: str:: from_utf8 ( & buffer) . unwrap ( ) ;
40+ crate :: println!( "{}: {}" , description, hex_str) ;
41+ }
42+ }
43+
3244/// Stepping detection: attempt to modify the RRCR configuration. If bit 12 (code area protection)
3345/// can be flipped, then we are A0 stepping.
3446fn detect_stepping ( ) -> & ' static str {
@@ -57,7 +69,6 @@ pub fn audit() {
5769 crate :: println!( "Board type reads as: {:?}" , boardtype) ;
5870 crate :: println!( "Boot partition is: {:?}" , owc. get_decoded:: <AltBootCoding >( ) ) ;
5971 crate :: println!( "Semver is: {}" , crate :: version:: SEMVER ) ;
60- crate :: println!( "Baobit commit is: {}" , crate :: version:: BAOBIT_COMMIT ) ;
6172 crate :: println!( "Description is: {}" , crate :: RELEASE_DESCRIPTION ) ;
6273 crate :: println!( "Stepping is: {}" , detect_stepping( ) ) ;
6374 let slot_mgr = bao1x_hal:: acram:: SlotManager :: new ( ) ;
@@ -169,12 +180,13 @@ pub fn audit() {
169180 let b0_pk: & SignatureInFlash = unsafe { b0_pk_ptr. as_ref ( ) . unwrap ( ) } ;
170181 let boot0_used = unsafe {
171182 core:: slice:: from_raw_parts (
172- ( bao1x_api:: BOOT0_START + UNSIGNED_LEN ) as * const u8 ,
173- b0_pk. sealed_data . signed_len as usize ,
183+ ( bao1x_api:: BOOT0_START + SIGBLOCK_LEN ) as * const u8 ,
184+ b0_pk. sealed_data . signed_len as usize - ( SIGBLOCK_LEN - UNSIGNED_LEN ) ,
174185 )
175186 } ;
176- // only the portion that's protected by signature
187+ // only the portion that's strictly reproducible
177188 hash_region ( boot0_used, "boot0 code only" ) ;
189+ report_toolchain ( b0_pk, "boot0 baobit toolchain" ) ;
178190
179191 let boot1_region = unsafe {
180192 core:: slice:: from_raw_parts (
@@ -185,6 +197,18 @@ pub fn audit() {
185197 // includes free space
186198 hash_region ( boot1_region, "boot1 partition" ) ;
187199
200+ let b1_pk_ptr = bao1x_api:: BOOT1_START as * const SignatureInFlash ;
201+ let b1_pk: & SignatureInFlash = unsafe { b1_pk_ptr. as_ref ( ) . unwrap ( ) } ;
202+ let boot1_used = unsafe {
203+ core:: slice:: from_raw_parts (
204+ ( bao1x_api:: BOOT1_START + SIGBLOCK_LEN ) as * const u8 ,
205+ b1_pk. sealed_data . signed_len as usize - ( SIGBLOCK_LEN - UNSIGNED_LEN ) ,
206+ )
207+ } ;
208+ // only the portion that's strictly reproducible
209+ hash_region ( boot1_used, "boot1 code only" ) ;
210+ report_toolchain ( b1_pk, "boot1 baobit toolchain" ) ;
211+
188212 // detailed state checks
189213 let mut secure = true ;
190214 // check that boot1 pubkeys match the indelible entries
0 commit comments