LCOV - code coverage report
Current view: top level - unit_test/test_spdm_responder/error_test - endpoint_info_err.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 347 347
Test Date: 2025-06-29 08:09:00 Functions: 100.0 % 15 15

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2025 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : 
       7              : #include "spdm_unit_test.h"
       8              : #include "internal/libspdm_responder_lib.h"
       9              : #include "internal/libspdm_requester_lib.h"
      10              : 
      11              : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
      12              : 
      13              : #pragma pack(1)
      14              : typedef struct {
      15              :     spdm_message_header_t header;
      16              :     /* param1 - subcode of the request
      17              :      * param2 - Bit[7:4]: reserved
      18              :      *          Bit[3:0]: slot_id */
      19              :     uint8_t request_attributes;
      20              :     uint8_t reserved[3];
      21              :     uint8_t nonce[32];
      22              : } spdm_get_endpoint_info_request_max_t;
      23              : #pragma pack()
      24              : 
      25              : /* request signature, correct */
      26              : spdm_get_endpoint_info_request_max_t m_libspdm_get_endpoint_info_request_err1 = {
      27              :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_ENDPOINT_INFO,
      28              :       SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER, 0},
      29              :     SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
      30              :     {0, 0, 0},
      31              :     /* nonce */
      32              : };
      33              : size_t m_libspdm_get_endpoint_info_request_err1_size =
      34              :     sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
      35              : 
      36              : /* request signature, but version 12 */
      37              : spdm_get_endpoint_info_request_max_t m_libspdm_get_endpoint_info_request_err2 = {
      38              :     { SPDM_MESSAGE_VERSION_12, SPDM_GET_ENDPOINT_INFO,
      39              :       SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER, 0},
      40              :     SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
      41              :     {0, 0, 0},
      42              :     /* nonce */
      43              : };
      44              : size_t m_libspdm_get_endpoint_info_request_err2_size =
      45              :     sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
      46              : 
      47              : /* request signature, but no nonce */
      48              : spdm_get_endpoint_info_request_max_t m_libspdm_get_endpoint_info_request_err3 = {
      49              :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_ENDPOINT_INFO,
      50              :       SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER, 0},
      51              :     SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
      52              :     {0, 0, 0},
      53              :     /* no nonce */
      54              : };
      55              : size_t m_libspdm_get_endpoint_info_request_err3_size =
      56              :     sizeof(spdm_get_endpoint_info_request_t);
      57              : 
      58              : /* request signature, but invalid slot_id */
      59              : spdm_get_endpoint_info_request_max_t m_libspdm_get_endpoint_info_request_err4 = {
      60              :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_ENDPOINT_INFO,
      61              :       SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER, 0xA},
      62              :     SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
      63              :     {0, 0, 0},
      64              :     /* nonce */
      65              : };
      66              : size_t m_libspdm_get_endpoint_info_request_err4_size =
      67              :     sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
      68              : 
      69              : /* request signature, correct, with slot_id == 0xF */
      70              : spdm_get_endpoint_info_request_max_t m_libspdm_get_endpoint_info_request_err5 = {
      71              :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_ENDPOINT_INFO,
      72              :       SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER, 0xF},
      73              :     SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
      74              :     {0, 0, 0},
      75              :     /* nonce */
      76              : };
      77              : size_t m_libspdm_get_endpoint_info_request_err5_size =
      78              :     sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
      79              : 
      80              : /* request signature, correct, with slot_id == 0x1 */
      81              : spdm_get_endpoint_info_request_max_t m_libspdm_get_endpoint_info_request_err6 = {
      82              :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_ENDPOINT_INFO,
      83              :       SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER, 1},
      84              :     SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
      85              :     {0, 0, 0},
      86              :     /* nonce */
      87              : };
      88              : size_t m_libspdm_get_endpoint_info_request_err6_size =
      89              :     sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
      90              : 
      91              : /* request signature, but sub_code invalid */
      92              : spdm_get_endpoint_info_request_max_t m_libspdm_get_endpoint_info_request_err7 = {
      93              :     { SPDM_MESSAGE_VERSION_13, SPDM_GET_ENDPOINT_INFO,
      94              :       2, 0},
      95              :     SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
      96              :     {0, 0, 0},
      97              :     /* nonce */
      98              : };
      99              : size_t m_libspdm_get_endpoint_info_request_err7_size =
     100              :     sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
     101              : 
     102              : /**
     103              :  * Test 1: Error case, connection version is lower than 1.3
     104              :  * Expected Behavior: generate an ERROR_RESPONSE with code
     105              :  *                    SPDM_ERROR_CODE_UNSUPPORTED_REQUEST
     106              :  **/
     107            1 : void libspdm_test_responder_endpoint_info_err_case1(void **state)
     108              : {
     109              :     libspdm_return_t status;
     110              :     libspdm_test_context_t *spdm_test_context;
     111              :     libspdm_context_t *spdm_context;
     112              :     libspdm_session_info_t* session_info;
     113              :     size_t response_size;
     114              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     115              :     spdm_error_response_t *spdm_response;
     116              : 
     117            1 :     spdm_test_context = *state;
     118            1 :     spdm_context = spdm_test_context->spdm_context;
     119            1 :     spdm_test_context->case_id = 0x1;
     120            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
     121              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     122            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     123            1 :     spdm_context->connection_info.connection_state =
     124              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     125            1 :     spdm_context->local_context.capability.flags = 0;
     126            1 :     spdm_context->local_context.capability.flags |=
     127              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     128            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     129              :         m_libspdm_use_hash_algo;
     130            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     131              :         m_libspdm_use_asym_algo;
     132              : 
     133            1 :     session_info = NULL;
     134              : 
     135            1 :     libspdm_reset_message_e(spdm_context, session_info);
     136            1 :     response_size = sizeof(response);
     137            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     138              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     139              : 
     140            1 :     status = libspdm_get_response_endpoint_info(
     141              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     142              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     143              : 
     144            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     145              : 
     146              :     /* response size check */
     147            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     148            1 :     spdm_response = (void *)response;
     149              : 
     150              :     /* response message check */
     151            1 :     assert_int_equal(spdm_response->header.request_response_code,
     152              :                      SPDM_ERROR);
     153            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
     154            1 :     assert_int_equal(spdm_response->header.param2, SPDM_GET_ENDPOINT_INFO);
     155              : 
     156              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     157              :     /* transcript.message_e size check */
     158              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     159              : #endif
     160            1 : }
     161              : 
     162              : /**
     163              :  * Test 2: Force response_state = SPDM_RESPONSE_STATE_BUSY when asked GET_ENDPOINT_INFO
     164              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_BUSY
     165              :  **/
     166            1 : void libspdm_test_responder_endpoint_info_err_case2(void **state)
     167              : {
     168              :     libspdm_return_t status;
     169              :     libspdm_test_context_t *spdm_test_context;
     170              :     libspdm_context_t *spdm_context;
     171              :     libspdm_session_info_t* session_info;
     172              :     size_t response_size;
     173              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     174              :     spdm_error_response_t *spdm_response;
     175              : 
     176            1 :     spdm_test_context = *state;
     177            1 :     spdm_context = spdm_test_context->spdm_context;
     178            1 :     spdm_test_context->case_id = 0x2;
     179            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     180              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     181            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY; /* force busy state */
     182            1 :     spdm_context->connection_info.connection_state =
     183              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     184            1 :     spdm_context->local_context.capability.flags = 0;
     185            1 :     spdm_context->local_context.capability.flags |=
     186              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     187            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     188              :         m_libspdm_use_hash_algo;
     189            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     190              :         m_libspdm_use_asym_algo;
     191              : 
     192            1 :     session_info = NULL;
     193              : 
     194            1 :     libspdm_reset_message_e(spdm_context, session_info);
     195            1 :     response_size = sizeof(response);
     196            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     197              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     198              : 
     199            1 :     status = libspdm_get_response_endpoint_info(
     200              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     201              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     202              : 
     203            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     204              : 
     205              :     /* response size check */
     206            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     207            1 :     spdm_response = (void *)response;
     208              : 
     209              :     /* response message check */
     210            1 :     assert_int_equal(spdm_response->header.request_response_code,
     211              :                      SPDM_ERROR);
     212            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_BUSY);
     213            1 :     assert_int_equal(spdm_response->header.param2, 0);
     214            1 :     assert_int_equal(spdm_context->response_state,
     215              :                      LIBSPDM_RESPONSE_STATE_BUSY);
     216              : 
     217              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     218              :     /* transcript.message_e size check */
     219              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     220              : #endif
     221            1 : }
     222              : 
     223              : /**
     224              :  * Test 3: Force response_state = SPDM_RESPONSE_STATE_NEED_RESYNC when asked GET_ENDPOINT_INFO
     225              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_REQUEST_RESYNCH
     226              :  **/
     227            1 : void libspdm_test_responder_endpoint_info_err_case3(void **state)
     228              : {
     229              :     libspdm_return_t status;
     230              :     libspdm_test_context_t *spdm_test_context;
     231              :     libspdm_context_t *spdm_context;
     232              :     libspdm_session_info_t* session_info;
     233              :     size_t response_size;
     234              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     235              :     spdm_error_response_t *spdm_response;
     236              : 
     237            1 :     spdm_test_context = *state;
     238            1 :     spdm_context = spdm_test_context->spdm_context;
     239            1 :     spdm_test_context->case_id = 0x3;
     240            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     241              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     242            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NEED_RESYNC; /* force resync state */
     243            1 :     spdm_context->connection_info.connection_state =
     244              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     245            1 :     spdm_context->local_context.capability.flags = 0;
     246            1 :     spdm_context->local_context.capability.flags |=
     247              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     248            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     249              :         m_libspdm_use_hash_algo;
     250            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     251              :         m_libspdm_use_asym_algo;
     252              : 
     253            1 :     session_info = NULL;
     254              : 
     255            1 :     libspdm_reset_message_e(spdm_context, session_info);
     256            1 :     response_size = sizeof(response);
     257            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     258              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     259              : 
     260            1 :     status = libspdm_get_response_endpoint_info(
     261              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     262              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     263              : 
     264            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     265              : 
     266              :     /* response size check */
     267            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     268            1 :     spdm_response = (void *)response;
     269              : 
     270              :     /* response message check */
     271            1 :     assert_int_equal(spdm_response->header.request_response_code,
     272              :                      SPDM_ERROR);
     273            1 :     assert_int_equal(spdm_response->header.param1,
     274              :                      SPDM_ERROR_CODE_REQUEST_RESYNCH);
     275            1 :     assert_int_equal(spdm_response->header.param2, 0);
     276            1 :     assert_int_equal(spdm_context->response_state,
     277              :                      LIBSPDM_RESPONSE_STATE_NEED_RESYNC);
     278              : 
     279              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     280              :     /* transcript.message_e size check */
     281              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     282              : #endif
     283            1 : }
     284              : 
     285              : #if LIBSPDM_RESPOND_IF_READY_SUPPORT
     286              : /**
     287              :  * Test 4: Force response_state = SPDM_RESPONSE_STATE_NOT_READY when asked GET_ENDPOINT_INFO
     288              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_RESPONSE_NOT_READY
     289              :  **/
     290            1 : void libspdm_test_responder_endpoint_info_err_case4(void **state)
     291              : {
     292              :     libspdm_return_t status;
     293              :     libspdm_test_context_t *spdm_test_context;
     294              :     libspdm_context_t *spdm_context;
     295              :     libspdm_session_info_t* session_info;
     296              :     size_t response_size;
     297              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     298              :     spdm_error_response_t *spdm_response;
     299              :     spdm_error_data_response_not_ready_t *error_data;
     300              : 
     301            1 :     spdm_test_context = *state;
     302            1 :     spdm_context = spdm_test_context->spdm_context;
     303            1 :     spdm_test_context->case_id = 0x4;
     304            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     305              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     306            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NOT_READY; /* force not ready state */
     307            1 :     spdm_context->connection_info.connection_state =
     308              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     309            1 :     spdm_context->local_context.capability.flags = 0;
     310            1 :     spdm_context->local_context.capability.flags |=
     311              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     312            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     313              :         m_libspdm_use_hash_algo;
     314            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     315              :         m_libspdm_use_asym_algo;
     316              : 
     317            1 :     session_info = NULL;
     318              : 
     319            1 :     libspdm_reset_message_e(spdm_context, session_info);
     320            1 :     response_size = sizeof(response);
     321            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     322              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     323              : 
     324            1 :     status = libspdm_get_response_endpoint_info(
     325              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     326              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     327              : 
     328            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     329              : 
     330              :     /* response size check */
     331            1 :     assert_int_equal(response_size,
     332              :                      sizeof(spdm_error_response_t) +
     333              :                      sizeof(spdm_error_data_response_not_ready_t));
     334            1 :     spdm_response = (void *)response;
     335              : 
     336              :     /* response message check */
     337            1 :     error_data = (spdm_error_data_response_not_ready_t
     338              :                   *)(spdm_response + 1);
     339            1 :     assert_int_equal(spdm_response->header.request_response_code,
     340              :                      SPDM_ERROR);
     341            1 :     assert_int_equal(spdm_response->header.param1,
     342              :                      SPDM_ERROR_CODE_RESPONSE_NOT_READY);
     343            1 :     assert_int_equal(spdm_response->header.param2, 0);
     344            1 :     assert_int_equal(spdm_context->response_state,
     345              :                      LIBSPDM_RESPONSE_STATE_NOT_READY);
     346            1 :     assert_int_equal(error_data->request_code, SPDM_GET_ENDPOINT_INFO);
     347              : 
     348              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     349              :     /* transcript.message_e size check */
     350              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     351              : #endif
     352            1 : }
     353              : #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
     354              : 
     355              : /**
     356              :  * Test 5: Simulate wrong `connection_state` when asked `GET_ENDPOINT_INFO`
     357              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_UNEXPECTED_REQUEST
     358              :  **/
     359            1 : void libspdm_test_responder_endpoint_info_err_case5(void **state)
     360              : {
     361              :     libspdm_return_t status;
     362              :     libspdm_test_context_t *spdm_test_context;
     363              :     libspdm_context_t *spdm_context;
     364              :     libspdm_session_info_t* session_info;
     365              :     size_t response_size;
     366              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     367              :     spdm_error_response_t *spdm_response;
     368              : 
     369            1 :     spdm_test_context = *state;
     370            1 :     spdm_context = spdm_test_context->spdm_context;
     371            1 :     spdm_test_context->case_id = 0x5;
     372            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     373              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     374            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     375            1 :     spdm_context->connection_info.connection_state =
     376              :         LIBSPDM_CONNECTION_STATE_AFTER_VERSION; /* wrong state */
     377            1 :     spdm_context->local_context.capability.flags = 0;
     378            1 :     spdm_context->local_context.capability.flags |=
     379              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     380            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     381              :         m_libspdm_use_hash_algo;
     382            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     383              :         m_libspdm_use_asym_algo;
     384              : 
     385            1 :     session_info = NULL;
     386              : 
     387            1 :     libspdm_reset_message_e(spdm_context, session_info);
     388            1 :     response_size = sizeof(response);
     389            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     390              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     391              : 
     392            1 :     status = libspdm_get_response_endpoint_info(
     393              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     394              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     395              : 
     396            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     397              : 
     398              :     /* response size check */
     399            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     400            1 :     spdm_response = (void *)response;
     401              : 
     402              :     /* response message check */
     403            1 :     assert_int_equal(spdm_response->header.request_response_code,
     404              :                      SPDM_ERROR);
     405            1 :     assert_int_equal(spdm_response->header.param1,
     406              :                      SPDM_ERROR_CODE_UNEXPECTED_REQUEST);
     407            1 :     assert_int_equal(spdm_response->header.param2, 0);
     408              : 
     409              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     410              :     /* transcript.message_e size check */
     411              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     412              : #endif
     413            1 : }
     414              : 
     415              : 
     416              : /**
     417              :  * Test 6: Error Case: Responder does not support EP_INFO_CAP
     418              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_UNSUPPORTED_REQUEST
     419              :  **/
     420            1 : void libspdm_test_responder_endpoint_info_err_case6(void **state)
     421              : {
     422              :     libspdm_return_t status;
     423              :     libspdm_test_context_t *spdm_test_context;
     424              :     libspdm_context_t *spdm_context;
     425              :     libspdm_session_info_t* session_info;
     426              :     size_t response_size;
     427              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     428              :     spdm_error_response_t *spdm_response;
     429              : 
     430            1 :     spdm_test_context = *state;
     431            1 :     spdm_context = spdm_test_context->spdm_context;
     432            1 :     spdm_test_context->case_id = 0x6;
     433            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     434              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     435            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     436            1 :     spdm_context->connection_info.connection_state =
     437              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     438            1 :     spdm_context->local_context.capability.flags = 0; /* no EP_INFO_CAP */
     439            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     440              :         m_libspdm_use_hash_algo;
     441            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     442              :         m_libspdm_use_asym_algo;
     443              : 
     444            1 :     session_info = NULL;
     445              : 
     446            1 :     libspdm_reset_message_e(spdm_context, session_info);
     447            1 :     response_size = sizeof(response);
     448            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     449              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     450              : 
     451            1 :     status = libspdm_get_response_endpoint_info(
     452              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     453              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     454              : 
     455            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     456              : 
     457              :     /* response size check */
     458            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     459            1 :     spdm_response = (void *)response;
     460              : 
     461              :     /* response message check */
     462            1 :     assert_int_equal(spdm_response->header.request_response_code,
     463              :                      SPDM_ERROR);
     464            1 :     assert_int_equal(spdm_response->header.param1,
     465              :                      SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
     466            1 :     assert_int_equal(spdm_response->header.param2, SPDM_GET_ENDPOINT_INFO);
     467              : 
     468              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     469              :     /* transcript.message_e size check */
     470              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     471              : #endif
     472            1 : }
     473              : 
     474              : /**
     475              :  * Test 7: Error Case: Request contains mismatch version
     476              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
     477              :  **/
     478            1 : void libspdm_test_responder_endpoint_info_err_case7(void **state)
     479              : {
     480              :     libspdm_return_t status;
     481              :     libspdm_test_context_t *spdm_test_context;
     482              :     libspdm_context_t *spdm_context;
     483              :     libspdm_session_info_t* session_info;
     484              :     size_t response_size;
     485              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     486              :     spdm_error_response_t *spdm_response;
     487              : 
     488            1 :     spdm_test_context = *state;
     489            1 :     spdm_context = spdm_test_context->spdm_context;
     490            1 :     spdm_test_context->case_id = 0x7;
     491            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     492              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     493            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     494            1 :     spdm_context->connection_info.connection_state =
     495              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     496            1 :     spdm_context->local_context.capability.flags = 0;
     497            1 :     spdm_context->local_context.capability.flags |=
     498              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     499            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     500              :         m_libspdm_use_hash_algo;
     501            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     502              :         m_libspdm_use_asym_algo;
     503              : 
     504            1 :     session_info = NULL;
     505              : 
     506            1 :     libspdm_reset_message_e(spdm_context, session_info);
     507            1 :     response_size = sizeof(response);
     508            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     509              :                               m_libspdm_get_endpoint_info_request_err2.nonce);
     510              : 
     511            1 :     status = libspdm_get_response_endpoint_info(
     512              :         spdm_context, m_libspdm_get_endpoint_info_request_err2_size,
     513              :         &m_libspdm_get_endpoint_info_request_err2, &response_size, response);
     514              : 
     515            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     516              : 
     517              :     /* response size check */
     518            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     519            1 :     spdm_response = (void *)response;
     520              : 
     521              :     /* response message check */
     522            1 :     assert_int_equal(spdm_response->header.request_response_code,
     523              :                      SPDM_ERROR);
     524            1 :     assert_int_equal(spdm_response->header.param1,
     525              :                      SPDM_ERROR_CODE_VERSION_MISMATCH);
     526            1 :     assert_int_equal(spdm_response->header.param2, 0);
     527              : 
     528              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     529              :     /* transcript.message_e size check */
     530              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     531              : #endif
     532            1 : }
     533              : 
     534              : /**
     535              :  * Test 8: Error Case: Signature was required, but responder only support EP_INFO_CAP_NO_SIG
     536              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_UNSUPPORTED_REQUEST
     537              :  **/
     538            1 : void libspdm_test_responder_endpoint_info_err_case8(void **state)
     539              : {
     540              :     libspdm_return_t status;
     541              :     libspdm_test_context_t *spdm_test_context;
     542              :     libspdm_context_t *spdm_context;
     543              :     libspdm_session_info_t* session_info;
     544              :     size_t response_size;
     545              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     546              :     spdm_error_response_t *spdm_response;
     547              : 
     548            1 :     spdm_test_context = *state;
     549            1 :     spdm_context = spdm_test_context->spdm_context;
     550            1 :     spdm_test_context->case_id = 0x8;
     551            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     552              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     553            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     554            1 :     spdm_context->connection_info.connection_state =
     555              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     556            1 :     spdm_context->local_context.capability.flags = 0;
     557            1 :     spdm_context->local_context.capability.flags |=
     558              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_NO_SIG;
     559            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     560              :         m_libspdm_use_hash_algo;
     561            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     562              :         m_libspdm_use_asym_algo;
     563              : 
     564            1 :     session_info = NULL;
     565              : 
     566            1 :     libspdm_reset_message_e(spdm_context, session_info);
     567            1 :     response_size = sizeof(response);
     568            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     569              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     570              : 
     571            1 :     status = libspdm_get_response_endpoint_info(
     572              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     573              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     574              : 
     575            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     576              : 
     577              :     /* response size check */
     578            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     579            1 :     spdm_response = (void *)response;
     580              : 
     581              :     /* response message check */
     582            1 :     assert_int_equal(spdm_response->header.request_response_code,
     583              :                      SPDM_ERROR);
     584            1 :     assert_int_equal(spdm_response->header.param1,
     585              :                      SPDM_ERROR_CODE_UNSUPPORTED_REQUEST);
     586            1 :     assert_int_equal(spdm_response->header.param2, SPDM_GET_ENDPOINT_INFO);
     587              : 
     588              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     589              :     /* transcript.message_e size check */
     590              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     591              : #endif
     592            1 : }
     593              : 
     594              : /**
     595              :  * Test 9: Error Case: Signature was required, but there is no nonce in request
     596              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
     597              :  **/
     598            1 : void libspdm_test_responder_endpoint_info_err_case9(void **state)
     599              : {
     600              :     libspdm_return_t status;
     601              :     libspdm_test_context_t *spdm_test_context;
     602              :     libspdm_context_t *spdm_context;
     603              :     libspdm_session_info_t* session_info;
     604              :     size_t response_size;
     605              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     606              :     spdm_error_response_t *spdm_response;
     607              : 
     608            1 :     spdm_test_context = *state;
     609            1 :     spdm_context = spdm_test_context->spdm_context;
     610            1 :     spdm_test_context->case_id = 0x9;
     611            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     612              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     613            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     614            1 :     spdm_context->connection_info.connection_state =
     615              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     616            1 :     spdm_context->local_context.capability.flags = 0;
     617            1 :     spdm_context->local_context.capability.flags |=
     618              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     619            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     620              :         m_libspdm_use_hash_algo;
     621            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     622              :         m_libspdm_use_asym_algo;
     623              : 
     624            1 :     session_info = NULL;
     625              : 
     626            1 :     libspdm_reset_message_e(spdm_context, session_info);
     627            1 :     response_size = sizeof(response);
     628              : 
     629            1 :     status = libspdm_get_response_endpoint_info(
     630              :         spdm_context, m_libspdm_get_endpoint_info_request_err3_size,
     631              :         &m_libspdm_get_endpoint_info_request_err3, &response_size, response);
     632              : 
     633            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     634              : 
     635              :     /* response size check */
     636            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     637            1 :     spdm_response = (void *)response;
     638              : 
     639              :     /* response message check */
     640            1 :     assert_int_equal(spdm_response->header.request_response_code,
     641              :                      SPDM_ERROR);
     642            1 :     assert_int_equal(spdm_response->header.param1,
     643              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     644            1 :     assert_int_equal(spdm_response->header.param2, 0);
     645              : 
     646              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     647              :     /* transcript.message_e size check */
     648              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     649              : #endif
     650            1 : }
     651              : 
     652              : /**
     653              :  * Test 10: Error Case: Request contains invalid slot_id
     654              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
     655              :  **/
     656            1 : void libspdm_test_responder_endpoint_info_err_case10(void **state)
     657              : {
     658              :     libspdm_return_t status;
     659              :     libspdm_test_context_t *spdm_test_context;
     660              :     libspdm_context_t *spdm_context;
     661              :     libspdm_session_info_t* session_info;
     662              :     size_t response_size;
     663              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     664              :     spdm_error_response_t *spdm_response;
     665              : 
     666            1 :     spdm_test_context = *state;
     667            1 :     spdm_context = spdm_test_context->spdm_context;
     668            1 :     spdm_test_context->case_id = 0xA;
     669            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     670              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     671            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     672            1 :     spdm_context->connection_info.connection_state =
     673              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     674            1 :     spdm_context->local_context.capability.flags = 0;
     675            1 :     spdm_context->local_context.capability.flags |=
     676              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     677            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     678              :         m_libspdm_use_hash_algo;
     679            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     680              :         m_libspdm_use_asym_algo;
     681              : 
     682            1 :     session_info = NULL;
     683              : 
     684            1 :     libspdm_reset_message_e(spdm_context, session_info);
     685            1 :     response_size = sizeof(response);
     686            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     687              :                               m_libspdm_get_endpoint_info_request_err4.nonce);
     688              : 
     689            1 :     status = libspdm_get_response_endpoint_info(
     690              :         spdm_context, m_libspdm_get_endpoint_info_request_err4_size,
     691              :         &m_libspdm_get_endpoint_info_request_err4, &response_size, response);
     692              : 
     693            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     694              : 
     695              :     /* response size check */
     696            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     697            1 :     spdm_response = (void *)response;
     698              : 
     699              :     /* response message check */
     700            1 :     assert_int_equal(spdm_response->header.request_response_code,
     701              :                      SPDM_ERROR);
     702            1 :     assert_int_equal(spdm_response->header.param1,
     703              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     704            1 :     assert_int_equal(spdm_response->header.param2, 0);
     705              : 
     706              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     707              :     /* transcript.message_e size check */
     708              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     709              : #endif
     710            1 : }
     711              : 
     712              : /**
     713              :  * Test 11: Error case, signature was required
     714              :  *          but local_cert_chain_provision[slot_id] == NULL
     715              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
     716              :  **/
     717            1 : void libspdm_test_responder_endpoint_info_err_case11(void **state)
     718              : {
     719              :     libspdm_return_t status;
     720              :     libspdm_test_context_t *spdm_test_context;
     721              :     libspdm_context_t *spdm_context;
     722              :     libspdm_session_info_t* session_info;
     723              :     size_t response_size;
     724              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     725              :     spdm_error_response_t *spdm_response;
     726              : 
     727            1 :     spdm_test_context = *state;
     728            1 :     spdm_context = spdm_test_context->spdm_context;
     729            1 :     spdm_test_context->case_id = 0xB;
     730            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     731              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     732            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     733            1 :     spdm_context->connection_info.connection_state =
     734              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     735            1 :     spdm_context->local_context.capability.flags = 0;
     736            1 :     spdm_context->local_context.capability.flags |=
     737              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     738            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     739              :         m_libspdm_use_hash_algo;
     740            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     741              :         m_libspdm_use_asym_algo;
     742              : 
     743            1 :     session_info = NULL;
     744              :     /* no initialization for spdm_context->local_context.local_cert_chain_provision */
     745            9 :     for (int i = 0; i < SPDM_MAX_SLOT_COUNT; i++) {
     746            8 :         spdm_context->local_context.local_cert_chain_provision_size[i] = 0;
     747            8 :         spdm_context->local_context.local_cert_chain_provision[i] = NULL;
     748              :     }
     749              : 
     750            1 :     libspdm_reset_message_e(spdm_context, session_info);
     751            1 :     response_size = sizeof(response);
     752            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     753              :                               m_libspdm_get_endpoint_info_request_err1.nonce);
     754              : 
     755            1 :     status = libspdm_get_response_endpoint_info(
     756              :         spdm_context, m_libspdm_get_endpoint_info_request_err1_size,
     757              :         &m_libspdm_get_endpoint_info_request_err1, &response_size, response);
     758              : 
     759            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     760              : 
     761              :     /* response size check */
     762            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     763            1 :     spdm_response = (void *)response;
     764              : 
     765              :     /* response message check */
     766            1 :     assert_int_equal(spdm_response->header.request_response_code,
     767              :                      SPDM_ERROR);
     768            1 :     assert_int_equal(spdm_response->header.param1,
     769              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     770            1 :     assert_int_equal(spdm_response->header.param2, 0);
     771              : 
     772              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     773              :     /* transcript.message_e size check */
     774              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     775              : #endif
     776            1 : }
     777              : 
     778              : /**
     779              :  * Test 12: Error case, signature was required, slot_id == 0xF
     780              :  *          but local_public_key_provision == NULL
     781              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
     782              :  **/
     783            1 : void libspdm_test_responder_endpoint_info_err_case12(void **state)
     784              : {
     785              :     libspdm_return_t status;
     786              :     libspdm_test_context_t *spdm_test_context;
     787              :     libspdm_context_t *spdm_context;
     788              :     libspdm_session_info_t* session_info;
     789              :     size_t response_size;
     790              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     791              :     spdm_error_response_t *spdm_response;
     792              : 
     793            1 :     spdm_test_context = *state;
     794            1 :     spdm_context = spdm_test_context->spdm_context;
     795            1 :     spdm_test_context->case_id = 0xC;
     796            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     797              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     798            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     799            1 :     spdm_context->connection_info.connection_state =
     800              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     801            1 :     spdm_context->local_context.capability.flags = 0;
     802            1 :     spdm_context->local_context.capability.flags |=
     803              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     804            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     805              :         m_libspdm_use_hash_algo;
     806            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     807              :         m_libspdm_use_asym_algo;
     808              : 
     809            1 :     session_info = NULL;
     810              :     /* no initialization for spdm_context->local_context.local_public_key_provision */
     811            1 :     spdm_context->local_context.local_public_key_provision = NULL;
     812              : 
     813            1 :     libspdm_reset_message_e(spdm_context, session_info);
     814            1 :     response_size = sizeof(response);
     815            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     816              :                               m_libspdm_get_endpoint_info_request_err5.nonce);
     817              : 
     818            1 :     status = libspdm_get_response_endpoint_info(
     819              :         spdm_context, m_libspdm_get_endpoint_info_request_err5_size,
     820              :         &m_libspdm_get_endpoint_info_request_err5, &response_size, response);
     821              : 
     822            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     823              : 
     824              :     /* response size check */
     825            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     826            1 :     spdm_response = (void *)response;
     827              : 
     828              :     /* response message check */
     829            1 :     assert_int_equal(spdm_response->header.request_response_code,
     830              :                      SPDM_ERROR);
     831            1 :     assert_int_equal(spdm_response->header.param1,
     832              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     833            1 :     assert_int_equal(spdm_response->header.param2, 0);
     834              : 
     835              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     836              :     /* transcript.message_e size check */
     837              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     838              : #endif
     839            1 : }
     840              : 
     841              : /**
     842              :  * Test 13: Error case, signature was required, multi_key_conn_rsp is set
     843              :  *          but local_key_usage_bit_mask[slot_id] not meet requirement
     844              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
     845              :  **/
     846            1 : void libspdm_test_responder_endpoint_info_err_case13(void **state)
     847              : {
     848              :     libspdm_return_t status;
     849              :     libspdm_test_context_t *spdm_test_context;
     850              :     libspdm_context_t *spdm_context;
     851              :     libspdm_session_info_t* session_info;
     852              :     size_t response_size;
     853              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     854              :     spdm_error_response_t *spdm_response;
     855              :     void *data;
     856              :     size_t data_size;
     857              : 
     858            1 :     spdm_test_context = *state;
     859            1 :     spdm_context = spdm_test_context->spdm_context;
     860            1 :     spdm_test_context->case_id = 0xD;
     861            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     862              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     863            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     864            1 :     spdm_context->connection_info.connection_state =
     865              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     866            1 :     spdm_context->local_context.capability.flags = 0;
     867            1 :     spdm_context->local_context.capability.flags |=
     868              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     869            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     870              :         m_libspdm_use_hash_algo;
     871            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     872              :         m_libspdm_use_asym_algo;
     873              : 
     874            1 :     session_info = NULL;
     875            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     876              :                                                     m_libspdm_use_asym_algo, &data,
     877              :                                                     &data_size, NULL, NULL);
     878            9 :     for (int i = 0; i < SPDM_MAX_SLOT_COUNT; i++) {
     879            8 :         spdm_context->local_context.local_cert_chain_provision_size[i] = data_size;
     880            8 :         spdm_context->local_context.local_cert_chain_provision[i] = data;
     881              :     }
     882            1 :     spdm_context->connection_info.peer_used_cert_chain_slot_id = 1;
     883            1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
     884              :     /* no initialization for spdm_context->local_context.local_key_usage_bit_mask */
     885            1 :     spdm_context->local_context.local_key_usage_bit_mask[1] = 0;
     886              : 
     887              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     888              :     spdm_context->connection_info.peer_used_cert_chain[1].buffer_size =
     889              :         data_size;
     890              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[1].buffer,
     891              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[1].buffer),
     892              :                      data, data_size);
     893              : #else
     894            1 :     libspdm_hash_all(
     895              :         spdm_context->connection_info.algorithm.base_hash_algo,
     896              :         data, data_size,
     897            1 :         spdm_context->connection_info.peer_used_cert_chain[1].buffer_hash);
     898            1 :     spdm_context->connection_info.peer_used_cert_chain[1].buffer_hash_size =
     899            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
     900            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
     901              :         spdm_context->connection_info.algorithm.base_hash_algo,
     902              :         spdm_context->connection_info.algorithm.base_asym_algo,
     903              :         data, data_size,
     904              :         &spdm_context->connection_info.peer_used_cert_chain[1].leaf_cert_public_key);
     905              : #endif
     906            1 :     spdm_context->connection_info.multi_key_conn_rsp = true;
     907              : 
     908            1 :     libspdm_reset_message_e(spdm_context, session_info);
     909            1 :     response_size = sizeof(response);
     910            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     911              :                               m_libspdm_get_endpoint_info_request_err6.nonce);
     912              : 
     913            1 :     status = libspdm_get_response_endpoint_info(
     914              :         spdm_context, m_libspdm_get_endpoint_info_request_err6_size,
     915              :         &m_libspdm_get_endpoint_info_request_err6, &response_size, response);
     916              : 
     917            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     918              : 
     919              :     /* response size check */
     920            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     921            1 :     spdm_response = (void *)response;
     922              : 
     923              :     /* response message check */
     924            1 :     assert_int_equal(spdm_response->header.request_response_code,
     925              :                      SPDM_ERROR);
     926            1 :     assert_int_equal(spdm_response->header.param1,
     927              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     928            1 :     assert_int_equal(spdm_response->header.param2, 0);
     929              : 
     930              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     931              :     /* transcript.message_e size check */
     932              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     933              : #endif
     934            1 : }
     935              : 
     936              : /**
     937              :  * Test 14: Error case, invalid sub_code
     938              :  * Expected Behavior: generate an ERROR_RESPONSE with code SPDM_ERROR_CODE_INVALID_REQUEST
     939              :  **/
     940            1 : void libspdm_test_responder_endpoint_info_err_case14(void **state)
     941              : {
     942              :     libspdm_return_t status;
     943              :     libspdm_test_context_t *spdm_test_context;
     944              :     libspdm_context_t *spdm_context;
     945              :     libspdm_session_info_t* session_info;
     946              :     size_t response_size;
     947              :     uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
     948              :     spdm_error_response_t *spdm_response;
     949              : 
     950            1 :     spdm_test_context = *state;
     951            1 :     spdm_context = spdm_test_context->spdm_context;
     952            1 :     spdm_test_context->case_id = 0xE;
     953            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     954              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     955            1 :     spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
     956            1 :     spdm_context->connection_info.connection_state =
     957              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     958            1 :     spdm_context->local_context.capability.flags = 0;
     959            1 :     spdm_context->local_context.capability.flags |=
     960              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_SIG;
     961            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     962              :         m_libspdm_use_hash_algo;
     963            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     964              :         m_libspdm_use_asym_algo;
     965              : 
     966            1 :     session_info = NULL;
     967              : 
     968            1 :     libspdm_reset_message_e(spdm_context, session_info);
     969            1 :     response_size = sizeof(response);
     970            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE,
     971              :                               m_libspdm_get_endpoint_info_request_err7.nonce);
     972              : 
     973            1 :     status = libspdm_get_response_endpoint_info(
     974              :         spdm_context, m_libspdm_get_endpoint_info_request_err7_size,
     975              :         &m_libspdm_get_endpoint_info_request_err7, &response_size, response);
     976              : 
     977            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     978              : 
     979              :     /* response size check */
     980            1 :     assert_int_equal(response_size, sizeof(spdm_error_response_t));
     981            1 :     spdm_response = (void *)response;
     982              : 
     983              :     /* response message check */
     984            1 :     assert_int_equal(spdm_response->header.request_response_code,
     985              :                      SPDM_ERROR);
     986            1 :     assert_int_equal(spdm_response->header.param1,
     987              :                      SPDM_ERROR_CODE_INVALID_REQUEST);
     988            1 :     assert_int_equal(spdm_response->header.param2, 0);
     989              : 
     990              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     991              :     /* transcript.message_e size check */
     992              :     assert_int_equal(spdm_context->transcript.message_e.buffer_size, 0);
     993              : #endif
     994            1 : }
     995              : 
     996            1 : int libspdm_responder_endpoint_info_error_test_main(void)
     997              : {
     998            1 :     const struct CMUnitTest spdm_responder_endpoint_info_tests[] = {
     999              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case1),
    1000              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case2),
    1001              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case3),
    1002              :         #if LIBSPDM_RESPOND_IF_READY_SUPPORT
    1003              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case4),
    1004              :         #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
    1005              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case5),
    1006              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case6),
    1007              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case7),
    1008              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case8),
    1009              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case9),
    1010              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case10),
    1011              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case11),
    1012              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case12),
    1013              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case13),
    1014              :         cmocka_unit_test(libspdm_test_responder_endpoint_info_err_case14),
    1015              :     };
    1016              : 
    1017            1 :     libspdm_test_context_t test_context = {
    1018              :         LIBSPDM_TEST_CONTEXT_VERSION,
    1019              :         false,
    1020              :     };
    1021              : 
    1022            1 :     libspdm_setup_test_context(&test_context);
    1023              : 
    1024            1 :     return cmocka_run_group_tests(spdm_responder_endpoint_info_tests,
    1025              :                                   libspdm_unit_test_group_setup,
    1026              :                                   libspdm_unit_test_group_teardown);
    1027              : }
    1028              : 
    1029              : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP*/
        

Generated by: LCOV version 2.0-1