From 1aafb0d2178356c56c1af681a4ecb178e5b3df4c Mon Sep 17 00:00:00 2001 From: OuyangHang33 Date: Sun, 21 Apr 2024 23:04:05 +0800 Subject: [PATCH] Fix requester can't receive err ms from respondergafter sending incorrect UpdateAllKeys operation Signed-off-by: OuyangHang33 --- spdmlib/src/common/session.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/spdmlib/src/common/session.rs b/spdmlib/src/common/session.rs index d23ee01..f44b04b 100644 --- a/spdmlib/src/common/session.rs +++ b/spdmlib/src/common/session.rs @@ -919,10 +919,24 @@ impl SpdmSession { app_buffer, &self.application_secret.response_direction, ); - if r != Err(SPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) { + // When meet Generic failure, try backup keys before aborting. + if r == Err(SPDM_STATUS_CRYPTO_ERROR) && self.responder_backup_valid { + // Retry decoding message with backup Requester key. + let r_backup = self.decode_msg( + secured_buffer, + app_buffer, + &self.application_secret_backup.response_direction, + ); + if r_backup != Err(SPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) { + self.application_secret.response_direction.sequence_number += 1; + } + r_backup + } else if r != Err(SPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) { self.application_secret.response_direction.sequence_number += 1; + r + } else { + r } - r } } _ => Err(SPDM_STATUS_INVALID_STATE_LOCAL),