Skip to content

Commit 2766d12

Browse files
embediverleongross
authored andcommitted
Cleanup logging in requester example
1 parent 946a48d commit 2766d12

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

examples/spdm_requester.rs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
//! SPDM Example Responder utilizing the requester library.
44
5+
use std::fmt::Display;
56
use std::io::{Error, ErrorKind, Result as IoResult};
67
use std::net::TcpStream;
78

@@ -353,6 +354,7 @@ fn full_flow(stream: TcpStream, config: &RequesterConfig) -> IoResult<()> {
353354
if config.verbose {
354355
println!("DIGESTS: {:x?}", &message_buffer.message_data());
355356
}
357+
println!("Successfully retrieved cert chain digests");
356358

357359
// Get peer certificate chain
358360
loop {
@@ -362,8 +364,10 @@ fn full_flow(stream: TcpStream, config: &RequesterConfig) -> IoResult<()> {
362364
spdm_context
363365
.requester_send_request(&mut message_buffer, EID)
364366
.unwrap();
365-
println!("requested GET_CERTIFICATE");
366-
println!("state: {:?}", spdm_context.connection_info().state());
367+
if config.verbose {
368+
println!("requested GET_CERTIFICATE");
369+
println!("state: {:?}", spdm_context.connection_info().state());
370+
}
367371

368372
spdm_context
369373
.requester_process_message(&mut message_buffer)
@@ -389,9 +393,9 @@ fn full_flow(stream: TcpStream, config: &RequesterConfig) -> IoResult<()> {
389393
.unwrap();
390394
let root_hash = store.get_root_hash(0, hash_algo).unwrap();
391395
println!(
392-
"slot 0: Root hash ({hash_algo:?}, {} bytes): {:02x?}",
396+
"slot 0: Root hash ({hash_algo:?}, {} bytes): {}",
393397
root_hash.len(),
394-
root_hash
398+
HexString(root_hash)
395399
);
396400
let cert_chain = store.get_cert_chain(0, hash_algo).unwrap();
397401

@@ -488,8 +492,8 @@ fn full_flow(stream: TcpStream, config: &RequesterConfig) -> IoResult<()> {
488492

489493
/// Display configuration information
490494
fn display_info(config: &RequesterConfig) {
491-
println!("Real SPDM Library Integrated DMTF Compatible Responder");
492-
println!("=====================================================");
495+
println!("SPDM Library DMTF Compatible Requester Example Flow");
496+
println!("===================================================");
493497
println!("Configuration:");
494498
println!(" Port: {}", config.port);
495499
println!(" Certificate: {}", config.cert_path);
@@ -526,15 +530,11 @@ fn display_info(config: &RequesterConfig) {
526530
);
527531
println!();
528532

529-
println!("Clean Platform Implementation Features:");
530-
println!(" SPDM Versions: 1.2, 1.1");
531-
println!(" Protocol Processing: Real SPDM library integration");
533+
println!("Requester Features:");
534+
println!(" SPDM Versions: 1.0, 1.1, 1.2, 1.3");
532535
println!(" Hash Algorithm: SHA-384 (platform module)");
533536
println!(" Signature Algorithm: ECDSA P-384 (platform module)");
534-
println!(" Measurements: Demo device measurements (platform module)");
535-
println!(" Certificates: Static OpenSSL-generated certificate chain (platform module)");
536-
println!(" Transport: TCP socket with DMTF protocol (platform module)");
537-
println!(" ✅ NO CODE DUPLICATION - All implementations from unified platform module");
537+
println!(" Transport: TCP socket with DMTF NONE or MCTP protocol (platform module)");
538538
println!();
539539
}
540540

@@ -555,9 +555,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
555555
println!("Connection from: {}", peer_addr);
556556
}
557557

558-
// Handle client with real SPDM processing using platform implementations
558+
println!("Starting requester command flow...");
559559
full_flow(stream, &config)?;
560560

561+
println!("Request flow finished successfully.");
562+
561563
Ok(())
562564
}
563565

@@ -638,11 +640,29 @@ fn verify_challenge_auth_signature(
638640
ctx.transcript_hash(TranscriptContext::M1, &mut transcript_hash)
639641
.unwrap();
640642
if config.verbose {
641-
println!("M1/2 hash: {transcript_hash:02x?}");
643+
println!("M1/2 hash: {}", HexString(&transcript_hash));
642644
}
643645

644646
// M denotes the message that is signed. M shall be the concatenation of the combined_spdm_prefix and unverified_message_hash.
645647
let m = [sig_combined_context.as_slice(), &transcript_hash].concat();
646648

647-
pubkey.verify(&m, &signature).is_ok()
649+
let res = pubkey.verify(&m, &signature);
650+
if config.verbose {
651+
if let Err(e) = &res {
652+
println!("Signature verify error: {e}");
653+
}
654+
}
655+
res.is_ok()
656+
}
657+
658+
#[derive(Debug)]
659+
struct HexString<'a>(&'a [u8]);
660+
661+
impl Display for HexString<'_> {
662+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
663+
for x in self.0 {
664+
write!(f, "{:02X}", x)?;
665+
}
666+
Ok(())
667+
}
648668
}

0 commit comments

Comments
 (0)