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 % 188 188
Test Date: 2025-12-21 08:10:27 Functions: 100.0 % 7 7

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

Generated by: LCOV version 2.0-1