diff --git a/spdmlib/src/common/session.rs b/spdmlib/src/common/session.rs index f44b04b..d230b8e 100644 --- a/spdmlib/src/common/session.rs +++ b/spdmlib/src/common/session.rs @@ -928,7 +928,9 @@ impl SpdmSession { &self.application_secret_backup.response_direction, ); if r_backup != Err(SPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) { - self.application_secret.response_direction.sequence_number += 1; + self.application_secret_backup + .response_direction + .sequence_number += 1; } r_backup } else if r != Err(SPDM_STATUS_SEQUENCE_NUMBER_OVERFLOW) { diff --git a/spdmlib/src/requester/key_update_req.rs b/spdmlib/src/requester/key_update_req.rs index 7aec510..e1b623b 100644 --- a/spdmlib/src/requester/key_update_req.rs +++ b/spdmlib/src/requester/key_update_req.rs @@ -116,13 +116,27 @@ impl RequesterContext { Err(SPDM_STATUS_INVALID_MSG_FIELD) } } - SpdmRequestResponseCode::SpdmResponseError => self - .spdm_handle_error_response_main( + SpdmRequestResponseCode::SpdmResponseError => { + let spdm_version_sel = self.common.negotiate_info.spdm_version_sel; + let session = if let Some(s) = self.common.get_session_via_id(session_id) { + s + } else { + return Err(SPDM_STATUS_INVALID_PARAMETER); + }; + error!("!!! key_update : fail !!! rollback all keys\n"); + session.activate_data_secret_update( + spdm_version_sel, + update_requester, + update_responder, + false, + )?; + self.spdm_handle_error_response_main( Some(session_id), receive_buffer, SpdmRequestResponseCode::SpdmRequestKeyUpdate, SpdmRequestResponseCode::SpdmResponseKeyUpdateAck, - ), + ) + } _ => Err(SPDM_STATUS_ERROR_PEER), } }