Skip to content

Commit

Permalink
Do not use SPDM_ERROR_CODE_SESSION_REQUIRED for SPDM 1.1.
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <[email protected]>
  • Loading branch information
jyao1 committed Sep 24, 2024
1 parent 5029b5c commit 0cd6d2f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 32 deletions.
24 changes: 18 additions & 6 deletions library/spdm_responder_lib/libspdm_rsp_end_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,28 @@ libspdm_return_t libspdm_get_response_end_session(libspdm_context_t *spdm_contex
}

if (!spdm_context->last_spdm_request_session_id_valid) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
session_info = libspdm_get_session_info_via_session_id(
spdm_context, spdm_context->last_spdm_request_session_id);
if (session_info == NULL) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
session_state = libspdm_secured_message_get_session_state(
session_info->secured_message_context);
Expand Down
31 changes: 23 additions & 8 deletions library/spdm_responder_lib/libspdm_rsp_finish.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,24 @@ libspdm_return_t libspdm_get_response_finish(libspdm_context_t *spdm_context, si
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)) {
/* No handshake in clear, then it must be in a session.*/
if (!spdm_context->last_spdm_request_session_id_valid) {
return libspdm_generate_error_response(
spdm_context, SPDM_ERROR_CODE_SESSION_REQUIRED, 0, response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(
spdm_context, SPDM_ERROR_CODE_SESSION_REQUIRED, 0, response_size, response);
} else {
return libspdm_generate_error_response(
spdm_context, SPDM_ERROR_CODE_UNSPECIFIED, 0, response_size, response);
}
}
} else {
/* handshake in clear, then it must not be in a session.*/
if (spdm_context->last_spdm_request_session_id_valid) {
return libspdm_generate_error_response(
spdm_context, SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(
spdm_context, SPDM_ERROR_CODE_SESSION_REQUIRED, 0, response_size, response);
} else {
return libspdm_generate_error_response(
spdm_context, SPDM_ERROR_CODE_UNSPECIFIED, 0, response_size, response);
}
}
}
if (spdm_context->last_spdm_request_session_id_valid) {
Expand All @@ -436,9 +445,15 @@ libspdm_return_t libspdm_get_response_finish(libspdm_context_t *spdm_context, si
}
session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
if (session_info == NULL) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
if (session_info->use_psk) {
return libspdm_generate_error_response(spdm_context,
Expand Down
24 changes: 18 additions & 6 deletions library/spdm_responder_lib/libspdm_rsp_heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,28 @@ libspdm_return_t libspdm_get_response_heartbeat(libspdm_context_t *spdm_context,
}

if (!spdm_context->last_spdm_request_session_id_valid) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
session_info = libspdm_get_session_info_via_session_id(
spdm_context, spdm_context->last_spdm_request_session_id);
if (session_info == NULL) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
session_state = libspdm_secured_message_get_session_state(
session_info->secured_message_context);
Expand Down
24 changes: 18 additions & 6 deletions library/spdm_responder_lib/libspdm_rsp_key_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,29 @@ libspdm_return_t libspdm_get_response_key_update(libspdm_context_t *spdm_context
}

if (!spdm_context->last_spdm_request_session_id_valid) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
session_id = spdm_context->last_spdm_request_session_id;
session_info =
libspdm_get_session_info_via_session_id(spdm_context, session_id);
if (session_info == NULL) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
session_state = libspdm_secured_message_get_session_state(
session_info->secured_message_context);
Expand Down
24 changes: 18 additions & 6 deletions library/spdm_responder_lib/libspdm_rsp_psk_finish.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,29 @@ libspdm_return_t libspdm_get_response_psk_finish(libspdm_context_t *spdm_context
}

if (!spdm_context->last_spdm_request_session_id_valid) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
session_id = spdm_context->last_spdm_request_session_id;
session_info =
libspdm_get_session_info_via_session_id(spdm_context, session_id);
if (session_info == NULL) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_SESSION_REQUIRED, 0,
response_size, response);
} else {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}
}
if (!session_info->use_psk) {
return libspdm_generate_error_response(spdm_context,
Expand Down

0 comments on commit 0cd6d2f

Please sign in to comment.