Skip to content

Commit 19fc1af

Browse files
roumingtylerfanelli
authored andcommitted
preattestation: fix family_id and image_id parsing
AMD defines the `family_id` and `image_id` fields as 16 bytes long. Therefore, in the command-line tool, we should expect 32 hexadecimal characters to convert this into a 16-byte sequence. This patch addresses the issue when only 16 characters are parsed. Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
1 parent ec7d91d commit 19fc1af

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

src/preattestation.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ mod idblock {
274274
#[arg(value_name = "launch-digest", required = true)]
275275
pub launch_digest: String,
276276

277-
/// Family ID of the guest provided by the guest owner. Has to be 16 characters.
277+
/// Family ID of the guest provided by the guest owner in hex. Has to be 32 characters (16 bytes).
278278
#[arg(short, long, value_name = "family-id")]
279279
pub family_id: Option<String>,
280280

281-
/// Image ID of the guest provided by the guest owner. Has to be 16 characters.
281+
/// Image ID of the guest provided by the guest owner in hex. Has to be 32 characters (16 bytes).
282282
#[arg(short = 'm', long, value_name = "image-id")]
283283
pub image_id: Option<String>,
284284

@@ -316,23 +316,25 @@ mod idblock {
316316
};
317317

318318
let family_id = match args.family_id {
319-
Some(family) => {
320-
if family.chars().count() == 16 {
321-
Some(FamilyId::new(family.as_bytes().try_into()?))
322-
} else {
323-
return Err(anyhow::anyhow!("Invalid Family Id length!"));
319+
Some(s) => {
320+
if s.len() != 32 {
321+
return Err(anyhow::anyhow!("Family ID must be 32 hex chars"));
324322
}
323+
let bytes: [u8; 16] =
324+
<[u8; 16]>::from_hex(&s).map_err(|_| anyhow::anyhow!("Invalid hex"))?;
325+
Some(FamilyId::new(bytes))
325326
}
326327
None => None,
327328
};
328329

329330
let image_id = match args.image_id {
330-
Some(image) => {
331-
if image.chars().count() == 16 {
332-
Some(ImageId::new(image.as_bytes().try_into()?))
333-
} else {
334-
return Err(anyhow::anyhow!("Invalid Image Id length!"));
331+
Some(s) => {
332+
if s.len() != 32 {
333+
return Err(anyhow::anyhow!("Image ID must be 32 hex chars"));
335334
}
335+
let bytes: [u8; 16] =
336+
<[u8; 16]>::from_hex(&s).map_err(|_| anyhow::anyhow!("Invalid hex"))?;
337+
Some(ImageId::new(bytes))
336338
}
337339
None => None,
338340
};

0 commit comments

Comments
 (0)