LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - encap_request.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 86.3 % 757 653
Test Date: 2025-08-24 08:11:14 Functions: 88.9 % 18 16

            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_requester_lib.h"
       9              : 
      10              : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
      11              : 
      12              : static uint8_t m_libspdm_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
      13              : static uint8_t temp_buf[LIBSPDM_RECEIVER_BUFFER_SIZE];
      14              : static uint8_t temp_buff[LIBSPDM_MAX_SPDM_MSG_SIZE];
      15              : 
      16           21 : libspdm_return_t libspdm_requester_encap_request_test_send_message(void *spdm_context,
      17              :                                                                    size_t request_size,
      18              :                                                                    const void *request,
      19              :                                                                    uint64_t timeout)
      20              : {
      21              :     libspdm_test_context_t *spdm_test_context;
      22              : 
      23           21 :     spdm_test_context = libspdm_get_test_context();
      24              :     static uint8_t sub_index = 0;
      25              :     spdm_deliver_encapsulated_response_request_t *spdm_deliver_encapsulated_response_request;
      26              :     uint8_t send_temp_buf[LIBSPDM_SENDER_BUFFER_SIZE];
      27              :     size_t decode_message_size;
      28              :     spdm_error_response_t *spdm_response;
      29              :     libspdm_return_t status;
      30              :     uint32_t *message_session_id;
      31              :     bool is_message_app_message;
      32              :     uint8_t message_buffer[LIBSPDM_SENDER_BUFFER_SIZE];
      33              : 
      34           21 :     memcpy(message_buffer, request, request_size);
      35              : 
      36           21 :     switch (spdm_test_context->case_id)
      37              :     {
      38            1 :     case 0x1:
      39            1 :         return LIBSPDM_STATUS_SEND_FAIL;
      40            2 :     case 0x2:
      41            2 :         return LIBSPDM_STATUS_SUCCESS;
      42            0 :     case 0x3:
      43            0 :         return LIBSPDM_STATUS_SUCCESS;
      44            1 :     case 0x4:
      45            1 :         return LIBSPDM_STATUS_SUCCESS;
      46            2 :     case 0x5:
      47            2 :         return LIBSPDM_STATUS_SUCCESS;
      48            0 :     case 0x6:
      49            0 :         return LIBSPDM_STATUS_SUCCESS;
      50            2 :     case 0x7:
      51            2 :         return LIBSPDM_STATUS_SUCCESS;
      52            2 :     case 0x8:
      53            2 :         return LIBSPDM_STATUS_SUCCESS;
      54            2 :     case 0x9:
      55            2 :         return LIBSPDM_STATUS_SUCCESS;
      56            2 :     case 0xA:
      57              :     {
      58            2 :         if (sub_index == 0) {
      59            1 :             sub_index++;
      60            1 :         } else if (sub_index == 1) {
      61            1 :             sub_index = 0;
      62            1 :             message_session_id = NULL;
      63            1 :             is_message_app_message = false;
      64            1 :             spdm_deliver_encapsulated_response_request = (void*) send_temp_buf;
      65            1 :             decode_message_size = sizeof(spdm_deliver_encapsulated_response_request_t) +
      66              :                                   sizeof(spdm_error_response_t);
      67            1 :             status = libspdm_transport_test_decode_message(spdm_context, &message_session_id,
      68              :                                                            &is_message_app_message, true,
      69              :                                                            request_size, message_buffer,
      70              :                                                            &decode_message_size,
      71              :                                                            (void **)&spdm_deliver_encapsulated_response_request);
      72            1 :             if (LIBSPDM_STATUS_IS_ERROR(status)) {
      73            0 :                 LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "transport_decode_message - %xu\n",
      74              :                                status));
      75              :             }
      76            1 :             spdm_response = (void*) (spdm_deliver_encapsulated_response_request + 1);
      77            1 :             if (spdm_response->header.request_response_code != SPDM_ERROR) {
      78            0 :                 return LIBSPDM_STATUS_SEND_FAIL;
      79              :             }
      80            1 :             if (spdm_response->header.param1 != SPDM_ERROR_CODE_UNEXPECTED_REQUEST) { /* Here check ErrorCode should be UnexpectedRequestd */
      81            0 :                 return LIBSPDM_STATUS_SEND_FAIL;
      82              :             }
      83            1 :             if (spdm_response->header.param2 != 0) {
      84            0 :                 return LIBSPDM_STATUS_SEND_FAIL;
      85              :             }
      86              :         }
      87            2 :         return LIBSPDM_STATUS_SUCCESS;
      88              :     }
      89            1 :     case 0xb:
      90            1 :         return LIBSPDM_STATUS_SUCCESS;
      91            1 :     case 0xc:
      92            1 :         return LIBSPDM_STATUS_SUCCESS;
      93            2 :     case 0xD:
      94            2 :         return LIBSPDM_STATUS_SUCCESS;
      95            1 :     case 0xE:
      96            1 :         return LIBSPDM_STATUS_SUCCESS;
      97            2 :     case 0xF:
      98            2 :         return LIBSPDM_STATUS_SUCCESS;
      99            0 :     default:
     100            0 :         return LIBSPDM_STATUS_SEND_FAIL;
     101              :     }
     102              : }
     103              : 
     104           20 : libspdm_return_t libspdm_requester_encap_request_test_receive_message(
     105              :     void *spdm_context, size_t *response_size,
     106              :     void **response, uint64_t timeout)
     107              : {
     108              : 
     109              :     libspdm_test_context_t *spdm_test_context;
     110              :     spdm_encapsulated_request_response_t *libspdm_encapsulated_request_response;
     111              :     uint8_t *digest;
     112              :     size_t temp_buf_size;
     113              :     uint8_t *temp_buf_ptr;
     114              : 
     115           20 :     spdm_test_context = libspdm_get_test_context();
     116              :     static uint8_t sub_index = 0;
     117           20 :     switch (spdm_test_context->case_id)
     118              :     {
     119            0 :     case 0x1:
     120            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     121              : 
     122            2 :     case 0x2:
     123              :     {
     124              :         spdm_digest_response_t *spdm_response;
     125              : 
     126              :         ((libspdm_context_t *)spdm_context)
     127            2 :         ->connection_info.algorithm.base_hash_algo =
     128              :             m_libspdm_use_hash_algo;
     129            2 :         if (sub_index == 0) {
     130            1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
     131            1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     132              :                             sizeof(spdm_encapsulated_request_response_t);
     133            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     134            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     135            1 :             libspdm_encapsulated_request_response = (void*) temp_buf_ptr;
     136            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     137            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     138              :                 SPDM_ENCAPSULATED_REQUEST;
     139            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     140            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     141              : 
     142            1 :             spdm_response = (void *)(temp_buf_ptr
     143              :                                      + sizeof(spdm_encapsulated_request_response_t));
     144            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     145            1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
     146            1 :             spdm_response->header.param1 = 0;
     147            1 :             spdm_response->header.param2 = 0;
     148            1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     149              :                             sizeof(m_libspdm_local_certificate_chain),
     150              :                             (uint8_t)(0xFF));
     151              : 
     152            1 :             digest = (void *)(spdm_response + 1);
     153            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     154              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     155            1 :             spdm_response->header.param2 |= (0x01 << 0);
     156            1 :             sub_index++;
     157            1 :         } else if (sub_index == 1) {
     158              :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
     159              :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
     160            1 :             temp_buf_size = sizeof(spdm_message_header_t);
     161            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     162            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     163            1 :             spdm_encapsulated_response_ack_response = (void*) temp_buf_ptr;
     164            1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
     165            1 :             spdm_encapsulated_response_ack_response->request_response_code =
     166              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     167            1 :             spdm_encapsulated_response_ack_response->param1 = 0;
     168            1 :             spdm_encapsulated_response_ack_response->param2 =
     169              :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
     170            1 :             sub_index = 0;
     171              :         } else {
     172            0 :             temp_buf_size = 0;
     173            0 :             temp_buf_ptr = NULL;
     174              :         }
     175            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     176              :                                               temp_buf_size, temp_buf_ptr,
     177              :                                               response_size, response);
     178              :     }
     179            2 :         return LIBSPDM_STATUS_SUCCESS;
     180            0 :     case 0x3:
     181              :     {
     182              :         spdm_digest_response_t *spdm_response;
     183              : 
     184              :         ((libspdm_context_t *)spdm_context)
     185            0 :         ->connection_info.algorithm.base_hash_algo =
     186              :             m_libspdm_use_hash_algo;
     187            0 :         if (sub_index == 0) {
     188            0 :             temp_buf_size = sizeof(spdm_digest_response_t) +
     189            0 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     190              :                             sizeof(spdm_encapsulated_request_response_t);
     191            0 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     192            0 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     193            0 :             libspdm_encapsulated_request_response = (void *) temp_buf_ptr;
     194            0 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     195            0 :             libspdm_encapsulated_request_response->header.request_response_code =
     196              :                 SPDM_ENCAPSULATED_REQUEST;
     197            0 :             libspdm_encapsulated_request_response->header.param1 = 0;
     198            0 :             libspdm_encapsulated_request_response->header.param2 = 0;
     199              : 
     200            0 :             spdm_response =
     201              :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
     202            0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     203            0 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
     204            0 :             spdm_response->header.param1 = 0;
     205            0 :             spdm_response->header.param2 = 0;
     206            0 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     207              :                             sizeof(m_libspdm_local_certificate_chain),
     208              :                             (uint8_t)(0xFF));
     209              : 
     210            0 :             digest = (void *)(spdm_response + 1);
     211            0 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     212              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     213            0 :             spdm_response->header.param2 |= (0x01 << 0);
     214            0 :             sub_index++;
     215            0 :         } else if (sub_index == 1) {
     216              :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
     217              :             spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
     218            0 :             temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
     219            0 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     220            0 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     221            0 :             spdm_encapsulated_response_ack_response = (void *) temp_buf_ptr;
     222            0 :             spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     223            0 :             spdm_encapsulated_response_ack_response->header.request_response_code =
     224              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     225            0 :             spdm_encapsulated_response_ack_response->header.param1 = 0;
     226            0 :             spdm_encapsulated_response_ack_response->header.param2 =
     227              :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
     228            0 :             sub_index = 0;
     229              :         } else {
     230            0 :             temp_buf_size = 0;
     231            0 :             temp_buf_ptr = NULL;
     232              :         }
     233            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     234              :                                               temp_buf_size, temp_buf_ptr,
     235              :                                               response_size, response);
     236              :     }
     237            0 :         return LIBSPDM_STATUS_SUCCESS;
     238            1 :     case 0x4:
     239              :     {
     240              :         spdm_digest_response_t *spdm_response;
     241              : 
     242              :         ((libspdm_context_t *)spdm_context)
     243            1 :         ->connection_info.algorithm.base_hash_algo =
     244              :             m_libspdm_use_hash_algo;
     245            1 :         temp_buf_size = sizeof(spdm_encapsulated_request_response_t);
     246            1 :         libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     247            1 :         temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     248            1 :         spdm_response = (void *) temp_buf_ptr;
     249            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     250            1 :         spdm_response->header.request_response_code = SPDM_ENCAPSULATED_REQUEST;
     251            1 :         spdm_response->header.param1 = 0;
     252            1 :         spdm_response->header.param2 = 0;
     253              : 
     254            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     255              :                                               temp_buf_size, temp_buf_ptr,
     256              :                                               response_size, response);
     257              :     }
     258            1 :         return LIBSPDM_STATUS_SUCCESS;
     259            2 :     case 0x5:
     260              :     {
     261              :         spdm_digest_response_t *spdm_response;
     262              : 
     263              :         ((libspdm_context_t *)spdm_context)
     264            2 :         ->connection_info.algorithm.base_hash_algo =
     265              :             m_libspdm_use_hash_algo;
     266            2 :         if (sub_index == 0) {
     267            1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
     268            1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     269              :                             sizeof(spdm_encapsulated_request_response_t);
     270            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     271            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     272            1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
     273            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     274            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     275              :                 SPDM_ENCAPSULATED_REQUEST;
     276            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     277            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     278              : 
     279            1 :             spdm_response =
     280              :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
     281            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     282            1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
     283            1 :             spdm_response->header.param1 = 0;
     284            1 :             spdm_response->header.param2 = 0;
     285            1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     286              :                             sizeof(m_libspdm_local_certificate_chain),
     287              :                             (uint8_t)(0xFF));
     288              : 
     289            1 :             digest = (void *)(spdm_response + 1);
     290            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     291              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     292            1 :             spdm_response->header.param2 |= (0x01 << 0);
     293              : 
     294            1 :             libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     295              :                                                   temp_buf_size, temp_buf_ptr,
     296              :                                                   response_size, response);
     297            1 :             sub_index++;
     298            1 :         } else if (sub_index == 1) {
     299              :             size_t temp_buff_size;
     300              :             uint8_t *temp_buff_ptr;
     301              : 
     302            1 :             temp_buff_size = sizeof(spdm_message_header_t);
     303            1 :             libspdm_zero_mem(temp_buff, LIBSPDM_MAX_SPDM_MSG_SIZE);
     304            1 :             temp_buff_ptr = temp_buff + sizeof(libspdm_test_message_header_t);
     305              : 
     306            1 :             sub_index = 0;
     307            1 :             libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     308              :                                                   temp_buff_size, temp_buff_ptr,
     309              :                                                   response_size, response);
     310              :         }
     311              :     }
     312            2 :         return LIBSPDM_STATUS_SUCCESS;
     313            0 :     case 0x6:
     314              :     {
     315              :         spdm_digest_response_t *spdm_response;
     316              : 
     317              :         ((libspdm_context_t *)spdm_context)
     318            0 :         ->connection_info.algorithm.base_hash_algo =
     319              :             m_libspdm_use_hash_algo;
     320            0 :         if (sub_index == 0) {
     321            0 :             temp_buf_size =
     322              :                 sizeof(spdm_digest_response_t) +
     323            0 :                 libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     324              :                 sizeof(spdm_encapsulated_request_response_t);
     325            0 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     326            0 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     327              : 
     328            0 :             libspdm_encapsulated_request_response = (void*) temp_buf_ptr;
     329            0 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     330            0 :             libspdm_encapsulated_request_response->header.request_response_code =
     331              :                 SPDM_ENCAPSULATED_REQUEST;
     332            0 :             libspdm_encapsulated_request_response->header.param1 = 0;
     333            0 :             libspdm_encapsulated_request_response->header.param2 = 0;
     334              : 
     335            0 :             spdm_response =
     336              :                 (void*) (temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
     337            0 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     338            0 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
     339            0 :             spdm_response->header.param1 = 0;
     340            0 :             spdm_response->header.param2 = 0;
     341            0 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     342              :                             sizeof(m_libspdm_local_certificate_chain),
     343              :                             (uint8_t) (0xFF));
     344              : 
     345            0 :             digest = (void*) (spdm_response + 1);
     346            0 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     347              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     348            0 :             spdm_response->header.param2 |= (0x01 << 0);
     349            0 :             sub_index++;
     350            0 :         } else if (sub_index == 1) {
     351              :             spdm_encapsulated_response_ack_response_t* spdm_encapsulated_response_ack_response;
     352            0 :             temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
     353            0 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     354            0 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     355            0 :             spdm_encapsulated_response_ack_response = (void*) temp_buf_ptr;
     356            0 :             spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     357            0 :             spdm_encapsulated_response_ack_response->header.request_response_code =
     358              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     359            0 :             spdm_encapsulated_response_ack_response->header.param1 = 0;
     360            0 :             spdm_encapsulated_response_ack_response->header.param2 = 0;
     361            0 :             sub_index = 0;
     362              :         } else {
     363            0 :             temp_buf_size = 0;
     364            0 :             temp_buf_ptr = NULL;
     365              :         }
     366            0 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     367              :                                               temp_buf_size, temp_buf_ptr,
     368              :                                               response_size, response);
     369              :     }
     370            0 :         return LIBSPDM_STATUS_SUCCESS;
     371            2 :     case 0x7:
     372              :     {
     373              :         spdm_digest_response_t *spdm_response;
     374              : 
     375              :         ((libspdm_context_t *)spdm_context)
     376            2 :         ->connection_info.algorithm.base_hash_algo =
     377              :             m_libspdm_use_hash_algo;
     378            2 :         if (sub_index == 0) {
     379            1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
     380            1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     381              :                             sizeof(spdm_encapsulated_request_response_t);
     382            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     383            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     384            1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
     385            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     386            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     387              :                 SPDM_ENCAPSULATED_REQUEST;
     388            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     389            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     390              : 
     391            1 :             spdm_response =
     392              :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
     393            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     394            1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
     395            1 :             spdm_response->header.param1 = 0;
     396            1 :             spdm_response->header.param2 = 0;
     397            1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     398              :                             sizeof(m_libspdm_local_certificate_chain),
     399              :                             (uint8_t)(0xFF));
     400              : 
     401            1 :             digest = (void *)(spdm_response + 1);
     402            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     403              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     404            1 :             spdm_response->header.param2 |= (0x01 << 0);
     405            1 :             sub_index++;
     406            1 :         } else if (sub_index == 1) {
     407              :             spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
     408            1 :             temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
     409            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     410            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     411            1 :             spdm_encapsulated_response_ack_response = (void *) temp_buf_ptr;
     412            1 :             spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     413            1 :             spdm_encapsulated_response_ack_response->header.request_response_code =
     414              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     415            1 :             spdm_encapsulated_response_ack_response->header.param1 = 0;
     416            1 :             spdm_encapsulated_response_ack_response->header.param2 =
     417              :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER;
     418            1 :             sub_index = 0;
     419              :         } else {
     420            0 :             temp_buf_size = 0;
     421            0 :             temp_buf_ptr = NULL;
     422              :         }
     423            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     424              :                                               temp_buf_size, temp_buf_ptr,
     425              :                                               response_size, response);
     426              :     }
     427            2 :         return LIBSPDM_STATUS_SUCCESS;
     428            2 :     case 0x8:
     429              :     {
     430              :         spdm_get_certificate_request_t *spdm_response;
     431              : 
     432              :         ((libspdm_context_t *)spdm_context)
     433            2 :         ->connection_info.algorithm.base_hash_algo =
     434              :             m_libspdm_use_hash_algo;
     435            2 :         if (sub_index == 0) {
     436            1 :             temp_buf_size = sizeof(spdm_get_certificate_request_t) +
     437              :                             sizeof(spdm_encapsulated_request_response_t);
     438            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     439            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     440            1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
     441            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     442            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     443              :                 SPDM_ENCAPSULATED_REQUEST;
     444            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     445            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     446              : 
     447            1 :             spdm_response =
     448              :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
     449            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     450            1 :             spdm_response->header.request_response_code = SPDM_GET_CERTIFICATE;
     451            1 :             spdm_response->header.param1 = 0;
     452            1 :             spdm_response->header.param2 = 0;
     453            1 :             spdm_response->offset = 0;
     454            1 :             spdm_response->length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
     455            1 :             sub_index++;
     456            1 :         } else if (sub_index == 1) {
     457              :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
     458              :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
     459            1 :             temp_buf_size = sizeof(spdm_message_header_t);
     460            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     461            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     462            1 :             spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
     463            1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
     464            1 :             spdm_encapsulated_response_ack_response->request_response_code =
     465              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     466            1 :             spdm_encapsulated_response_ack_response->param1 = 0;
     467            1 :             spdm_encapsulated_response_ack_response->param2 =
     468              :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
     469            1 :             sub_index = 0;
     470              :         } else {
     471            0 :             temp_buf_size = 0;
     472            0 :             temp_buf_ptr = NULL;
     473              :         }
     474            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     475              :                                               temp_buf_size, temp_buf_ptr,
     476              :                                               response_size, response);
     477              :     }
     478            2 :         return LIBSPDM_STATUS_SUCCESS;
     479              : 
     480            2 :     case 0x9:
     481              :     {
     482              :         spdm_key_update_request_t *spdm_response;
     483              : 
     484              :         ((libspdm_context_t *)spdm_context)
     485            2 :         ->connection_info.algorithm.base_hash_algo =
     486              :             m_libspdm_use_hash_algo;
     487            2 :         if (sub_index == 0) {
     488            1 :             temp_buf_size = sizeof(spdm_key_update_request_t) +
     489              :                             sizeof(spdm_encapsulated_request_response_t);
     490            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     491            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     492            1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
     493            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     494            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     495              :                 SPDM_ENCAPSULATED_REQUEST;
     496            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     497            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     498              : 
     499            1 :             spdm_response =
     500              :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
     501            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     502            1 :             spdm_response->header.request_response_code = SPDM_KEY_UPDATE;
     503            1 :             spdm_response->header.param1 = SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
     504            1 :             spdm_response->header.param2 = 0x3;
     505              : 
     506            1 :             sub_index++;
     507            1 :         } else if (sub_index == 1) {
     508              :             /*When the version is SPDM_MESSAGE_VERSION_12, use the following code*/
     509              :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
     510            1 :             temp_buf_size = sizeof(spdm_message_header_t);
     511            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     512            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     513            1 :             spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
     514            1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
     515            1 :             spdm_encapsulated_response_ack_response->request_response_code =
     516              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     517            1 :             spdm_encapsulated_response_ack_response->param1 = 0;
     518            1 :             spdm_encapsulated_response_ack_response->param2 =
     519              :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
     520            1 :             sub_index = 0;
     521              :         } else {
     522            0 :             temp_buf_size = 0;
     523            0 :             temp_buf_ptr = NULL;
     524              :         }
     525            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     526              :                                               temp_buf_size, temp_buf_ptr,
     527              :                                               response_size, response);
     528              :     }
     529            2 :         return LIBSPDM_STATUS_SUCCESS;
     530              : 
     531            2 :     case 0xA:
     532              :     {
     533              :         spdm_get_encapsulated_request_request_t *spdm_response;
     534              : 
     535            2 :         if (sub_index == 0) {
     536            1 :             temp_buf_size = sizeof(spdm_encapsulated_request_response_t) +
     537              :                             sizeof(spdm_get_encapsulated_request_request_t);
     538            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     539            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     540              : 
     541              :             /* The following is ENCAPSULATED_REQUEST response message */
     542            1 :             libspdm_encapsulated_request_response = (void *) temp_buf_ptr;
     543            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     544            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     545              :                 SPDM_ENCAPSULATED_REQUEST;
     546            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     547            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     548              : 
     549              :             /* The following is EncapsulatedRequest Field of the above ENCAPSULATED_REQUEST response message*/
     550            1 :             spdm_response =
     551              :                 (void *)(temp_buf_ptr + sizeof(spdm_get_encapsulated_request_request_t));
     552            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     553            1 :             spdm_response->header.request_response_code = SPDM_GET_ENCAPSULATED_REQUEST;  /* Here invalid: GET_ENCAPSULATED_REQUEST is encapsulated */
     554            1 :             spdm_response->header.param1 = 0;
     555            1 :             spdm_response->header.param2 = 0;
     556              : 
     557            1 :             sub_index++;
     558            1 :         } else if (sub_index == 1) {
     559              :             spdm_message_header_t *spdm_encapsulated_response_ack_response;
     560            1 :             temp_buf_size = sizeof(spdm_message_header_t);
     561            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     562            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     563            1 :             spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
     564            1 :             spdm_encapsulated_response_ack_response->spdm_version = SPDM_MESSAGE_VERSION_11;
     565            1 :             spdm_encapsulated_response_ack_response->request_response_code =
     566              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     567            1 :             spdm_encapsulated_response_ack_response->param1 = 0;
     568            1 :             spdm_encapsulated_response_ack_response->param2 =
     569              :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
     570            1 :             sub_index = 0;
     571              :         } else {
     572            0 :             temp_buf_size = 0;
     573            0 :             temp_buf_ptr = NULL;
     574              :         }
     575            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     576              :                                               temp_buf_size, temp_buf_ptr,
     577              :                                               response_size, response);
     578              :     }
     579            2 :         return LIBSPDM_STATUS_SUCCESS;
     580              : 
     581            1 :     case 0xB:
     582              :     {
     583              :         spdm_error_response_t *spdm_response;
     584              : 
     585            1 :         temp_buf_size = sizeof(spdm_error_response_t);
     586            1 :         libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     587            1 :         temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     588            1 :         spdm_response = (void *) temp_buf_ptr;
     589            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     590            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     591            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
     592            1 :         spdm_response->header.param2 = 0;
     593              : 
     594            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     595              :                                               temp_buf_size, temp_buf_ptr,
     596              :                                               response_size, response);
     597              :     }
     598            1 :         return LIBSPDM_STATUS_SUCCESS;
     599              : 
     600            1 :     case 0xC:
     601              :     {
     602              :         spdm_error_response_t *spdm_response;
     603              : 
     604            1 :         temp_buf_size = sizeof(spdm_error_response_t);
     605            1 :         libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     606            1 :         temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     607            1 :         spdm_response = (void *) temp_buf_ptr;
     608            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     609            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     610            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_NO_PENDING_REQUESTS;
     611            1 :         spdm_response->header.param2 = 0;
     612              : 
     613            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     614              :                                               temp_buf_size, temp_buf_ptr,
     615              :                                               response_size, response);
     616              :     }
     617            1 :         return LIBSPDM_STATUS_SUCCESS;
     618              : 
     619            2 :     case 0xD:
     620              :     {
     621              :         spdm_get_endpoint_info_request_t *spdm_response;
     622              :         uint8_t *spdm_nonce;
     623              : 
     624              :         ((libspdm_context_t *)spdm_context)
     625            2 :         ->connection_info.algorithm.base_hash_algo =
     626              :             m_libspdm_use_hash_algo;
     627            2 :         if (sub_index == 0) {
     628            1 :             temp_buf_size = sizeof(spdm_encapsulated_request_response_t) +
     629              :                             sizeof(spdm_get_endpoint_info_request_t) + SPDM_NONCE_SIZE;
     630            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     631            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     632            1 :             libspdm_encapsulated_request_response = (void *)temp_buf_ptr;
     633            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     634            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     635              :                 SPDM_ENCAPSULATED_REQUEST;
     636            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     637            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     638              : 
     639            1 :             spdm_response =
     640              :                 (void *)(temp_buf_ptr + sizeof(spdm_encapsulated_request_response_t));
     641            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     642            1 :             spdm_response->header.request_response_code = SPDM_GET_ENDPOINT_INFO;
     643            1 :             spdm_response->header.param1 =
     644              :                 SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER;
     645            1 :             spdm_response->header.param2 = 0; /* slot_id */
     646            1 :             spdm_response->request_attributes =
     647              :                 SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED;
     648            1 :             libspdm_write_uint24(spdm_response->reserved, 0);
     649            1 :             spdm_nonce = (uint8_t *)(spdm_response + 1);
     650            1 :             libspdm_get_random_number(SPDM_NONCE_SIZE, spdm_nonce);
     651              : 
     652            1 :             sub_index++;
     653            1 :         } else if (sub_index == 1) {
     654              :             spdm_encapsulated_response_ack_response_t *spdm_encapsulated_response_ack_response;
     655            1 :             temp_buf_size = sizeof(spdm_encapsulated_response_ack_response_t);
     656            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     657            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     658            1 :             spdm_encapsulated_response_ack_response = (void *)temp_buf_ptr;
     659            1 :             spdm_encapsulated_response_ack_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
     660            1 :             spdm_encapsulated_response_ack_response->header.request_response_code =
     661              :                 SPDM_ENCAPSULATED_RESPONSE_ACK;
     662            1 :             spdm_encapsulated_response_ack_response->header.param1 = 0;
     663            1 :             spdm_encapsulated_response_ack_response->header.param2 =
     664              :                 SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_ABSENT;
     665            1 :             spdm_encapsulated_response_ack_response->ack_request_id = 0;
     666            1 :             libspdm_write_uint24(spdm_encapsulated_response_ack_response->reserved, 0);
     667              : 
     668            1 :             sub_index = 0;
     669              :         } else {
     670            0 :             temp_buf_size = 0;
     671            0 :             temp_buf_ptr = NULL;
     672              :         }
     673            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     674              :                                               temp_buf_size, temp_buf_ptr,
     675              :                                               response_size, response);
     676              :     }
     677            2 :         return LIBSPDM_STATUS_SUCCESS;
     678            1 :     case 0xE:
     679              :     {
     680              :         spdm_error_response_t *spdm_response;
     681              : 
     682            1 :         temp_buf_size = sizeof(spdm_error_response_t);
     683            1 :         libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     684            1 :         temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     685            1 :         spdm_response = (void *) temp_buf_ptr;
     686            1 :         spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     687            1 :         spdm_response->header.request_response_code = SPDM_ERROR;
     688            1 :         spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     689            1 :         spdm_response->header.param2 = 0;
     690            1 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     691              :                                               temp_buf_size, temp_buf_ptr,
     692              :                                               response_size, response);
     693              :     }
     694            1 :         return LIBSPDM_STATUS_SUCCESS;
     695            2 :     case 0xF:
     696              :     {
     697              :         spdm_digest_response_t *spdm_response;
     698              : 
     699              :         ((libspdm_context_t *)spdm_context)
     700            2 :         ->connection_info.algorithm.base_hash_algo =
     701              :             m_libspdm_use_hash_algo;
     702            2 :         if (sub_index == 0) {
     703            1 :             temp_buf_size = sizeof(spdm_digest_response_t) +
     704            1 :                             libspdm_get_hash_size(m_libspdm_use_hash_algo) +
     705              :                             sizeof(spdm_encapsulated_request_response_t);
     706            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     707            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     708            1 :             libspdm_encapsulated_request_response = (void*) temp_buf_ptr;
     709            1 :             libspdm_encapsulated_request_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     710            1 :             libspdm_encapsulated_request_response->header.request_response_code =
     711              :                 SPDM_ENCAPSULATED_REQUEST;
     712            1 :             libspdm_encapsulated_request_response->header.param1 = 0;
     713            1 :             libspdm_encapsulated_request_response->header.param2 = 0;
     714              : 
     715            1 :             spdm_response = (void *)(temp_buf_ptr
     716              :                                      + sizeof(spdm_encapsulated_request_response_t));
     717            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
     718            1 :             spdm_response->header.request_response_code = SPDM_GET_DIGESTS;
     719            1 :             spdm_response->header.param1 = 0;
     720            1 :             spdm_response->header.param2 = 0;
     721            1 :             libspdm_set_mem(m_libspdm_local_certificate_chain,
     722              :                             sizeof(m_libspdm_local_certificate_chain),
     723              :                             (uint8_t)(0xFF));
     724              : 
     725            1 :             digest = (void *)(spdm_response + 1);
     726            1 :             libspdm_hash_all(m_libspdm_use_hash_algo, m_libspdm_local_certificate_chain,
     727              :                              sizeof(m_libspdm_local_certificate_chain), &digest[0]);
     728            1 :             spdm_response->header.param2 |= (0x01 << 0);
     729            1 :             sub_index++;
     730            1 :         } else if (sub_index == 1) {
     731            1 :             temp_buf_size = sizeof(spdm_error_response_t);
     732            1 :             libspdm_zero_mem(temp_buf, LIBSPDM_RECEIVER_BUFFER_SIZE);
     733            1 :             temp_buf_ptr = temp_buf + sizeof(libspdm_test_message_header_t);
     734            1 :             spdm_response = (void *) temp_buf_ptr;
     735            1 :             spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
     736            1 :             spdm_response->header.request_response_code = SPDM_ERROR;
     737            1 :             spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
     738            1 :             spdm_response->header.param2 = 0;
     739            1 :             sub_index = 0;
     740              :         } else {
     741            0 :             temp_buf_size = 0;
     742            0 :             temp_buf_ptr = NULL;
     743              :         }
     744            2 :         libspdm_transport_test_encode_message(spdm_context, NULL, false, false,
     745              :                                               temp_buf_size, temp_buf_ptr,
     746              :                                               response_size, response);
     747              :     }
     748            2 :         return LIBSPDM_STATUS_SUCCESS;
     749            0 :     default:
     750            0 :         return LIBSPDM_STATUS_RECEIVE_FAIL;
     751              :     }
     752              : }
     753              : 
     754              : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
     755            1 : void libspdm_test_requester_encap_request_case1(void **State)
     756              : {
     757              :     libspdm_return_t status;
     758              :     libspdm_test_context_t *spdm_test_context;
     759              :     libspdm_context_t *spdm_context;
     760              :     void *data;
     761              :     size_t data_size;
     762              :     void *hash;
     763              :     size_t hash_size;
     764              : 
     765            1 :     spdm_test_context = *State;
     766            1 :     spdm_context = spdm_test_context->spdm_context;
     767            1 :     spdm_test_context->case_id = 0x1;
     768              : 
     769            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     770              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     771            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     772            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
     773            1 :     spdm_context->connection_info.capability.flags |=
     774              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
     775            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     776            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
     777            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
     778            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     779            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
     780            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
     781              : 
     782            1 :     spdm_context->connection_info.capability.flags |=
     783              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
     784            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     785              :                                                     m_libspdm_use_asym_algo, &data,
     786              :                                                     &data_size,
     787              :                                                     &hash, &hash_size);
     788            1 :     libspdm_reset_message_a(spdm_context);
     789            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     790            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     791            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     792            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     793              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     794              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
     795              :         data_size;
     796              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
     797              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
     798              :                      data, data_size);
     799              : #endif
     800              : 
     801            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
     802            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
     803            1 :     assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL);
     804            1 :     free(data);
     805            1 : }
     806              : 
     807            1 : void libspdm_test_requester_encap_request_case2(void **State)
     808              : {
     809              :     libspdm_return_t status;
     810              :     libspdm_test_context_t *spdm_test_context;
     811              :     libspdm_context_t *spdm_context;
     812              :     void *data;
     813              :     size_t data_size;
     814              :     void *hash;
     815              :     size_t hash_size;
     816              : 
     817            1 :     spdm_test_context = *State;
     818            1 :     spdm_context = spdm_test_context->spdm_context;
     819            1 :     spdm_test_context->case_id = 0x2;
     820              : 
     821            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     822              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     823            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     824            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
     825            1 :     spdm_context->connection_info.capability.flags |=
     826              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
     827            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     828            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
     829            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
     830            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     831            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
     832            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
     833            1 :     spdm_context->connection_info.capability.flags |=
     834              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
     835            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     836              :                                                     m_libspdm_use_asym_algo, &data,
     837              :                                                     &data_size,
     838              :                                                     &hash, &hash_size);
     839            1 :     libspdm_reset_message_a(spdm_context);
     840            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     841            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     842            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     843            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     844              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     845              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
     846              :         data_size;
     847              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
     848              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
     849              :                      data, data_size);
     850              : #endif
     851              : 
     852            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
     853            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
     854            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
     855            1 :     free(data);
     856            1 : }
     857              : 
     858            0 : void libspdm_test_requester_encap_request_case3(void **State)
     859              : {
     860            0 : }
     861              : 
     862            1 : void libspdm_test_requester_encap_request_case4(void **State)
     863              : {
     864              :     libspdm_return_t status;
     865              :     libspdm_test_context_t *spdm_test_context;
     866              :     libspdm_context_t *spdm_context;
     867              :     void *data;
     868              :     size_t data_size;
     869              :     void *hash;
     870              :     size_t hash_size;
     871              : 
     872            1 :     spdm_test_context = *State;
     873            1 :     spdm_context = spdm_test_context->spdm_context;
     874            1 :     spdm_test_context->case_id = 0x4;
     875              : 
     876            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     877              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     878            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     879            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
     880            1 :     spdm_context->connection_info.capability.flags |=
     881              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
     882            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     883            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
     884            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
     885            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     886            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
     887            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
     888            1 :     spdm_context->connection_info.capability.flags |=
     889              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
     890            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     891              :                                                     m_libspdm_use_asym_algo, &data,
     892              :                                                     &data_size,
     893              :                                                     &hash, &hash_size);
     894            1 :     libspdm_reset_message_a(spdm_context);
     895            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     896            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     897            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     898            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     899              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     900              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
     901              :         data_size;
     902              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
     903              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
     904              :                      data, data_size);
     905              : #endif
     906              : 
     907            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
     908            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
     909            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_SIZE);
     910            1 :     free(data);
     911            1 : }
     912              : 
     913            1 : void libspdm_test_requester_encap_request_case5(void **State)
     914              : {
     915              :     libspdm_return_t status;
     916              :     libspdm_test_context_t *spdm_test_context;
     917              :     libspdm_context_t *spdm_context;
     918              :     void *data;
     919              :     size_t data_size;
     920              :     void *hash;
     921              :     size_t hash_size;
     922              : 
     923            1 :     spdm_test_context = *State;
     924            1 :     spdm_context = spdm_test_context->spdm_context;
     925            1 :     spdm_test_context->case_id = 0x5;
     926              : 
     927            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     928              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     929            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     930            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
     931            1 :     spdm_context->connection_info.capability.flags |=
     932              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
     933            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     934            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
     935            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
     936            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     937            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
     938            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
     939            1 :     spdm_context->connection_info.capability.flags |=
     940              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
     941            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     942              :                                                     m_libspdm_use_asym_algo, &data,
     943              :                                                     &data_size,
     944              :                                                     &hash, &hash_size);
     945            1 :     libspdm_reset_message_a(spdm_context);
     946            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
     947            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
     948            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
     949            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
     950              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
     951              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
     952              :         data_size;
     953              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
     954              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
     955              :                      data, data_size);
     956              : #endif
     957              : 
     958            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
     959            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
     960            1 :     assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
     961            1 :     free(data);
     962            1 : }
     963              : 
     964            0 : void libspdm_test_requester_encap_request_case6(void **State)
     965              : {
     966            0 : }
     967              : 
     968            1 : void libspdm_test_requester_encap_request_case7(void **State)
     969              : {
     970              :     libspdm_return_t status;
     971              :     libspdm_test_context_t *spdm_test_context;
     972              :     libspdm_context_t *spdm_context;
     973              :     void *data;
     974              :     size_t data_size;
     975              :     void *hash;
     976              :     size_t hash_size;
     977              : 
     978            1 :     spdm_test_context = *State;
     979            1 :     spdm_context = spdm_test_context->spdm_context;
     980            1 :     spdm_test_context->case_id = 0x7;
     981              : 
     982            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
     983              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
     984            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
     985            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
     986            1 :     spdm_context->connection_info.capability.flags |=
     987              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
     988            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
     989            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
     990            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
     991            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
     992            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
     993            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
     994            1 :     spdm_context->connection_info.capability.flags |=
     995              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
     996            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
     997              :                                                     m_libspdm_use_asym_algo, &data,
     998              :                                                     &data_size,
     999              :                                                     &hash, &hash_size);
    1000            1 :     libspdm_reset_message_a(spdm_context);
    1001            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1002            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1003            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1004            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1005              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1006              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    1007              :         data_size;
    1008              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    1009              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    1010              :                      data, data_size);
    1011              : #endif
    1012              : 
    1013            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
    1014            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1015            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1016            1 :     free(data);
    1017            1 : }
    1018              : 
    1019            1 : void libspdm_test_requester_encap_request_case8(void **State)
    1020              : {
    1021              :     libspdm_return_t status;
    1022              :     libspdm_test_context_t *spdm_test_context;
    1023              :     libspdm_context_t *spdm_context;
    1024              :     void *data;
    1025              :     size_t data_size;
    1026              :     void *hash;
    1027              :     size_t hash_size;
    1028              : 
    1029            1 :     spdm_test_context = *State;
    1030            1 :     spdm_context = spdm_test_context->spdm_context;
    1031            1 :     spdm_test_context->case_id = 0x8;
    1032              : 
    1033            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1034              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1035            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1036            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
    1037            1 :     spdm_context->connection_info.capability.flags |=
    1038              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
    1039            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1040            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
    1041            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
    1042            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1043            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1044            1 :     spdm_context->local_context.capability.flags |=
    1045              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
    1046            1 :     spdm_context->connection_info.capability.flags |=
    1047              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1048            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1049              :                                                     m_libspdm_use_asym_algo, &data,
    1050              :                                                     &data_size,
    1051              :                                                     &hash, &hash_size);
    1052            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
    1053            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
    1054              : 
    1055            1 :     libspdm_reset_message_a(spdm_context);
    1056            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1057            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1058            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1059            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1060              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1061              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    1062              :         data_size;
    1063              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    1064              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    1065              :                      data, data_size);
    1066              : #endif
    1067              : 
    1068            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_certificate);
    1069            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1070            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1071            1 :     free(data);
    1072            1 : }
    1073              : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP) */
    1074              : 
    1075            1 : void libspdm_test_requester_encap_request_case9(void **State)
    1076              : {
    1077              :     libspdm_return_t status;
    1078              :     libspdm_test_context_t *spdm_test_context;
    1079              :     libspdm_context_t *spdm_context;
    1080              :     void *data;
    1081              :     size_t data_size;
    1082              :     void *hash;
    1083              :     size_t hash_size;
    1084              : 
    1085            1 :     spdm_test_context = *State;
    1086            1 :     spdm_context = spdm_test_context->spdm_context;
    1087            1 :     spdm_test_context->case_id = 0x9;
    1088              : 
    1089            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1090              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1091            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1092            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
    1093            1 :     spdm_context->connection_info.capability.flags |=
    1094              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
    1095            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1096            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
    1097            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
    1098            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1099            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1100            1 :     spdm_context->connection_info.capability.flags |=
    1101              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
    1102            1 :     spdm_context->local_context.capability.flags |=
    1103              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
    1104            1 :     spdm_context->connection_info.capability.flags |=
    1105              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1106            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1107              :                                                     m_libspdm_use_asym_algo, &data,
    1108              :                                                     &data_size,
    1109              :                                                     &hash, &hash_size);
    1110            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
    1111            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
    1112              : 
    1113            1 :     libspdm_reset_message_a(spdm_context);
    1114            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1115            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1116            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1117            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1118              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1119              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    1120              :         data_size;
    1121              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    1122              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    1123              :                      data, data_size);
    1124              : #endif
    1125              : 
    1126            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_key_update);
    1127            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1128            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1129            1 :     free(data);
    1130            1 : }
    1131              : 
    1132              : /**
    1133              :  * Test 10: GET_ENCAPSULATED_REQUEST request message is encapsulated in ENCAPSULATED_REQUEST response message.
    1134              :  * Expected Behavior: the Requester should respond with ErrorCode=UnexpectedRequest.
    1135              :  **/
    1136            1 : void libspdm_test_requester_encap_request_case10(void **State)
    1137              : {
    1138              :     libspdm_return_t status;
    1139              :     libspdm_test_context_t *spdm_test_context;
    1140              :     libspdm_context_t *spdm_context;
    1141              : 
    1142            1 :     spdm_test_context = *State;
    1143            1 :     spdm_context = spdm_test_context->spdm_context;
    1144            1 :     spdm_test_context->case_id = 0xA;
    1145              : 
    1146            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1147              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1148            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1149            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1150            1 :     spdm_context->connection_info.capability.flags |=
    1151              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1152              : 
    1153            1 :     libspdm_register_get_encap_response_func(spdm_context, NULL);
    1154            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1155            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1156            1 : }
    1157              : 
    1158              : /**
    1159              :  * Test 11: In a non-mutual-authentication context, Requester sends GET_ENCAPSULATED_REQUEST and
    1160              :  *          Responder replies with UnexpectedRequest.
    1161              :  * Expected Behavior: return LIBSPDM_STATUS_SUCCESS as Responder did not have a pending request for
    1162              :  *                    the Requester.
    1163              :  **/
    1164            1 : void libspdm_test_requester_encap_request_case11(void **State)
    1165              : {
    1166              :     libspdm_return_t status;
    1167              :     libspdm_test_context_t *spdm_test_context;
    1168              :     libspdm_context_t *spdm_context;
    1169              : 
    1170            1 :     spdm_test_context = *State;
    1171            1 :     spdm_context = spdm_test_context->spdm_context;
    1172            1 :     spdm_test_context->case_id = 0xB;
    1173              : 
    1174            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1175              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1176            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1177            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1178            1 :     spdm_context->connection_info.capability.flags |=
    1179              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1180              : 
    1181            1 :     libspdm_register_get_encap_response_func(spdm_context, NULL);
    1182            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1183            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1184            1 : }
    1185              : 
    1186              : /**
    1187              :  * Test 12: In a non-mutual-authentication context, Requester sends GET_ENCAPSULATED_REQUEST and
    1188              :  *          Responder replies with NoPendingRequests.
    1189              :  * Expected Behavior: return LIBSPDM_STATUS_SUCCESS as Responder did not have a pending request for
    1190              :  *                    the Requester.
    1191              :  **/
    1192            1 : void libspdm_test_requester_encap_request_case12(void **State)
    1193              : {
    1194              :     libspdm_return_t status;
    1195              :     libspdm_test_context_t *spdm_test_context;
    1196              :     libspdm_context_t *spdm_context;
    1197              : 
    1198            1 :     spdm_test_context = *State;
    1199            1 :     spdm_context = spdm_test_context->spdm_context;
    1200            1 :     spdm_test_context->case_id = 0xC;
    1201              : 
    1202            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1203              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1204            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1205            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1206            1 :     spdm_context->connection_info.capability.flags |=
    1207              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1208              : 
    1209            1 :     libspdm_register_get_encap_response_func(spdm_context, NULL);
    1210            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1211            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1212            1 : }
    1213              : 
    1214              : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
    1215            1 : void libspdm_test_requester_encap_request_case13(void **State)
    1216              : {
    1217              :     libspdm_return_t status;
    1218              :     libspdm_test_context_t *spdm_test_context;
    1219              :     libspdm_context_t *spdm_context;
    1220              :     void *data;
    1221              :     size_t data_size;
    1222              :     void *hash;
    1223              :     size_t hash_size;
    1224              : 
    1225            1 :     spdm_test_context = *State;
    1226            1 :     spdm_context = spdm_test_context->spdm_context;
    1227            1 :     spdm_test_context->case_id = 0xD;
    1228              : 
    1229            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
    1230              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1231            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1232            1 :     spdm_context->connection_info.capability.flags = 0;
    1233            1 :     spdm_context->local_context.capability.flags = 0;
    1234            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1235            1 :     spdm_context->connection_info.capability.flags |=
    1236              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1237            1 :     spdm_context->local_context.capability.flags |=
    1238              :         SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EP_INFO_CAP_SIG;
    1239            1 :     libspdm_read_requester_public_certificate_chain(m_libspdm_use_hash_algo,
    1240              :                                                     m_libspdm_use_req_asym_algo, &data,
    1241              :                                                     &data_size,
    1242              :                                                     &hash, &hash_size);
    1243            1 :     spdm_context->local_context.local_cert_chain_provision[0] = data;
    1244            1 :     spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
    1245              : 
    1246            1 :     libspdm_reset_message_a(spdm_context);
    1247            1 :     libspdm_reset_message_encap_e(spdm_context, NULL);
    1248            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1249            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1250            1 :     spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
    1251              : 
    1252              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1253              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    1254              :         data_size;
    1255              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    1256              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    1257              :                      data, data_size);
    1258              : #endif
    1259              : 
    1260            1 :     libspdm_register_get_encap_response_func(spdm_context,
    1261              :                                              libspdm_get_encap_response_endpoint_info);
    1262            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1263            1 :     assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
    1264            1 :     free(data);
    1265            1 : }
    1266              : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
    1267              : 
    1268            1 : void libspdm_test_requester_encap_request_case14(void **State)
    1269              : {
    1270              :     libspdm_return_t status;
    1271              :     libspdm_test_context_t *spdm_test_context;
    1272              :     libspdm_context_t *spdm_context;
    1273              :     void *data;
    1274              :     size_t data_size;
    1275              :     void *hash;
    1276              :     size_t hash_size;
    1277              : 
    1278            1 :     spdm_test_context = *State;
    1279            1 :     spdm_context = spdm_test_context->spdm_context;
    1280            1 :     spdm_test_context->case_id = 0xE;
    1281              : 
    1282            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1283              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1284            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1285            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
    1286            1 :     spdm_context->connection_info.capability.flags |=
    1287              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
    1288            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1289            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
    1290            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
    1291            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1292            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1293            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
    1294            1 :     spdm_context->connection_info.capability.flags |=
    1295              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1296            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1297              :                                                     m_libspdm_use_asym_algo, &data,
    1298              :                                                     &data_size,
    1299              :                                                     &hash, &hash_size);
    1300            1 :     libspdm_reset_message_a(spdm_context);
    1301            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1302            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1303            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1304            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1305              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1306              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    1307              :         data_size;
    1308              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    1309              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    1310              :                      data, data_size);
    1311              : #endif
    1312              : 
    1313            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
    1314            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1315            1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
    1316            1 :     assert_int_equal(spdm_context->connection_info.connection_state,
    1317              :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
    1318            1 :     free(data);
    1319            1 : }
    1320              : 
    1321            1 : void libspdm_test_requester_encap_request_case15(void **State)
    1322              : {
    1323              :     libspdm_return_t status;
    1324              :     libspdm_test_context_t *spdm_test_context;
    1325              :     libspdm_context_t *spdm_context;
    1326              :     void *data;
    1327              :     size_t data_size;
    1328              :     void *hash;
    1329              :     size_t hash_size;
    1330              : 
    1331            1 :     spdm_test_context = *State;
    1332            1 :     spdm_context = spdm_test_context->spdm_context;
    1333            1 :     spdm_test_context->case_id = 0xF;
    1334              : 
    1335            1 :     spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
    1336              :                                             SPDM_VERSION_NUMBER_SHIFT_BIT;
    1337            1 :     spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
    1338            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP;
    1339            1 :     spdm_context->connection_info.capability.flags |=
    1340              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
    1341            1 :     spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
    1342            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP;
    1343            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
    1344            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
    1345            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
    1346            1 :     spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
    1347            1 :     spdm_context->connection_info.capability.flags |=
    1348              :         SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
    1349            1 :     libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
    1350              :                                                     m_libspdm_use_asym_algo, &data,
    1351              :                                                     &data_size,
    1352              :                                                     &hash, &hash_size);
    1353            1 :     libspdm_reset_message_a(spdm_context);
    1354            1 :     spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
    1355            1 :     spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
    1356            1 :     spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
    1357            1 :     spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
    1358              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
    1359              :     spdm_context->connection_info.peer_used_cert_chain[0].buffer_size =
    1360              :         data_size;
    1361              :     libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[0].buffer,
    1362              :                      sizeof(spdm_context->connection_info.peer_used_cert_chain[0].buffer),
    1363              :                      data, data_size);
    1364              : #endif
    1365              : 
    1366            1 :     libspdm_register_get_encap_response_func(spdm_context, libspdm_get_encap_response_digest);
    1367            1 :     status = libspdm_encapsulated_request(spdm_context, NULL, 0, NULL);
    1368            1 :     assert_int_equal(status, LIBSPDM_STATUS_RESYNCH_PEER);
    1369            1 :     assert_int_equal(spdm_context->connection_info.connection_state,
    1370              :                      LIBSPDM_CONNECTION_STATE_NOT_STARTED);
    1371            1 :     free(data);
    1372            1 : }
    1373              : 
    1374            1 : int libspdm_requester_encap_request_test_main(void)
    1375              : {
    1376            1 :     const struct CMUnitTest spdm_requester_encap_request_tests[] = {
    1377              :         /* SendRequest failed*/
    1378              : #if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_ENABLE_CAPABILITY_CERT_CAP)
    1379              :         cmocka_unit_test(libspdm_test_requester_encap_request_case1),
    1380              :         /* Success Case ,func :libspdm_get_encap_response_digest*/
    1381              :         cmocka_unit_test(libspdm_test_requester_encap_request_case2),
    1382              :         /* Error response:Receive message only SPDM ENCAPSULATED_REQUEST response*/
    1383              :         cmocka_unit_test(libspdm_test_requester_encap_request_case4),
    1384              :         /* Error response: spdm_encapsulated_response_ack_response == NULL*/
    1385              :         cmocka_unit_test(libspdm_test_requester_encap_request_case5),
    1386              :         /* response: param2 == SPDM_ENCAPSULATED_RESPONSE_ACK_RESPONSE_PAYLOAD_TYPE_REQ_SLOT_NUMBER*/
    1387              :         cmocka_unit_test(libspdm_test_requester_encap_request_case7),
    1388              :         /*Success Case ,func :libspdm_get_encap_response_certificate */
    1389              :         cmocka_unit_test(libspdm_test_requester_encap_request_case8),
    1390              : #endif /* (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (..) */
    1391              : 
    1392              :         /*Success Case ,func :libspdm_get_encap_response_key_update */
    1393              :         cmocka_unit_test(libspdm_test_requester_encap_request_case9),
    1394              :         /*Error response: GET_ENCAPSULATED_REQUEST message is encapsulated */
    1395              :         cmocka_unit_test(libspdm_test_requester_encap_request_case10),
    1396              :         cmocka_unit_test(libspdm_test_requester_encap_request_case11),
    1397              :         cmocka_unit_test(libspdm_test_requester_encap_request_case12),
    1398              : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
    1399              :         /*Success Case ,func :libspdm_get_encap_response_endpoint_info */
    1400              :         cmocka_unit_test(libspdm_test_requester_encap_request_case13),
    1401              : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
    1402              :         /* Error response: send SPDM_GET_ENCAPSULATED_REQUEST and receive request resync */
    1403              :         cmocka_unit_test(libspdm_test_requester_encap_request_case14),
    1404              :         /* Error response: send SPDM_DELIVER_ENCAPSULATED_RESPONSE and receive request resync */
    1405              :         cmocka_unit_test(libspdm_test_requester_encap_request_case15),
    1406              : 
    1407              :     };
    1408              : 
    1409            1 :     libspdm_test_context_t test_context = {
    1410              :         LIBSPDM_TEST_CONTEXT_VERSION,
    1411              :         true,
    1412              :         libspdm_requester_encap_request_test_send_message,
    1413              :         libspdm_requester_encap_request_test_receive_message,
    1414              :     };
    1415              : 
    1416            1 :     libspdm_setup_test_context(&test_context);
    1417              : 
    1418            1 :     return cmocka_run_group_tests(spdm_requester_encap_request_tests,
    1419              :                                   libspdm_unit_test_group_setup,
    1420              :                                   libspdm_unit_test_group_teardown);
    1421              : }
    1422              : 
    1423              : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
        

Generated by: LCOV version 2.0-1