Skip to content

Commit

Permalink
Read metadata buffer size from descriptor
Browse files Browse the repository at this point in the history
Signed-off-by: Ouyang, Hang <[email protected]>
  • Loading branch information
OuyangHang33 authored and jyao1 committed Jan 29, 2024
1 parent 2880f76 commit 18c94ec
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions td-shim-tools/src/tee_info_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::io::Read;
use std::io::Seek;
use std::io::SeekFrom;
use std::mem::size_of;
use td_layout::build_time::TD_SHIM_METADATA_SIZE;
use td_shim::metadata::*;
use zeroize::Zeroize;

Expand Down Expand Up @@ -243,11 +242,9 @@ impl TdInfoStruct {
.seek(SeekFrom::Start(metadata_off as u64))
.unwrap();

let mut metadata_buf = [0; TD_SHIM_METADATA_SIZE as usize];

raw_image_file.read_exact(&mut metadata_buf).unwrap();

let desc = &metadata_buf[size_of::<TdxMetadataGuid>()..];
let mut desc_buf = [0; size_of::<TdxMetadataGuid>() + size_of::<TdxMetadataDescriptor>()];
raw_image_file.read_exact(&mut desc_buf).unwrap();
let desc = &desc_buf[size_of::<TdxMetadataGuid>()..];

// Signature 0 CHAR8[4] 4 'TDVF' signature
// Length 4 UINT32 4 Size of the structure (d)
Expand All @@ -261,6 +258,15 @@ impl TdInfoStruct {
panic!("The descriptor is not valid!\n");
}

raw_image_file
.seek(SeekFrom::Start(
metadata_off as u64 + size_of::<TdxMetadataGuid>() as u64,
))
.unwrap();
let mut metadata_buf = vec![0; descriptor.length as usize];
raw_image_file.read_exact(&mut metadata_buf).unwrap();
let desc = &metadata_buf[0..];

desc_offset += size_of::<TdxMetadataDescriptor>();

let mut buffer128: [u8; MRTD_EXTENSION_BUFFER_SIZE] = [0; MRTD_EXTENSION_BUFFER_SIZE]; // used by page add
Expand Down

0 comments on commit 18c94ec

Please sign in to comment.