MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / cmd_replay_imr

Function cmd_replay_imr

dstack-util/src/main.rs:254–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

252}
253
254fn cmd_replay_imr() -> Result<()> {
255 use sha2::Digest;
256
257 println!("=== Event Log Replay: Calculated IMR/RTMR Values ===\n");
258
259 // Read and replay event logs
260 let event_logs = att::eventlog::tdx::read_event_log().context("Failed to read event logs")?;
261
262 println!("Total events: {}", event_logs.len());
263
264 // Count events per IMR
265 let mut imr_counts = [0u32; 4];
266 for event in &event_logs {
267 if event.imr < 4 {
268 imr_counts[event.imr as usize] += 1;
269 }
270 }
271
272 println!("Event distribution:");
273 for (idx, count) in imr_counts.iter().enumerate() {
274 println!(" IMR {}: {} events", idx, count);
275 }
276 println!();
277
278 // Replay event logs to calculate IMR/RTMR values
279 println!("Replaying event log...");
280 let mut rtmrs: [[u8; 48]; 4] = [[0u8; 48]; 4];
281
282 for event in &event_logs {
283 if event.imr < 4 {
284 let mut hasher = sha2::Sha384::new();
285 hasher.update(rtmrs[event.imr as usize]);
286 hasher.update(event.digest());
287 rtmrs[event.imr as usize] = hasher.finalize().into();
288 }
289 }
290
291 println!("\nCalculated IMR/RTMR values from event log replay:\n");
292 println!("IMR 0 (CCEL) → {}", hex::encode(rtmrs[0]));
293 println!("IMR 1 (CCEL) → {}", hex::encode(rtmrs[1]));
294 println!("IMR 2 (CCEL) → {}", hex::encode(rtmrs[2]));
295 println!("IMR 3 (CCEL) → {}", hex::encode(rtmrs[3]));
296
297 println!("\n========================================");
298 println!("Note: These are the calculated values from replaying the CCEL event log.");
299 println!("The mapping between CCEL IMR indices and TDX RTMR indices may vary");
300 println!("depending on the platform implementation.");
301
302 Ok(())
303}
304
305fn cmd_hex(hex_args: HexCommand) -> Result<()> {
306 fn hex_encode_io(io: &mut impl Read) -> Result<()> {

Callers 1

mainFunction · 0.85

Calls 2

read_event_logFunction · 0.85
digestMethod · 0.45

Tested by

no test coverage detected