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

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2022 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              : 
      10              : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      11              : 
      12              : #define CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE (64)
      13              : 
      14              : typedef struct {
      15              :     spdm_message_header_t header;
      16              :     /* param1 == RSVD
      17              :      * param2 == RSVD*/
      18              :     uint16_t standard_id;
      19              :     uint8_t len;
      20              :     /*uint8_t                vendor_id[len];*/
      21              :     uint16_t payload_length;
      22              :     /* uint8_t                vendor_defined_payload[payload_length];*/
      23              : } my_spdm_vendor_defined_request_msg_t;
      24              : 
      25            1 : libspdm_return_t my_test_get_vendor_id_func(
      26              :     void *spdm_context,
      27              : #if LIBSPDM_PASS_SESSION_ID
      28              :     const uint32_t *session_id,
      29              : #endif
      30              :     uint16_t *resp_standard_id,
      31              :     uint8_t *resp_vendor_id_len,
      32              :     void *resp_vendor_id)
      33              : {
      34            1 :     *resp_standard_id = 6;
      35            1 :     *resp_vendor_id_len = 2;
      36            1 :     ((uint8_t*)resp_vendor_id)[0] = 0xAA;
      37            1 :     ((uint8_t*)resp_vendor_id)[1] = 0xAA;
      38              : 
      39            1 :     return LIBSPDM_STATUS_SUCCESS;
      40              : }
      41              : 
      42            1 : libspdm_return_t my_test_get_response_func(
      43              :     void *spdm_context, const uint32_t *session_id, bool is_app_message,
      44              :     size_t request_size, const void *request, size_t *response_size,
      45              :     void *response)
      46              : {
      47              :     /* response message size is greater than the sending transmit buffer size of responder */
      48            1 :     *response_size = CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE + 1;
      49            1 :     return LIBSPDM_STATUS_SUCCESS;
      50              : }
      51              : 
      52            1 : libspdm_return_t my_test_get_response_func2(
      53              :     void *spdm_context,
      54              : #if LIBSPDM_PASS_SESSION_ID
      55              :     const uint32_t *session_id,
      56              : #endif
      57              :     uint16_t req_standard_id,
      58              :     uint8_t req_vendor_id_len,
      59              :     const void *req_vendor_id,
      60              :     uint16_t req_size,
      61              :     const void *req_data,
      62              :     uint16_t *resp_size,
      63              :     void *resp_data)
      64              : {
      65              :     /* response message size is greater than the sending transmit buffer size of responder */
      66            1 :     *resp_size = CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE + 1;
      67            1 :     return LIBSPDM_STATUS_SUCCESS;
      68              : }
      69              : 
      70              : /**
      71              :  * Test 1: Test Responder Receive Send flow triggers chunk get mode
      72              :  * if response buffer is larger than requester data_transfer_size.
      73              :  **/
      74            1 : void libspdm_test_responder_receive_send_rsp_case1(void** state)
      75              : {
      76              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
      77              :     /* This test case is partially copied from test_requester_get_measurement_case4 */
      78              :     libspdm_return_t status;
      79              :     libspdm_test_context_t* spdm_test_context;
      80              :     libspdm_context_t* spdm_context;
      81              :     size_t response_size;
      82              :     uint8_t* response;
      83              :     spdm_error_response_t* spdm_response;
      84              :     spdm_get_measurements_request_t spdm_request;
      85              :     void* message;
      86              :     size_t message_size;
      87              :     void* data;
      88              :     size_t data_size;
      89              :     void* hash;
      90              :     size_t hash_size;
      91              :     uint32_t transport_header_size;
      92              :     uint8_t chunk_handle;
      93              : 
      94            1 :     spdm_test_context = *state;
      95            1 :     spdm_context = spdm_test_context->spdm_context;
      96            1 :     spdm_test_context->case_id = 1;
      97            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
      98              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
      99              : 
     100            1 :     spdm_context->connection_info.connection_state =
     101              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
     102              : 
     103            1 :     spdm_context->local_context.capability.flags |=
     104              :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
     105              :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
     106            1 :     spdm_context->connection_info.capability.flags |=
     107              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
     108              : 
     109            1 :     libspdm_read_responder_public_certificate_chain(
     110              :         m_libspdm_use_hash_algo,
     111              :         m_libspdm_use_asym_algo, &data,
     112              :         &data_size,
     113              :         &hash, &hash_size);
     114              : 
     115            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
     116            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
     117              : 
     118            1 :     libspdm_reset_message_m(spdm_context, NULL);
     119              : 
     120            1 :     spdm_context->connection_info.algorithm.measurement_spec =
     121              :         m_libspdm_use_measurement_spec;
     122            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     123              :         m_libspdm_use_measurement_hash_algo;
     124            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     125              :         m_libspdm_use_hash_algo;
     126            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     127              :         m_libspdm_use_asym_algo;
     128              : 
     129              :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     130              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
     131              :     libspdm_copy_mem(
     132              :         spdm_context->connection_info.peer_used_cert_chain[0].buffer,
     133              :         sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
     134              :         data, data_size);
     135              :     #else
     136            1 :     libspdm_hash_all(
     137              :         spdm_context->connection_info.algorithm.base_hash_algo,
     138              :         data, data_size,
     139            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
     140            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
     141            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
     142            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
     143              :         spdm_context->connection_info.algorithm.base_hash_algo,
     144              :         spdm_context->connection_info.algorithm.base_asym_algo,
     145              :         data, data_size,
     146              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
     147              :     #endif
     148              : 
     149            1 :     spdm_context->connection_info.capability.data_transfer_size =
     150              :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
     151              : 
     152            1 :     spdm_context->connection_info.capability.max_spdm_msg_size =
     153              :         LIBSPDM_MAX_SPDM_MSG_SIZE;
     154              : 
     155            1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
     156            1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
     157            1 :     spdm_request.header.request_response_code = SPDM_GET_MEASUREMENTS;
     158            1 :     spdm_request.header.param1 =
     159              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
     160            1 :     spdm_request.header.param2 =
     161              :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS;
     162            1 :     spdm_request.slot_id_param = 0;
     163              : 
     164            1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
     165            1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
     166              :                      &spdm_request, sizeof(spdm_request));
     167            1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
     168              : 
     169            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
     170            1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
     171            1 :     response = message;
     172            1 :     response_size = message_size;
     173            1 :     libspdm_zero_mem(response, response_size);
     174              : 
     175            1 :     status = libspdm_build_response(spdm_context, NULL, false,
     176              :                                     &response_size, (void**)&response);
     177              : 
     178            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     179            1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     180              : 
     181              :     /* Verify responder returned error large response with chunk_handle == 1
     182              :      * and responder is in chunking mode (get.chunk_in_use). */
     183            1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
     184            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
     185            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     186            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
     187            1 :     assert_int_equal(spdm_response->header.param2, 0);
     188              : 
     189            1 :     chunk_handle = *(uint8_t*)(spdm_response + 1);
     190            1 :     assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
     191            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
     192            1 :     libspdm_release_sender_buffer(spdm_context);
     193              : 
     194            1 :     free(data);
     195            1 :     libspdm_reset_message_m(spdm_context, NULL);
     196              :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     197              :     #else
     198            1 :     libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo,
     199              :                       spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
     200              :     #endif
     201              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     202            1 : }
     203              : 
     204              : /**
     205              :  * Test 2: Test Responder Receive Send flow triggers chunk get mode
     206              :  * if response message size is larger than responder sending transmit buffer size.
     207              :  **/
     208            1 : void libspdm_test_responder_receive_send_rsp_case2(void** state)
     209              : {
     210              :     libspdm_return_t status;
     211              :     libspdm_test_context_t* spdm_test_context;
     212              :     libspdm_context_t* spdm_context;
     213              :     size_t response_size;
     214              :     uint8_t* response;
     215              :     spdm_error_response_t* spdm_response;
     216              :     my_spdm_vendor_defined_request_msg_t spdm_request;
     217              :     void* message;
     218              :     size_t message_size;
     219              :     uint32_t transport_header_size;
     220              :     uint8_t chunk_handle;
     221              : 
     222            1 :     spdm_test_context = *state;
     223            1 :     spdm_context = spdm_test_context->spdm_context;
     224            1 :     spdm_test_context->case_id = 2;
     225            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
     226              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     227              : 
     228            1 :     spdm_context->connection_info.connection_state =
     229              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
     230              : 
     231            1 :     spdm_context->local_context.capability.flags |=
     232              :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
     233              :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
     234            1 :     spdm_context->connection_info.capability.flags |=
     235              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
     236              : 
     237              :     /* The local Responder transmit buffer size for sending a single and complete SPDM message */
     238            1 :     spdm_context->local_context.capability.sender_data_transfer_size =
     239              :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
     240              :     /* The peer Requester buffer size for receiving a single and complete SPDM message */
     241            1 :     spdm_context->connection_info.capability.data_transfer_size =
     242              :         LIBSPDM_DATA_TRANSFER_SIZE;
     243              : 
     244            1 :     spdm_context->connection_info.capability.max_spdm_msg_size =
     245              :         LIBSPDM_MAX_SPDM_MSG_SIZE;
     246              : 
     247            1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
     248            1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
     249            1 :     spdm_request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
     250              : 
     251            1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
     252            1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
     253              :                      &spdm_request, sizeof(spdm_request));
     254            1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
     255              : 
     256            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
     257            1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
     258              : 
     259            1 :     response = message;
     260            1 :     response_size = message_size;
     261            1 :     libspdm_zero_mem(response, response_size);
     262              : 
     263              :     /* Make response message size greater than the sending transmit buffer size of responder */
     264            1 :     spdm_context->get_response_func = (void *)my_test_get_response_func;
     265              : 
     266            1 :     status = libspdm_build_response(spdm_context, NULL, false,
     267              :                                     &response_size, (void**)&response);
     268            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     269            1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     270              : 
     271              :     /* Verify responder returned error large response with chunk_handle == 1
     272              :      * and responder is in chunking mode (get.chunk_in_use). */
     273            1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
     274            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
     275            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     276            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
     277            1 :     assert_int_equal(spdm_response->header.param2, 0);
     278              : 
     279            1 :     chunk_handle = *(uint8_t*)(spdm_response + 1);
     280            1 :     assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
     281            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
     282            1 :     libspdm_release_sender_buffer(spdm_context);
     283            1 : }
     284              : 
     285              : /**
     286              :  * Test 3: Test Responder Receive Send flow triggers chunk get mode
     287              :  * if response message size is larger than responder sending transmit buffer size.
     288              :  **/
     289            1 : void libspdm_test_responder_receive_send_rsp_case3(void** state)
     290              : {
     291              :     libspdm_return_t status;
     292              :     libspdm_test_context_t* spdm_test_context;
     293              :     libspdm_context_t* spdm_context;
     294              :     size_t response_size;
     295              :     uint8_t* response;
     296              :     spdm_error_response_t* spdm_response;
     297              :     my_spdm_vendor_defined_request_msg_t spdm_request;
     298              :     void* message;
     299              :     size_t message_size;
     300              :     uint32_t transport_header_size;
     301              :     uint8_t chunk_handle;
     302              : 
     303            1 :     spdm_test_context = *state;
     304            1 :     spdm_context = spdm_test_context->spdm_context;
     305            1 :     spdm_test_context->case_id = 2;
     306            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
     307              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     308              : 
     309            1 :     spdm_context->connection_info.connection_state =
     310              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
     311              : 
     312            1 :     spdm_context->local_context.capability.flags |=
     313              :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
     314              :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
     315            1 :     spdm_context->connection_info.capability.flags |=
     316              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
     317              : 
     318              :     /* The local Responder transmit buffer size for sending a single and complete SPDM message */
     319            1 :     spdm_context->local_context.capability.sender_data_transfer_size =
     320              :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
     321              :     /* The peer Requester buffer size for receiving a single and complete SPDM message */
     322            1 :     spdm_context->connection_info.capability.data_transfer_size =
     323              :         LIBSPDM_DATA_TRANSFER_SIZE;
     324              : 
     325            1 :     spdm_context->connection_info.capability.max_spdm_msg_size =
     326              :         LIBSPDM_MAX_SPDM_MSG_SIZE;
     327              : 
     328            1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
     329            1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
     330            1 :     spdm_request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
     331              : 
     332            1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
     333            1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
     334              :                      &spdm_request, sizeof(spdm_request));
     335            1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
     336              : 
     337            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
     338            1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
     339              : 
     340            1 :     response = message;
     341            1 :     response_size = message_size;
     342            1 :     libspdm_zero_mem(response, response_size);
     343              : 
     344              :     /* Make response message size greater than the sending transmit buffer size of responder */
     345            1 :     libspdm_register_vendor_get_id_callback_func(spdm_context, my_test_get_vendor_id_func);
     346            1 :     libspdm_register_vendor_callback_func(spdm_context, my_test_get_response_func2);
     347              : 
     348            1 :     status = libspdm_build_response(spdm_context, NULL, false,
     349              :                                     &response_size, (void**)&response);
     350            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     351            1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     352              : 
     353              :     /* Verify responder returned error large response with chunk_handle == 1
     354              :      * and responder is in chunking mode (get.chunk_in_use). */
     355            1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
     356            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
     357            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     358            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_LARGE_RESPONSE);
     359            1 :     assert_int_equal(spdm_response->header.param2, 0);
     360              : 
     361            1 :     chunk_handle = *(uint8_t*)(spdm_response + 1);
     362            1 :     assert_int_equal(chunk_handle, spdm_context->chunk_context.get.chunk_handle);
     363            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, true);
     364            1 :     libspdm_release_sender_buffer(spdm_context);
     365            1 : }
     366              : 
     367              : /**
     368              :  * Test 4: Test Responder Receive Send flow triggers chunk get mode
     369              :  * if response buffer is larger than requester max_spdm_msg_size.
     370              :  * expect: SPDM_ERROR_CODE_RESPONSE_TOO_LARGE
     371              :  **/
     372            1 : void libspdm_test_responder_receive_send_rsp_case4(void** state)
     373              : {
     374              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
     375              :     /* This test case is partially copied from test_requester_get_measurement_case4 */
     376              :     libspdm_return_t status;
     377              :     libspdm_test_context_t* spdm_test_context;
     378              :     libspdm_context_t* spdm_context;
     379              :     size_t response_size;
     380              :     uint8_t* response;
     381              :     spdm_error_response_t* spdm_response;
     382              :     spdm_get_measurements_request_t spdm_request;
     383              :     void* message;
     384              :     size_t message_size;
     385              :     void* data;
     386              :     size_t data_size;
     387              :     void* hash;
     388              :     size_t hash_size;
     389              :     uint32_t transport_header_size;
     390              : 
     391            1 :     spdm_test_context = *state;
     392            1 :     spdm_context = spdm_test_context->spdm_context;
     393            1 :     spdm_test_context->case_id = 3;
     394            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
     395              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     396              : 
     397            1 :     spdm_context->connection_info.connection_state =
     398              :         LIBSPDM_CONNECTION_STATE_AUTHENTICATED;
     399              : 
     400            1 :     spdm_context->local_context.capability.flags |=
     401              :         (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP
     402              :          | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP);
     403            1 :     spdm_context->connection_info.capability.flags |=
     404              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP;
     405              : 
     406            1 :     libspdm_read_responder_public_certificate_chain(
     407              :         m_libspdm_use_hash_algo,
     408              :         m_libspdm_use_asym_algo, &data,
     409              :         &data_size,
     410              :         &hash, &hash_size);
     411              : 
     412            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
     413            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
     414              : 
     415            1 :     libspdm_reset_message_m(spdm_context, NULL);
     416              : 
     417            1 :     spdm_context->connection_info.algorithm.measurement_spec =
     418              :         m_libspdm_use_measurement_spec;
     419            1 :     spdm_context->connection_info.algorithm.measurement_hash_algo =
     420              :         m_libspdm_use_measurement_hash_algo;
     421            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     422              :         m_libspdm_use_hash_algo;
     423            1 :     spdm_context->connection_info.algorithm.base_asym_algo =
     424              :         m_libspdm_use_asym_algo;
     425              : 
     426              :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     427              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size = data_size;
     428              :     libspdm_copy_mem(
     429              :         spdm_context->connection_info.peer_used_cert_chain[0].buffer,
     430              :         sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
     431              :         data, data_size);
     432              :     #else
     433            1 :     libspdm_hash_all(
     434              :         spdm_context->connection_info.algorithm.base_hash_algo,
     435              :         data, data_size,
     436            1 :         spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash);
     437            1 :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_hash_size =
     438            1 :         libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
     439            1 :     libspdm_get_leaf_cert_public_key_from_cert_chain(
     440              :         spdm_context->connection_info.algorithm.base_hash_algo,
     441              :         spdm_context->connection_info.algorithm.base_asym_algo,
     442              :         data, data_size,
     443              :         &spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
     444              :     #endif
     445              : 
     446            1 :     spdm_context->connection_info.capability.data_transfer_size =
     447              :         CHUNK_GET_UNIT_TEST_OVERRIDE_DATA_TRANSFER_SIZE;
     448              : 
     449              :     /*set requester small max_spdm_msg_size*/
     450            1 :     spdm_context->connection_info.capability.max_spdm_msg_size = 100;
     451              : 
     452            1 :     libspdm_zero_mem(&spdm_request, sizeof(spdm_request));
     453            1 :     spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12;
     454            1 :     spdm_request.header.request_response_code = SPDM_GET_MEASUREMENTS;
     455            1 :     spdm_request.header.param1 =
     456              :         SPDM_GET_MEASUREMENTS_REQUEST_ATTRIBUTES_GENERATE_SIGNATURE;
     457            1 :     spdm_request.header.param2 =
     458              :         SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_ALL_MEASUREMENTS;
     459            1 :     spdm_request.slot_id_param = 0;
     460              : 
     461            1 :     libspdm_copy_mem(spdm_context->last_spdm_request,
     462            1 :                      libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context),
     463              :                      &spdm_request, sizeof(spdm_request));
     464            1 :     spdm_context->last_spdm_request_size = sizeof(spdm_request);
     465              : 
     466            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
     467            1 :     libspdm_acquire_sender_buffer(spdm_context, &message_size, (void**) &message);
     468            1 :     response = message;
     469            1 :     response_size = message_size;
     470            1 :     libspdm_zero_mem(response, response_size);
     471              : 
     472            1 :     status = libspdm_build_response(spdm_context, NULL, false,
     473              :                                     &response_size, (void**)&response);
     474              : 
     475            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     476            1 :     transport_header_size = spdm_context->local_context.capability.transport_header_size;
     477              : 
     478              :     /* Verify responder returned SPDM_ERROR_CODE_RESPONSE_TOO_LARGE response with chunk_handle == 0
     479              :      * and responder is not in chunking mode (get.chunk_in_use). */
     480            1 :     spdm_response = (spdm_error_response_t*) ((uint8_t*)message + transport_header_size);
     481            1 :     assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12);
     482            1 :     assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR);
     483              : 
     484            1 :     assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_TOO_LARGE);
     485            1 :     assert_int_equal(spdm_response->header.param2, 0);
     486            1 :     assert_int_equal(0, spdm_context->chunk_context.get.chunk_handle);
     487            1 :     assert_int_equal(spdm_context->chunk_context.get.chunk_in_use, false);
     488            1 :     libspdm_release_sender_buffer(spdm_context);
     489              : 
     490            1 :     free(data);
     491            1 :     libspdm_reset_message_m(spdm_context, NULL);
     492              :     #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     493              :     #else
     494            1 :     libspdm_asym_free(spdm_context->connection_info.algorithm.base_asym_algo,
     495              :                       spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
     496              :     #endif
     497              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     498            1 : }
     499              : 
     500            1 : int libspdm_responder_receive_send_test_main(void)
     501              : {
     502            1 :     const struct CMUnitTest spdm_responder_receive_send_tests[] = {
     503              :         /* response message size is larger than requester data_transfer_size */
     504              :         cmocka_unit_test(libspdm_test_responder_receive_send_rsp_case1),
     505              :         /* response message size is larger than responder sending transmit buffer size */
     506              :         cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case2,
     507              :                                libspdm_unit_test_group_setup),
     508              :         /* response message size is larger than responder sending transmit buffer size
     509              :          * using the new Vendor Defined Message API */
     510              :         cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case3,
     511              :                                libspdm_unit_test_group_setup),
     512              :         /* response message size is larger than requester max_spdm_msg_size */
     513              :         cmocka_unit_test_setup(libspdm_test_responder_receive_send_rsp_case4,
     514              :                                libspdm_unit_test_group_setup),
     515              :     };
     516              : 
     517            1 :     libspdm_test_context_t test_context = {
     518              :         LIBSPDM_TEST_CONTEXT_VERSION,
     519              :         false,
     520              :     };
     521              : 
     522            1 :     libspdm_setup_test_context(&test_context);
     523              : 
     524            1 :     return cmocka_run_group_tests(spdm_responder_receive_send_tests,
     525              :                                   libspdm_unit_test_group_setup,
     526              :                                   libspdm_unit_test_group_teardown);
     527              : }
     528              : 
     529              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
        

Generated by: LCOV version 2.0-1