Skip to content

Commit

Permalink
Initial commit for SUPPORTED_EVENT_TYPES
Browse files Browse the repository at this point in the history
This commit implements the basic functionality of the Responder portion of `GET_SUPPORTED_EVENT_TYPES` / `SUPPORTED_EVENT_TYPES`. It includes simple unit tests that are to be fleshed out later on.

Signed-off-by: Steven Bellock <[email protected]>
  • Loading branch information
steven-bellock authored and jyao1 committed Mar 13, 2024
1 parent 906eb39 commit 4c2817b
Show file tree
Hide file tree
Showing 15 changed files with 483 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
- CLANG
- ARM_GNU
configurations:
- "-DLIBSPDM_ENABLE_CAPABILITY_CERT_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_CHAL_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_MEAS_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_PSK_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_CSR_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP=1 -DLIBSPDM_RESPOND_IF_READY_SUPPORT=1 -DLIBSPDM_SEND_GET_CERTIFICATE_SUPPORT=1 -DLIBSPDM_SEND_CHALLENGE_SUPPORT=1 -DLIBSPDM_HAL_PASS_SPDM_CONTEXT=1"
- "-DLIBSPDM_ENABLE_CAPABILITY_CERT_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_CHAL_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_MEAS_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_PSK_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_CSR_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP=0 -DLIBSPDM_RESPOND_IF_READY_SUPPORT=0 -DLIBSPDM_SEND_GET_CERTIFICATE_SUPPORT=0 -DLIBSPDM_SEND_CHALLENGE_SUPPORT=0 -DLIBSPDM_HAL_PASS_SPDM_CONTEXT=0"
- "-DLIBSPDM_ENABLE_CAPABILITY_CERT_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_CHAL_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_MEAS_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_PSK_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_CSR_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP=1 -DLIBSPDM_ENABLE_CAPABILITY_EVENT_CAP=1 -DLIBSPDM_RESPOND_IF_READY_SUPPORT=1 -DLIBSPDM_SEND_GET_CERTIFICATE_SUPPORT=1 -DLIBSPDM_SEND_CHALLENGE_SUPPORT=1 -DLIBSPDM_EVENT_RECIPIENT_SUPPORT=1 -DLIBSPDM_HAL_PASS_SPDM_CONTEXT=1"
- "-DLIBSPDM_ENABLE_CAPABILITY_CERT_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_CHAL_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_MEAS_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_PSK_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_CSR_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP=0 -DLIBSPDM_ENABLE_CAPABILITY_EVENT_CAP=0 -DLIBSPDM_RESPOND_IF_READY_SUPPORT=0 -DLIBSPDM_SEND_GET_CERTIFICATE_SUPPORT=0 -DLIBSPDM_SEND_CHALLENGE_SUPPORT=0 -DLIBSPDM_EVENT_RECIPIENT_SUPPORT=0 -DLIBSPDM_HAL_PASS_SPDM_CONTEXT=0"
- "-DLIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT=0 -DLIBSPDM_FIPS_MODE=0 -DLIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX=0"
- "-DLIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT=1 -DLIBSPDM_FIPS_MODE=1 -DLIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX=1"
- "-DDISABLE_TESTS=1"
Expand Down
42 changes: 42 additions & 0 deletions include/hal/library/eventlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright Notice:
* Copyright 2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

#ifndef EVENTLIB_H
#define EVENTLIB_H

#include "hal/base.h"
#include "internal/libspdm_lib_config.h"
#include "industry_standard/spdm.h"

#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
/**
* Populate the SupportedEventGroupsList field in the SUPPORTED_EVENT_TYPES response.
*
* The SPDM specification mandates that, at a minimum, the event notifier must support the DMTF
* event types and the EventLost event.
*
* @param spdm_context A pointer to the SPDM context.
* @param spdm_version Indicates the negotiated version.
* @param supported_event_groups_list A pointer to the buffer that holds the list of event.
* groups.
* @param supported_event_groups_list_len On input, the size, in bytes, of the buffer to hold the
* list of event groups.
* On output, the size, in bytes, of the list of event
* groups. This value must be greater than zero.
* @param event_group_count The number of event groups in supported_event_groups_list. This value
* must be greater than 0.
*
* @retval true The event groups list was successfully populated.
* @retval false An error occurred when populating the event groups list.
**/
extern bool libspdm_event_get_types(
void *spdm_context,
spdm_version_number_t spdm_version,
void *supported_event_groups_list,
uint32_t *supported_event_groups_list_len,
uint8_t *event_group_count);
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
#endif /* EVENTLIB_H */
1 change: 1 addition & 0 deletions include/internal/libspdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "hal/library/responder/measlib.h"
#include "hal/library/responder/psklib.h"
#include "hal/library/responder/setcertlib.h"
#include "hal/library/eventlib.h"
#include "hal/library/cryptlib.h"

