LCOV - code coverage report
Current view: top level - unit_test/test_spdm_responder - encap_get_endpoint_info.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 215 215
Test Date: 2025-09-14 08:11:04 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2025 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : #include "spdm_unit_test.h"
       7              : #include "internal/libspdm_responder_lib.h"
       8              : 
       9              : #if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT) && \
      10              :     (LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP)
      11              : 
      12              : #define LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE 0x20
      13              : 
      14              : static uint8_t m_endpoint_info_buffer_receive[LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE];
      15              : static uint8_t m_endpoint_info_buffer_send[LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE];
      16              : 
      17            5 : libspdm_return_t get_endpoint_info_callback (
      18              :     void *spdm_context,
      19              :     uint8_t subcode,
      20              :     uint8_t param2,
      21              :     uint8_t request_attributes,
      22              :     uint32_t endpoint_info_size,
      23              :     const void *endpoint_info)
      24              : {
      25            5 :     LIBSPDM_ASSERT (endpoint_info_size <= LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE);
      26            5 :     libspdm_copy_mem (m_endpoint_info_buffer_send, endpoint_info_size,
      27              :                       endpoint_info, endpoint_info_size);
      28            5 :     return LIBSPDM_STATUS_SUCCESS;
      29              : }
      30              : 
      31              : /**
      32              :  * Test 1: Normal case, request a endpoint info with signature
      33              :  * Expected Behavior: get a RETURN_SUCCESS return code, correct endpoint_info
      34              :  *                    and an empty transcript.message_encap_e
      35              :  **/
      36            1 : void libspdm_test_responder_encap_get_endpoint_info_case1(void **state)
      37              : {
      38              :     libspdm_return_t status;
      39              :     libspdm_test_context_t *spdm_test_context;
      40              :     libspdm_context_t *spdm_context;
      41              :     spdm_endpoint_info_response_t *spdm_response;
      42              :     uint8_t temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
      43              :     bool need_continue;
      44              :     uint8_t *ptr;
      45              :     size_t sig_size;
      46              :     size_t response_size;
      47              :     uint32_t endpoint_info_size;
      48              :     void *data;
      49              :     size_t data_size;
      50              : 
      51            1 :     spdm_test_context = *state;
      52            1 :     spdm_test_context->case_id = 0x1;
      53            1 :     spdm_context = spdm_test_context->spdm_context;
      54            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
      55              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
      56            1 :     spdm_context->connection_info.connection_state =
      57              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
      58            1 :     spdm_context->connection_info.capability.flags = 0;
      59            1 :     spdm_context->connection_info.capability.flags |=
      60              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG;
      61            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
      62              :         m_libspdm_use_hash_algo;
      63            1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
      64              :         m_libspdm_use_req_asym_algo;
      65            1 :     spdm_context->get_endpoint_info_callback = get_endpoint_info_callback;
      66              : 
      67            1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
      68              :                                                     m_libspdm_use_req_asym_algo, &data,
      69              :                                                     &data_size, NULL, NULL);
      70            1 :     libspdm_reset_message_a(spdm_context);
      71            1 :     libspdm_reset_message_encap_e(spdm_context, NULL);
      72              : 
      73            3 :     for (uint32_t index = 0; index < 2; index++) {
      74              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
      75              :         spdm_context->connection_info.peer_used_cert_chain[index].buffer_size = data_size;
      76              :         libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[index].buffer,
      77              :                          sizeof(spdm_context->connection_info.peer_used_cert_chain[index].buffer),
      78              :                          data, data_size);
      79              : #else
      80            2 :         libspdm_hash_all(
      81              :             spdm_context->connection_info.algorithm.base_hash_algo,
      82              :             data, data_size,
      83            2 :             spdm_context->connection_info.peer_used_cert_chain[index].buffer_hash);
      84            2 :         spdm_context->connection_info.peer_used_cert_chain[index].buffer_hash_size =
      85            2 :             libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
      86            2 :         libspdm_get_leaf_cert_public_key_from_cert_chain(
      87              :             spdm_context->connection_info.algorithm.base_hash_algo,
      88            2 :             spdm_context->connection_info.algorithm.req_base_asym_alg,
      89              :             data, data_size,
      90              :             &spdm_context->connection_info.peer_used_cert_chain[index].leaf_cert_public_key);
      91              : #endif
      92              :     }
      93              : 
      94              :     /* Subcase 1: slot_id = 0 */
      95            1 :     spdm_context->encap_context.req_slot_id = 0;
      96            1 :     endpoint_info_size = LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE;
      97            1 :     libspdm_generate_device_endpoint_info(
      98              :         spdm_context, SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER,
      99              :         SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
     100              :         &endpoint_info_size, m_endpoint_info_buffer_receive);
     101            1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
     102              : 
     103            1 :     response_size = sizeof(spdm_endpoint_info_response_t) +
     104              :                     SPDM_NONCE_SIZE + sizeof(uint32_t) +
     105            1 :                     endpoint_info_size + sig_size;
     106              : 
     107            1 :     spdm_response = (void *)temp_buf;
     108            1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     109            1 :     spdm_response->header.request_response_code = SPDM_ENDPOINT_INFO;
     110            1 :     spdm_response->header.param1 = 0;
     111            1 :     spdm_response->header.param2 = spdm_context->encap_context.req_slot_id &
     112              :                                    SPDM_ENDPOINT_INFO_RESPONSE_SLOT_ID_MASK;
     113            1 :     spdm_response->reserved = 0;
     114              : 
     115            1 :     ptr = (void *)(spdm_response + 1);
     116            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     117            1 :     ptr += SPDM_NONCE_SIZE;
     118              : 
     119            1 :     *(uint32_t *)ptr = endpoint_info_size; /* ep_info_len */
     120            1 :     ptr += sizeof(uint32_t);
     121              : 
     122            1 :     libspdm_copy_mem(ptr, endpoint_info_size,
     123              :                      m_endpoint_info_buffer_receive, endpoint_info_size);
     124            1 :     ptr += endpoint_info_size;
     125              : 
     126            1 :     libspdm_requester_data_sign(
     127              :         spdm_context,
     128            1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     129              :             SPDM_ENDPOINT_INFO,
     130              :             m_libspdm_use_req_asym_algo, m_libspdm_use_req_pqc_asym_algo, m_libspdm_use_hash_algo,
     131              :             false, (uint8_t*)spdm_response, response_size - sig_size,
     132              :             ptr, &sig_size);
     133              : 
     134            1 :     status = libspdm_process_encap_response_endpoint_info(spdm_context, response_size,
     135              :                                                           spdm_response, &need_continue);
     136            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     137           13 :     for (uint32_t index = 0; index < endpoint_info_size; index++) {
     138           12 :         assert_int_equal (m_endpoint_info_buffer_receive[index],
     139              :                           m_endpoint_info_buffer_send[index]);
     140              :     }
     141              :     /* Completion of GET_ENDPOINT_INFO sets mut IL1/IL2 to null. */
     142              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     143              :     assert_int_equal(spdm_context->transcript.message_encap_e.buffer_size, 0);
     144              : #else
     145            1 :     assert_null(spdm_context->transcript.digest_context_encap_il1il2);
     146              : #endif
     147              : 
     148              : 
     149              :     /* Subcase 2: slot_id = 1 */
     150            1 :     spdm_context->encap_context.req_slot_id = 1;
     151            1 :     endpoint_info_size = LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE;
     152            1 :     libspdm_generate_device_endpoint_info(
     153              :         spdm_context, SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER,
     154              :         SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
     155              :         &endpoint_info_size, m_endpoint_info_buffer_receive);
     156            1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
     157              : 
     158            1 :     response_size = sizeof(spdm_endpoint_info_response_t) +
     159              :                     SPDM_NONCE_SIZE + sizeof(uint32_t) +
     160            1 :                     endpoint_info_size + sig_size;
     161              : 
     162            1 :     spdm_response = (void *)temp_buf;
     163            1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     164            1 :     spdm_response->header.request_response_code = SPDM_ENDPOINT_INFO;
     165            1 :     spdm_response->header.param1 = 0;
     166            1 :     spdm_response->header.param2 = spdm_context->encap_context.req_slot_id &
     167              :                                    SPDM_ENDPOINT_INFO_RESPONSE_SLOT_ID_MASK;
     168            1 :     spdm_response->reserved = 0;
     169              : 
     170            1 :     ptr = (void *)(spdm_response + 1);
     171            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     172            1 :     ptr += SPDM_NONCE_SIZE;
     173              : 
     174            1 :     *(uint32_t *)ptr = endpoint_info_size; /* ep_info_len */
     175            1 :     ptr += sizeof(uint32_t);
     176              : 
     177            1 :     libspdm_copy_mem(ptr, endpoint_info_size,
     178              :                      m_endpoint_info_buffer_receive, endpoint_info_size);
     179            1 :     ptr += endpoint_info_size;
     180              : 
     181            1 :     libspdm_requester_data_sign(
     182              :         spdm_context,
     183            1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     184              :             SPDM_ENDPOINT_INFO,
     185              :             m_libspdm_use_req_asym_algo, m_libspdm_use_req_pqc_asym_algo, m_libspdm_use_hash_algo,
     186              :             false, (uint8_t*)spdm_response, response_size - sig_size,
     187              :             ptr, &sig_size);
     188              : 
     189            1 :     status = libspdm_process_encap_response_endpoint_info(spdm_context, response_size,
     190              :                                                           spdm_response, &need_continue);
     191            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     192           13 :     for (uint32_t index = 0; index < endpoint_info_size; index++) {
     193           12 :         assert_int_equal (m_endpoint_info_buffer_receive[index],
     194              :                           m_endpoint_info_buffer_send[index]);
     195              :     }
     196              :     /* Completion of GET_ENDPOINT_INFO sets mut IL1/IL2 to null. */
     197              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     198              :     assert_int_equal(spdm_context->transcript.message_encap_e.buffer_size, 0);
     199              : #else
     200            1 :     assert_null(spdm_context->transcript.digest_context_encap_il1il2);
     201              : #endif
     202            1 : }
     203              : 
     204              : /**
     205              :  * Test 2: Normal case, request a endpoint info with signature, req_slot_id = 0xFF
     206              :  * Expected Behavior: get a RETURN_SUCCESS return code, correct endpoint_info
     207              :  *                    and an empty transcript.message_encap_e
     208              :  **/
     209            1 : void libspdm_test_responder_encap_get_endpoint_info_case2(void **state)
     210              : {
     211              :     libspdm_return_t status;
     212              :     libspdm_test_context_t *spdm_test_context;
     213              :     libspdm_context_t *spdm_context;
     214              :     spdm_endpoint_info_response_t *spdm_response;
     215              :     uint8_t temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
     216              :     bool need_continue;
     217              :     uint8_t *ptr;
     218              :     size_t sig_size;
     219              :     size_t response_size;
     220              :     uint32_t endpoint_info_size;
     221              :     void *data;
     222              :     size_t data_size;
     223              : 
     224            1 :     spdm_test_context = *state;
     225            1 :     spdm_test_context->case_id = 0x2;
     226            1 :     spdm_context = spdm_test_context->spdm_context;
     227            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     228              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     229            1 :     spdm_context->connection_info.connection_state =
     230              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     231            1 :     spdm_context->connection_info.capability.flags = 0;
     232            1 :     spdm_context->connection_info.capability.flags |=
     233              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG;
     234            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     235              :         m_libspdm_use_hash_algo;
     236            1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
     237              :         m_libspdm_use_req_asym_algo;
     238            1 :     spdm_context->get_endpoint_info_callback = get_endpoint_info_callback;
     239              : 
     240            1 :     libspdm_read_requester_public_key(m_libspdm_use_req_asym_algo, &data, &data_size);
     241            1 :     spdm_context->local_context.peer_public_key_provision = data;
     242            1 :     spdm_context->local_context.peer_public_key_provision_size = data_size;
     243              : 
     244            1 :     spdm_context->encap_context.req_slot_id = 0xFF;
     245            1 :     endpoint_info_size = LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE;
     246            1 :     libspdm_generate_device_endpoint_info(
     247              :         spdm_context, SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER,
     248              :         SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
     249              :         &endpoint_info_size, m_endpoint_info_buffer_receive);
     250            1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
     251              : 
     252            1 :     response_size = sizeof(spdm_endpoint_info_response_t) +
     253              :                     SPDM_NONCE_SIZE + sizeof(uint32_t) +
     254            1 :                     endpoint_info_size + sig_size;
     255              : 
     256            1 :     spdm_response = (void *)temp_buf;
     257            1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     258            1 :     spdm_response->header.request_response_code = SPDM_ENDPOINT_INFO;
     259            1 :     spdm_response->header.param1 = 0;
     260            1 :     spdm_response->header.param2 = spdm_context->encap_context.req_slot_id &
     261              :                                    SPDM_ENDPOINT_INFO_RESPONSE_SLOT_ID_MASK;
     262            1 :     spdm_response->reserved = 0;
     263              : 
     264            1 :     ptr = (void *)(spdm_response + 1);
     265            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     266            1 :     ptr += SPDM_NONCE_SIZE;
     267              : 
     268            1 :     *(uint32_t *)ptr = endpoint_info_size; /* ep_info_len */
     269            1 :     ptr += sizeof(uint32_t);
     270              : 
     271            1 :     libspdm_copy_mem(ptr, endpoint_info_size,
     272              :                      m_endpoint_info_buffer_receive, endpoint_info_size);
     273            1 :     ptr += endpoint_info_size;
     274              : 
     275            1 :     libspdm_requester_data_sign(
     276              :         spdm_context,
     277            1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     278              :             SPDM_ENDPOINT_INFO,
     279              :             m_libspdm_use_req_asym_algo, m_libspdm_use_req_pqc_asym_algo, m_libspdm_use_hash_algo,
     280              :             false, (uint8_t*)spdm_response, response_size - sig_size,
     281              :             ptr, &sig_size);
     282              : 
     283            1 :     status = libspdm_process_encap_response_endpoint_info(spdm_context, response_size,
     284              :                                                           spdm_response, &need_continue);
     285            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     286           13 :     for (uint32_t index = 0; index < endpoint_info_size; index++) {
     287           12 :         assert_int_equal (m_endpoint_info_buffer_receive[index],
     288              :                           m_endpoint_info_buffer_send[index]);
     289              :     }
     290              :     /* Completion of GET_ENDPOINT_INFO sets mut IL1/IL2 to null. */
     291              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     292              :     assert_int_equal(spdm_context->transcript.message_encap_e.buffer_size, 0);
     293              : #else
     294            1 :     assert_null(spdm_context->transcript.digest_context_encap_il1il2);
     295              : #endif
     296            1 : }
     297              : 
     298              : /**
     299              :  * Test 3: Normal case, request a endpoint info without signature
     300              :  * Expected Behavior: get a RETURN_SUCCESS return code, correct endpoint_info
     301              :  **/
     302            1 : void libspdm_test_responder_encap_get_endpoint_info_case3(void **state)
     303              : {
     304              :     libspdm_return_t status;
     305              :     libspdm_test_context_t *spdm_test_context;
     306              :     libspdm_context_t *spdm_context;
     307              :     spdm_endpoint_info_response_t *spdm_response;
     308              :     uint8_t temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
     309              :     bool need_continue;
     310              :     uint8_t *ptr;
     311              :     size_t response_size;
     312              :     uint32_t endpoint_info_size;
     313              : 
     314            1 :     spdm_test_context = *state;
     315            1 :     spdm_test_context->case_id = 0x3;
     316            1 :     spdm_context = spdm_test_context->spdm_context;
     317            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     318              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     319            1 :     spdm_context->connection_info.connection_state =
     320              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     321            1 :     spdm_context->connection_info.capability.flags = 0;
     322            1 :     spdm_context->connection_info.capability.flags |=
     323              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_NO_SIG;
     324            1 :     spdm_context->get_endpoint_info_callback = get_endpoint_info_callback;
     325              : 
     326            1 :     spdm_context->encap_context.req_slot_id = 0;
     327            1 :     endpoint_info_size = LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE;
     328            1 :     libspdm_generate_device_endpoint_info(
     329              :         spdm_context, SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER,
     330              :         SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
     331              :         &endpoint_info_size, m_endpoint_info_buffer_receive);
     332              : 
     333            1 :     response_size = sizeof(spdm_endpoint_info_response_t) +
     334            1 :                     sizeof(uint32_t) + endpoint_info_size;
     335              : 
     336            1 :     spdm_response = (void *)temp_buf;
     337            1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     338            1 :     spdm_response->header.request_response_code = SPDM_ENDPOINT_INFO;
     339            1 :     spdm_response->header.param1 = 0;
     340            1 :     spdm_response->header.param2 = spdm_context->encap_context.req_slot_id &
     341              :                                    SPDM_ENDPOINT_INFO_RESPONSE_SLOT_ID_MASK;
     342            1 :     spdm_response->reserved = 0;
     343              : 
     344            1 :     ptr = (void *)(spdm_response + 1);
     345            1 :     *(uint32_t *)ptr = endpoint_info_size; /* ep_info_len */
     346            1 :     ptr += sizeof(uint32_t);
     347              : 
     348            1 :     libspdm_copy_mem(ptr, endpoint_info_size,
     349              :                      m_endpoint_info_buffer_receive, endpoint_info_size);
     350            1 :     ptr += endpoint_info_size;
     351              : 
     352            1 :     status = libspdm_process_encap_response_endpoint_info(spdm_context, response_size,
     353              :                                                           spdm_response, &need_continue);
     354            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     355           13 :     for (uint32_t index = 0; index < endpoint_info_size; index++) {
     356           12 :         assert_int_equal (m_endpoint_info_buffer_receive[index],
     357              :                           m_endpoint_info_buffer_send[index]);
     358              :     }
     359            1 : }
     360              : 
     361              : /**
     362              :  * Test 4: Normal case, request a endpoint info with signature within session
     363              :  * Expected Behavior: get a RETURN_SUCCESS return code, correct endpoint_info
     364              :  *                    and an empty session_transcript.message_encap_e
     365              :  **/
     366            1 : void libspdm_test_responder_encap_get_endpoint_info_case4(void **state)
     367              : {
     368              :     libspdm_return_t status;
     369              :     libspdm_test_context_t *spdm_test_context;
     370              :     libspdm_context_t *spdm_context;
     371              :     spdm_endpoint_info_response_t *spdm_response;
     372              :     uint8_t temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
     373              :     bool need_continue;
     374              :     uint8_t *ptr;
     375              :     size_t sig_size;
     376              :     size_t response_size;
     377              :     uint32_t endpoint_info_size;
     378              :     void *data;
     379              :     size_t data_size;
     380              :     uint32_t session_id;
     381              :     libspdm_session_info_t *session_info;
     382              : 
     383            1 :     spdm_test_context = *state;
     384            1 :     spdm_test_context->case_id = 0x4;
     385            1 :     spdm_context = spdm_test_context->spdm_context;
     386            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
     387              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     388            1 :     spdm_context->connection_info.connection_state =
     389              :         LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     390            1 :     spdm_context->connection_info.capability.flags = 0;
     391            1 :     spdm_context->connection_info.capability.flags |=
     392              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG;
     393            1 :     spdm_context->connection_info.algorithm.base_hash_algo =
     394              :         m_libspdm_use_hash_algo;
     395            1 :     spdm_context->connection_info.algorithm.req_base_asym_alg =
     396              :         m_libspdm_use_req_asym_algo;
     397            1 :     spdm_context->get_endpoint_info_callback = get_endpoint_info_callback;
     398              : 
     399            1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
     400              :                                                     m_libspdm_use_req_asym_algo, &data,
     401              :                                                     &data_size, NULL, NULL);
     402              : 
     403            1 :     spdm_context->connection_info.capability.flags |=
     404              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
     405            1 :     spdm_context->connection_info.capability.flags |=
     406              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
     407            1 :     spdm_context->connection_info.capability.flags |=
     408              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     409            1 :     spdm_context->local_context.capability.flags = 0;
     410            1 :     spdm_context->local_context.capability.flags |=
     411              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
     412            1 :     spdm_context->local_context.capability.flags |=
     413              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
     414            1 :     spdm_context->local_context.capability.flags |=
     415              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     416            1 :     spdm_context->connection_info.algorithm.dhe_named_group =
     417              :         m_libspdm_use_dhe_algo;
     418            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite =
     419              :         m_libspdm_use_aead_algo;
     420              : 
     421            1 :     session_id = 0xFFFFFFFF;
     422            1 :     session_info = &spdm_context->session_info[0];
     423            1 :     libspdm_session_info_init(spdm_context, session_info, session_id, true);
     424            1 :     libspdm_secured_message_set_session_state(
     425              :         session_info->secured_message_context,
     426              :         LIBSPDM_SESSION_STATE_ESTABLISHED);
     427              : 
     428            1 :     libspdm_reset_message_a(spdm_context);
     429            1 :     libspdm_reset_message_encap_e(spdm_context, session_info);
     430              : 
     431            3 :     for (uint32_t index = 0; index < 2; index++) {
     432              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     433              :         spdm_context->connection_info.peer_used_cert_chain[index].buffer_size = data_size;
     434              :         libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[index].buffer,
     435              :                          sizeof(spdm_context->connection_info.peer_used_cert_chain[index].buffer),
     436              :                          data, data_size);
     437              : #else
     438            2 :         libspdm_hash_all(
     439              :             spdm_context->connection_info.algorithm.base_hash_algo,
     440              :             data, data_size,
     441            2 :             spdm_context->connection_info.peer_used_cert_chain[index].buffer_hash);
     442            2 :         spdm_context->connection_info.peer_used_cert_chain[index].buffer_hash_size =
     443            2 :             libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
     444            2 :         libspdm_get_leaf_cert_public_key_from_cert_chain(
     445              :             spdm_context->connection_info.algorithm.base_hash_algo,
     446            2 :             spdm_context->connection_info.algorithm.req_base_asym_alg,
     447              :             data, data_size,
     448              :             &spdm_context->connection_info.peer_used_cert_chain[index].leaf_cert_public_key);
     449              : #endif
     450              :     }
     451              : 
     452            1 :     spdm_context->encap_context.req_slot_id = 0;
     453            1 :     endpoint_info_size = LIBSPDM_TEST_ENDPOINT_INFO_BUFFER_SIZE;
     454            1 :     libspdm_generate_device_endpoint_info(
     455              :         spdm_context, SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER,
     456              :         SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED,
     457              :         &endpoint_info_size, m_endpoint_info_buffer_receive);
     458            1 :     sig_size = libspdm_get_asym_signature_size(m_libspdm_use_req_asym_algo);
     459              : 
     460            1 :     response_size = sizeof(spdm_endpoint_info_response_t) +
     461              :                     SPDM_NONCE_SIZE + sizeof(uint32_t) +
     462            1 :                     endpoint_info_size + sig_size;
     463              : 
     464            1 :     spdm_response = (void *)temp_buf;
     465            1 :     spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     466            1 :     spdm_response->header.request_response_code = SPDM_ENDPOINT_INFO;
     467            1 :     spdm_response->header.param1 = 0;
     468            1 :     spdm_response->header.param2 = spdm_context->encap_context.req_slot_id &
     469              :                                    SPDM_ENDPOINT_INFO_RESPONSE_SLOT_ID_MASK;
     470            1 :     spdm_response->reserved = 0;
     471              : 
     472            1 :     ptr = (void *)(spdm_response + 1);
     473            1 :     libspdm_get_random_number(SPDM_NONCE_SIZE, ptr);
     474            1 :     ptr += SPDM_NONCE_SIZE;
     475              : 
     476            1 :     *(uint32_t *)ptr = endpoint_info_size; /* ep_info_len */
     477            1 :     ptr += sizeof(uint32_t);
     478              : 
     479            1 :     libspdm_copy_mem(ptr, endpoint_info_size,
     480              :                      m_endpoint_info_buffer_receive, endpoint_info_size);
     481            1 :     ptr += endpoint_info_size;
     482              : 
     483            1 :     libspdm_requester_data_sign(
     484              :         spdm_context,
     485            1 :         spdm_response->header.spdm_version << SPDM_VERSION_NUMBER_SHIFT_BIT,
     486              :             SPDM_ENDPOINT_INFO,
     487              :             m_libspdm_use_req_asym_algo, m_libspdm_use_req_pqc_asym_algo, m_libspdm_use_hash_algo,
     488              :             false, (uint8_t*)spdm_response, response_size - sig_size,
     489              :             ptr, &sig_size);
     490              : 
     491            1 :     status = libspdm_process_encap_response_endpoint_info(spdm_context, response_size,
     492              :                                                           spdm_response, &need_continue);
     493            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     494           13 :     for (uint32_t index = 0; index < endpoint_info_size; index++) {
     495           12 :         assert_int_equal (m_endpoint_info_buffer_receive[index],
     496              :                           m_endpoint_info_buffer_send[index]);
     497              :     }
     498              :     /* Completion of GET_ENDPOINT_INFO sets mut IL1/IL2 to null. */
     499              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     500              :     assert_int_equal(session_info->session_transcript.message_encap_e.buffer_size, 0);
     501              : #else
     502            1 :     assert_null(session_info->session_transcript.digest_context_encap_il1il2);
     503              : #endif
     504            1 : }
     505              : 
     506            1 : int libspdm_responder_encap_get_endpoint_info_test_main(void)
     507              : {
     508            1 :     const struct CMUnitTest spdm_responder_encap_get_endpoint_info_tests[] = {
     509              :         /* Success requeset endpoint info with signature */
     510              :         cmocka_unit_test(libspdm_test_responder_encap_get_endpoint_info_case1),
     511              :         /* Success requeset endpoint info with signature, req_slot_id = 0xFF */
     512              :         cmocka_unit_test(libspdm_test_responder_encap_get_endpoint_info_case2),
     513              :         /* Success requeset endpoint info without signature */
     514              :         cmocka_unit_test(libspdm_test_responder_encap_get_endpoint_info_case3),
     515              :         /* Success requeset endpoint info with signature in a session */
     516              :         cmocka_unit_test(libspdm_test_responder_encap_get_endpoint_info_case4),
     517              :     };
     518              : 
     519            1 :     libspdm_test_context_t test_context = {
     520              :         LIBSPDM_TEST_CONTEXT_VERSION,
     521              :         false,
     522              :     };
     523              : 
     524            1 :     libspdm_setup_test_context(&test_context);
     525              : 
     526            1 :     return cmocka_run_group_tests(spdm_responder_encap_get_endpoint_info_tests,
     527              :                                   libspdm_unit_test_group_setup,
     528              :                                   libspdm_unit_test_group_teardown);
     529              : }
     530              : 
     531              : #endif /* (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (...) */
        

Generated by: LCOV version 2.0-1