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 % 346 346
Test Date: 2026-02-22 08:11:49 Functions: 100.0 % 15 15

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

Generated by: LCOV version 2.0-1