#define INVALID_SESSION_ID 0
Expand Down
13 changes: 12 additions & 1 deletion include/internal/libspdm_responder_lib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -757,6 +757,17 @@ libspdm_return_t libspdm_get_response_chunk_send(libspdm_context_t *spdm_context

#endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */

#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
/**
* Process the SPDM GET_SUPPORTED_EVENT_TYPES request and return the response.
**/
libspdm_return_t libspdm_get_response_supported_event_types(libspdm_context_t *spdm_context,
size_t request_size,
const void *request,
size_t *response_size,
void *response);
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */

#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
/**
* Process the SPDM VENDOR_DEFINED_REQUEST request and return the response.
Expand Down
4 changes: 4 additions & 0 deletions include/library/spdm_lib_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
#define LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP 1
#endif

#ifndef LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
#define LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP 1
#endif

#ifndef LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
#define LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES 1
#endif
Expand Down
1 change: 1 addition & 0 deletions library/spdm_common_lib/libspdm_com_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const char *libspdm_get_code_str(uint8_t request_code)
{ SPDM_SET_CERTIFICATE, "SPDM_SET_CERTIFICATE" },
{ SPDM_CHUNK_SEND, "SPDM_CHUNK_SEND" },
{ SPDM_CHUNK_GET, "SPDM_CHUNK_GET" },
/* SPDM request code (1.3) */
{ SPDM_GET_SUPPORTED_EVENT_TYPES, "SPDM_GET_SUPPORTED_EVENT_TYPES" }
};

Expand Down
1 change: 1 addition & 0 deletions library/spdm_responder_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SET(src_spdm_responder_lib
libspdm_rsp_respond_if_ready.c
libspdm_rsp_version.c
libspdm_rsp_set_certificate.c
libspdm_rsp_supported_event_types.c
libspdm_rsp_csr.c
libspdm_rsp_chunk_send_ack.c
libspdm_rsp_chunk_get.c
Expand Down
4 changes: 4 additions & 0 deletions library/spdm_responder_lib/libspdm_rsp_receive_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ libspdm_get_spdm_response_func libspdm_get_response_func_via_request_code(uint8_
{ SPDM_CHUNK_SEND, libspdm_get_response_chunk_send},
#endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */

#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
{ SPDM_SUPPORTED_EVENT_TYPES, libspdm_get_response_supported_event_types },
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */

#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
{ SPDM_VENDOR_DEFINED_REQUEST, libspdm_get_vendor_defined_response },
#endif /*LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES*/
Expand Down
123 changes: 123 additions & 0 deletions library/spdm_responder_lib/libspdm_rsp_supported_event_types.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* Copyright Notice:
* Copyright 2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

#include "internal/libspdm_responder_lib.h"
#include "internal/libspdm_secured_message_lib.h"

#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP

libspdm_return_t libspdm_get_response_supported_event_types(libspdm_context_t *spdm_context,
size_t request_size,
const void *request,
size_t *response_size,
void *response)
{
spdm_supported_event_types_response_t *spdm_response;
const spdm_get_supported_event_types_request_t *spdm_request;
const size_t response_buffer_size = *response_size;
uint32_t supported_event_groups_list_len;
uint8_t event_group_count;
uint32_t session_id;
libspdm_session_info_t *session_info;
libspdm_session_state_t session_state;

spdm_request = request;

/* -=[Check Parameters Phase]=- */
LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_SUPPORTED_EVENT_TYPES);

/* -=[Verify State Phase]=- */
if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
return libspdm_responder_handle_response_state(
spdm_context,
spdm_request->header.request_response_code,
response_size, response);
}
if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
0, response_size, response);
}
if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
SPDM_GET_SUPPORTED_EVENT_TYPES,
response_size, response);
}
if (!libspdm_is_capabilities_flag_supported(
spdm_context, false,
0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP)) {
return libspdm_generate_error_response(
spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
SPDM_GET_SUPPORTED_EVENT_TYPES, response_size, response);
}
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);
}
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);
}
session_state = libspdm_secured_message_get_session_state(
session_info->secured_message_context);
if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
response_size, response);
}
/* This message can only be in secured session.
* Thus don't need to consider transport layer padding, just check its exact size. */
if (request_size != sizeof(spdm_get_supported_event_types_request_t)) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_INVALID_REQUEST, 0,
response_size, response);
}
if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
response_size, response);
}

/* -=[Construct Response Phase]=- */
LIBSPDM_ASSERT(response_buffer_size >= sizeof(spdm_supported_event_types_response_t));
libspdm_zero_mem(response, response_buffer_size);
spdm_response = response;

spdm_response->header.spdm_version = libspdm_get_connection_version(spdm_context);
spdm_response->header.request_response_code = SPDM_SUPPORTED_EVENT_TYPES;
spdm_response->header.param2 = 0;

supported_event_groups_list_len = (uint32_t)response_buffer_size -
sizeof(spdm_supported_event_types_response_t);

if (!libspdm_event_get_types(spdm_context, spdm_context->connection_info.version,
(void *)(spdm_response + 1), &supported_event_groups_list_len,
&event_group_count)) {
return libspdm_generate_error_response(spdm_context,
SPDM_ERROR_CODE_UNSPECIFIED, 0,
response_size, response);
}

LIBSPDM_ASSERT(supported_event_groups_list_len > 0);
LIBSPDM_ASSERT(supported_event_groups_list_len <=
(response_buffer_size - sizeof(spdm_supported_event_types_response_t)));
LIBSPDM_ASSERT(event_group_count > 0);

spdm_response->header.param1 = event_group_count;
spdm_response->supported_event_groups_list_len = supported_event_groups_list_len;

*response_size = sizeof(spdm_supported_event_types_response_t) +
supported_event_groups_list_len;

return LIBSPDM_STATUS_SUCCESS;
}

#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
12 changes: 12 additions & 0 deletions os_stub/spdm_device_secret_lib_null/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,16 @@ bool libspdm_gen_csr_ex(
}
#endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP_EX*/

#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
bool libspdm_event_get_types(
void *spdm_context,
spdm_version_number_t spdm_version,
void *supported_event_groups_list,
uint32_t *supported_event_groups_list_len,
uint8_t *event_group_count)
{
return false;
}
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */

#endif /* LIBSPDM_ENABLE_CAPABILITY_CSR_CAP */
23 changes: 23 additions & 0 deletions os_stub/spdm_device_secret_lib_sample/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "raw_data_key.h"

bool g_in_trusted_environment = false;
uint32_t g_supported_event_groups_list_len = 8;
uint8_t g_event_group_count = 1;

/* "LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY = 1" means use the RAW private key only
* "LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY = 0" means controlled by g_private_key_mode
Expand Down Expand Up @@ -1987,3 +1989,24 @@ bool libspdm_write_certificate_to_nvm(
return true;
}
#endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP */

#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
bool libspdm_event_get_types(
void *spdm_context,
spdm_version_number_t spdm_version,
void *supported_event_groups_list,
uint32_t *supported_event_groups_list_len,
uint8_t *event_group_count)
{
*supported_event_groups_list_len = g_supported_event_groups_list_len;

for (uint32_t index = 0; index < *supported_event_groups_list_len; index++)
{
((char *)supported_event_groups_list)[index] = (char)index;
}

*event_group_count = g_event_group_count;

return true;
}
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
2 changes: 2 additions & 0 deletions unit_test/test_spdm_responder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ SET(src_test_spdm_responder
encap_key_update.c
encap_challenge.c
encap_response.c
supported_event_types.c
error_test/supported_event_types_err.c
set_certificate_rsp.c
csr.c
receive_send.c
Expand Down
Loading

0 comments on commit 4c2817b

Please sign in to comment.