LCOV - code coverage report
Current view: top level - library/spdm_responder_lib - libspdm_rsp_psk_exchange.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 70.1 % 187 131
Test Date: 2025-10-12 08:10:56 Functions: 100.0 % 2 2

            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 "internal/libspdm_responder_lib.h"
       8              : #include "internal/libspdm_secured_message_lib.h"
       9              : 
      10              : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
      11              : 
      12              : /**
      13              :  * This function generates the PSK exchange HMAC based upon TH.
      14              :  *
      15              :  * @param  spdm_context                  A pointer to the SPDM context.
      16              :  * @param  session_info                  The session info of an SPDM session.
      17              :  * @param  hmac                         The buffer to store the PSK exchange HMAC.
      18              :  *
      19              :  * @retval true  PSK exchange HMAC is generated.
      20              :  * @retval false PSK exchange HMAC is not generated.
      21              :  **/
      22           11 : static bool libspdm_generate_psk_exchange_rsp_hmac(libspdm_context_t *spdm_context,
      23              :                                                    libspdm_session_info_t *session_info,
      24              :                                                    uint8_t *hmac)
      25              : {
      26              :     uint8_t hmac_data[LIBSPDM_MAX_HASH_SIZE];
      27              :     size_t hash_size;
      28              :     bool result;
      29              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
      30              :     uint8_t *th_curr_data;
      31              :     size_t th_curr_data_size;
      32              :     libspdm_th_managed_buffer_t th_curr;
      33              :     uint8_t hash_data[LIBSPDM_MAX_HASH_SIZE];
      34              : #endif
      35              : 
      36           11 :     hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
      37              : 
      38              : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
      39              :     result = libspdm_calculate_th_for_exchange(spdm_context, session_info,
      40              :                                                NULL, 0, &th_curr);
      41              :     if (!result) {
      42              :         return false;
      43              :     }
      44              :     th_curr_data = libspdm_get_managed_buffer(&th_curr);
      45              :     th_curr_data_size = libspdm_get_managed_buffer_size(&th_curr);
      46              : 
      47              :     result = libspdm_hash_all (spdm_context->connection_info.algorithm.base_hash_algo,
      48              :                                th_curr_data, th_curr_data_size, hash_data);
      49              :     if (!result) {
      50              :         return false;
      51              :     }
      52              : 
      53              :     result = libspdm_hmac_all_with_response_finished_key(
      54              :         session_info->secured_message_context, hash_data,
      55              :         hash_size, hmac_data);
      56              :     if (!result) {
      57              :         return false;
      58              :     }
      59              : #else
      60           11 :     result = libspdm_calculate_th_hmac_for_exchange_rsp(
      61              :         spdm_context, session_info, &hash_size, hmac_data);
      62           11 :     if (!result) {
      63            0 :         return false;
      64              :     }
      65              : #endif
      66           11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "th_curr hmac - "));
      67           11 :     LIBSPDM_INTERNAL_DUMP_DATA(hmac_data, hash_size);
      68           11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
      69              : 
      70           11 :     libspdm_copy_mem(hmac, hash_size, hmac_data, hash_size);
      71              : 
      72           11 :     return true;
      73              : }
      74              : 
      75           18 : libspdm_return_t libspdm_get_response_psk_exchange(libspdm_context_t *spdm_context,
      76              :                                                    size_t request_size,
      77              :                                                    const void *request,
      78              :                                                    size_t *response_size,
      79              :                                                    void *response)
      80              : {
      81              :     const spdm_psk_exchange_request_t *spdm_request;
      82              :     spdm_psk_exchange_response_t *spdm_response;
      83              :     bool result;
      84              :     uint32_t session_id;
      85              :     uint32_t measurement_summary_hash_size;
      86              :     uint32_t hmac_size;
      87              :     const uint8_t *cptr;
      88              :     uint8_t *ptr;
      89              :     libspdm_session_info_t *session_info;
      90              :     size_t total_size;
      91              :     uint16_t req_session_id;
      92              :     uint16_t rsp_session_id;
      93              :     libspdm_return_t status;
      94              :     size_t opaque_psk_exchange_rsp_size;
      95              :     uint8_t th1_hash_data[LIBSPDM_MAX_HASH_SIZE];
      96              :     uint8_t th2_hash_data[LIBSPDM_MAX_HASH_SIZE];
      97              :     uint32_t algo_size;
      98              :     uint16_t context_length;
      99              :     const void *psk_hint;
     100              :     size_t psk_hint_size;
     101              :     spdm_version_number_t secured_message_version;
     102              : 
     103           18 :     spdm_request = request;
     104              : 
     105              :     /* -=[Check Parameters Phase]=- */
     106           18 :     LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_PSK_EXCHANGE);
     107              : 
     108           18 :     if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
     109            0 :         return libspdm_generate_error_response(spdm_context,
     110              :                                                SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
     111              :                                                SPDM_PSK_EXCHANGE,
     112              :                                                response_size, response);
     113              :     }
     114              : 
     115           18 :     if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
     116            0 :         return libspdm_generate_error_response(spdm_context,
     117              :                                                SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
     118              :                                                response_size, response);
     119              :     }
     120           18 :     if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
     121            3 :         return libspdm_responder_handle_response_state(
     122              :             spdm_context,
     123            3 :             spdm_request->header.request_response_code,
     124              :             response_size, response);
     125              :     }
     126              :     /* Check capabilities even if GET_CAPABILITIES is not sent.
     127              :      * Assuming capabilities are provisioned.*/
     128           15 :     if (!libspdm_is_capabilities_flag_supported(
     129              :             spdm_context, false,
     130              :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP,
     131              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP)) {
     132            0 :         return libspdm_generate_error_response(
     133              :             spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
     134              :             SPDM_PSK_EXCHANGE, response_size, response);
     135              :     }
     136              : 
     137              :     /* While clearing MAC_CAP and setting ENCRYPT_CAP is legal according to DSP0274, libspdm
     138              :      * also implements DSP0277 secure messages, which requires at least MAC_CAP to be set.
     139              :      */
     140           15 :     if (!libspdm_is_capabilities_flag_supported(
     141              :             spdm_context, false,
     142              :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP,
     143              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP)) {
     144            0 :         return libspdm_generate_error_response(
     145              :             spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
     146              :             SPDM_KEY_EXCHANGE, response_size, response);
     147              :     }
     148              : 
     149           15 :     if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
     150            1 :         return libspdm_generate_error_response(spdm_context,
     151              :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
     152              :                                                0, response_size, response);
     153              :     }
     154           14 :     if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_12) {
     155            2 :         if ((spdm_context->connection_info.algorithm.other_params_support &
     156              :              SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_MASK) != SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1) {
     157            0 :             return libspdm_generate_error_response(
     158              :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
     159              :                 0, response_size, response);
     160              :         }
     161              :     }
     162           14 :     if (spdm_context->last_spdm_request_session_id_valid) {
     163            0 :         return libspdm_generate_error_response(spdm_context,
     164              :                                                SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
     165              :                                                0, response_size, response);
     166              :     }
     167              : 
     168              :     {
     169              :         /* Double check if algorithm has been provisioned, because ALGORITHM might be skipped.*/
     170           14 :         if (libspdm_is_capabilities_flag_supported(
     171              :                 spdm_context, true, 0,
     172              :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
     173            0 :             if (spdm_context->connection_info.algorithm
     174            0 :                 .measurement_spec != SPDM_MEASUREMENT_SPECIFICATION_DMTF) {
     175            0 :                 return libspdm_generate_error_response(
     176              :                     spdm_context,
     177              :                     SPDM_ERROR_CODE_INVALID_REQUEST,
     178              :                     0, response_size,
     179              :                     response);
     180              :             }
     181            0 :             algo_size = libspdm_get_measurement_hash_size(
     182              :                 spdm_context->connection_info.algorithm
     183              :                 .measurement_hash_algo);
     184            0 :             if (algo_size == 0) {
     185            0 :                 return libspdm_generate_error_response(
     186              :                     spdm_context,
     187              :                     SPDM_ERROR_CODE_INVALID_REQUEST,
     188              :                     0, response_size,
     189              :                     response);
     190              :             }
     191              :         }
     192           14 :         algo_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
     193           14 :         if (algo_size == 0) {
     194            0 :             return libspdm_generate_error_response(
     195              :                 spdm_context,
     196              :                 SPDM_ERROR_CODE_INVALID_REQUEST,
     197              :                 0, response_size, response);
     198              :         }
     199           14 :         if (spdm_context->connection_info.algorithm.key_schedule !=
     200              :             SPDM_ALGORITHMS_KEY_SCHEDULE_SPDM) {
     201            0 :             return libspdm_generate_error_response(
     202              :                 spdm_context,
     203              :                 SPDM_ERROR_CODE_INVALID_REQUEST,
     204              :                 0, response_size, response);
     205              :         }
     206              :     }
     207              : 
     208           14 :     if (spdm_request->header.param1 > 0) {
     209            4 :         if (!libspdm_is_capabilities_flag_supported(
     210              :                 spdm_context, false,
     211            3 :                 0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) ||
     212            3 :             (spdm_context->connection_info.algorithm.measurement_spec == 0) ||
     213            3 :             (spdm_context->connection_info.algorithm.measurement_hash_algo == 0) ) {
     214            1 :             return libspdm_generate_error_response(
     215              :                 spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST,
     216              :                 0, response_size, response);
     217              :         }
     218              :     }
     219              : 
     220           13 :     measurement_summary_hash_size = libspdm_get_measurement_summary_hash_size(
     221           13 :         spdm_context, false, spdm_request->header.param1);
     222           13 :     if ((measurement_summary_hash_size == 0) &&
     223           11 :         (spdm_request->header.param1 != SPDM_PSK_EXCHANGE_REQUEST_NO_MEASUREMENT_SUMMARY_HASH)) {
     224            1 :         return libspdm_generate_error_response(spdm_context,
     225              :                                                SPDM_ERROR_CODE_INVALID_REQUEST,
     226              :                                                0, response_size, response);
     227              :     }
     228              : 
     229           12 :     hmac_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
     230              : 
     231           12 :     if (request_size < sizeof(spdm_psk_exchange_request_t)) {
     232            0 :         return libspdm_generate_error_response(spdm_context,
     233              :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
     234              :                                                response_size, response);
     235              :     }
     236           12 :     if (request_size < sizeof(spdm_psk_exchange_request_t) +
     237           12 :         spdm_request->psk_hint_length +
     238           12 :         spdm_request->context_length +
     239           12 :         spdm_request->opaque_length) {
     240            1 :         return libspdm_generate_error_response(spdm_context,
     241              :                                                SPDM_ERROR_CODE_INVALID_REQUEST, 0,
     242              :                                                response_size, response);
     243              :     }
     244           11 :     request_size = sizeof(spdm_psk_exchange_request_t) +
     245           11 :                    spdm_request->psk_hint_length +
     246           11 :                    spdm_request->context_length +
     247           11 :                    spdm_request->opaque_length;
     248              : 
     249           11 :     if (spdm_request->opaque_length != 0) {
     250            9 :         cptr = (const uint8_t *)request + sizeof(spdm_psk_exchange_request_t) +
     251            9 :                spdm_request->psk_hint_length + spdm_request->context_length;
     252            9 :         result = libspdm_process_general_opaque_data_check(spdm_context,
     253            9 :                                                            spdm_request->opaque_length, cptr);
     254            9 :         if (!result) {
     255            0 :             return libspdm_generate_error_response(spdm_context,
     256              :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
     257              :                                                    response_size, response);
     258              :         }
     259            9 :         status = libspdm_process_opaque_data_supported_version_data(
     260            9 :             spdm_context, spdm_request->opaque_length, cptr, &secured_message_version);
     261            9 :         if (LIBSPDM_STATUS_IS_ERROR(status)) {
     262            0 :             return libspdm_generate_error_response(spdm_context,
     263              :                                                    SPDM_ERROR_CODE_INVALID_REQUEST, 0,
     264              :                                                    response_size, response);
     265              :         }
     266              :     }
     267              : 
     268           11 :     opaque_psk_exchange_rsp_size =
     269           11 :         libspdm_get_opaque_data_version_selection_data_size(spdm_context);
     270           11 :     if (libspdm_is_capabilities_flag_supported(
     271              :             spdm_context, false, 0,
     272              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
     273           11 :         context_length = LIBSPDM_PSK_CONTEXT_LENGTH;
     274              :     } else {
     275            0 :         context_length = 0;
     276              :     }
     277           11 :     total_size = sizeof(spdm_psk_exchange_response_t) +
     278           11 :                  measurement_summary_hash_size + context_length +
     279           11 :                  opaque_psk_exchange_rsp_size + hmac_size;
     280              : 
     281           11 :     LIBSPDM_ASSERT(*response_size >= total_size);
     282           11 :     *response_size = total_size;
     283           11 :     libspdm_zero_mem(response, *response_size);
     284           11 :     spdm_response = response;
     285              : 
     286           11 :     spdm_response->header.spdm_version = spdm_request->header.spdm_version;
     287           11 :     spdm_response->header.request_response_code = SPDM_PSK_EXCHANGE_RSP;
     288           11 :     if (libspdm_is_capabilities_flag_supported(
     289              :             spdm_context, false,
     290              :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
     291              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
     292            0 :         spdm_response->header.param1 = spdm_context->local_context.heartbeat_period;
     293              :     } else {
     294           11 :         spdm_response->header.param1 = 0x00;
     295              :     }
     296              : 
     297           11 :     req_session_id = spdm_request->req_session_id;
     298           11 :     rsp_session_id = libspdm_allocate_rsp_session_id(spdm_context, true);
     299           11 :     if (rsp_session_id == ((INVALID_SESSION_ID & 0xFFFF0000) >> 16)) {
     300            0 :         return libspdm_generate_error_response(
     301              :             spdm_context, SPDM_ERROR_CODE_SESSION_LIMIT_EXCEEDED, 0,
     302              :             response_size, response);
     303              :     }
     304           11 :     if (spdm_request->psk_hint_length == 0) {
     305            2 :         psk_hint_size = 0;
     306            2 :         psk_hint = NULL;
     307            9 :     } else if (spdm_request->psk_hint_length <= LIBSPDM_PSK_MAX_HINT_LENGTH ) {
     308            9 :         psk_hint_size = spdm_request->psk_hint_length;
     309            9 :         psk_hint = (const uint8_t *)request +
     310              :                    sizeof(spdm_psk_exchange_request_t);
     311              :     } else {
     312            0 :         return libspdm_generate_error_response(
     313              :             spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
     314              :             response_size, response);
     315              :     }
     316           11 :     session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
     317           11 :     session_info = libspdm_assign_session_id(spdm_context, session_id, secured_message_version,
     318              :                                              true);
     319           11 :     if (session_info == NULL) {
     320            0 :         return libspdm_generate_error_response(
     321              :             spdm_context, SPDM_ERROR_CODE_SESSION_LIMIT_EXCEEDED, 0,
     322              :             response_size, response);
     323              :     }
     324           11 :     libspdm_session_info_set_psk_hint(session_info, psk_hint, psk_hint_size);
     325              : 
     326           11 :     libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
     327           11 :                                                   spdm_request->header.request_response_code);
     328              : 
     329           11 :     spdm_response->rsp_session_id = rsp_session_id;
     330           11 :     spdm_response->reserved = 0;
     331              : 
     332           11 :     spdm_response->context_length = context_length;
     333           11 :     spdm_response->opaque_length = (uint16_t)opaque_psk_exchange_rsp_size;
     334              : 
     335           11 :     ptr = (void *)(spdm_response + 1);
     336              : 
     337              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
     338           11 :     if (libspdm_is_capabilities_flag_supported(
     339            2 :             spdm_context, false, 0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP) &&
     340            2 :         ((spdm_request->header.param1 == SPDM_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH) ||
     341            1 :          (spdm_request->header.param1 == SPDM_REQUEST_ALL_MEASUREMENTS_HASH))) {
     342            2 :         result = libspdm_generate_measurement_summary_hash(
     343              :             spdm_context,
     344            2 :             spdm_context->connection_info.version,
     345              :             spdm_context->connection_info.algorithm.base_hash_algo,
     346            2 :             spdm_context->connection_info.algorithm.measurement_spec,
     347              :             spdm_context->connection_info.algorithm.measurement_hash_algo,
     348            2 :             spdm_request->header.param1,
     349              :             ptr,
     350              :             measurement_summary_hash_size);
     351              : 
     352            2 :         if (!result) {
     353            0 :             libspdm_free_session_id(spdm_context, session_id);
     354            0 :             return libspdm_generate_error_response(spdm_context,
     355              :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
     356              :                                                    response_size, response);
     357              :         }
     358              :     }
     359              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     360              : 
     361           11 :     ptr += measurement_summary_hash_size;
     362              : 
     363           11 :     if (context_length != 0) {
     364           11 :         if (!libspdm_get_random_number(context_length, ptr)) {
     365            0 :             libspdm_free_session_id(spdm_context, session_id);
     366            0 :             return libspdm_generate_error_response(spdm_context,
     367              :                                                    SPDM_ERROR_CODE_UNSPECIFIED, 0,
     368              :                                                    response_size, response);
     369              :         }
     370           11 :         ptr += context_length;
     371              :     }
     372              : 
     373           11 :     libspdm_build_opaque_data_version_selection_data(
     374              :         spdm_context, secured_message_version, &opaque_psk_exchange_rsp_size, ptr);
     375              : 
     376           11 :     ptr += opaque_psk_exchange_rsp_size;
     377              : 
     378           11 :     status = libspdm_append_message_k(spdm_context, session_info, false, request, request_size);
     379           11 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     380            0 :         libspdm_free_session_id(spdm_context, session_id);
     381            0 :         return libspdm_generate_error_response(spdm_context,
     382              :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
     383              :                                                response_size, response);
     384              :     }
     385              : 
     386           11 :     status = libspdm_append_message_k(spdm_context, session_info, false, spdm_response,
     387           11 :                                       (size_t)ptr - (size_t)spdm_response);
     388           11 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     389            0 :         libspdm_free_session_id(spdm_context, session_id);
     390            0 :         return libspdm_generate_error_response(spdm_context,
     391              :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
     392              :                                                response_size, response);
     393              :     }
     394              : 
     395           11 :     LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_handshake_key[%x]\n",
     396              :                    session_id));
     397           11 :     result = libspdm_calculate_th1_hash(spdm_context, session_info, false,
     398              :                                         th1_hash_data);
     399           11 :     if (!result) {
     400            0 :         libspdm_free_session_id(spdm_context, session_id);
     401            0 :         return libspdm_generate_error_response(spdm_context,
     402              :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
     403              :                                                response_size, response);
     404              :     }
     405           11 :     result = libspdm_generate_session_handshake_key(
     406              :         session_info->secured_message_context, th1_hash_data);
     407           11 :     if (!result) {
     408            0 :         libspdm_free_session_id(spdm_context, session_id);
     409            0 :         return libspdm_generate_error_response(spdm_context,
     410              :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
     411              :                                                response_size, response);
     412              :     }
     413              : 
     414           11 :     result = libspdm_generate_psk_exchange_rsp_hmac(spdm_context, session_info,
     415              :                                                     ptr);
     416           11 :     if (!result) {
     417            0 :         libspdm_free_session_id(spdm_context, session_id);
     418            0 :         return libspdm_generate_error_response(
     419              :             spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
     420              :             0, response_size, response);
     421              :     }
     422           11 :     status = libspdm_append_message_k(spdm_context, session_info, false, ptr, hmac_size);
     423           11 :     if (LIBSPDM_STATUS_IS_ERROR(status)) {
     424            0 :         libspdm_free_session_id(spdm_context, session_id);
     425            0 :         return libspdm_generate_error_response(spdm_context,
     426              :                                                SPDM_ERROR_CODE_UNSPECIFIED, 0,
     427              :                                                response_size, response);
     428              :     }
     429           11 :     ptr += hmac_size;
     430              : 
     431           11 :     if (spdm_request->header.spdm_version >= SPDM_MESSAGE_VERSION_12) {
     432            2 :         session_info->session_policy = spdm_request->header.param2;
     433              :     }
     434           11 :     libspdm_set_session_state(spdm_context, session_id, LIBSPDM_SESSION_STATE_HANDSHAKING);
     435              : 
     436           11 :     if (!libspdm_is_capabilities_flag_supported(
     437              :             spdm_context, false, 0,
     438              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
     439              :         /* No need to receive PSK_FINISH, enter application phase directly.*/
     440              : 
     441            0 :         LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_generate_session_data_key[%x]\n",
     442              :                        session_id));
     443            0 :         result = libspdm_calculate_th2_hash(spdm_context, session_info,
     444              :                                             false, th2_hash_data);
     445            0 :         if (!result) {
     446            0 :             libspdm_free_session_id(spdm_context, session_id);
     447            0 :             return libspdm_generate_error_response(
     448              :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
     449              :                 0, response_size, response);
     450              :         }
     451            0 :         result = libspdm_generate_session_data_key(
     452              :             session_info->secured_message_context, th2_hash_data);
     453            0 :         if (!result) {
     454            0 :             libspdm_free_session_id(spdm_context, session_id);
     455            0 :             return libspdm_generate_error_response(
     456              :                 spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
     457              :                 0, response_size, response);
     458              :         }
     459              : 
     460              :         #if LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP
     461            0 :         if (libspdm_is_capabilities_flag_supported(
     462              :                 spdm_context, false,
     463              :                 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
     464              :                 SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
     465            0 :             result = libspdm_start_watchdog(
     466            0 :                 session_id, spdm_context->local_context.heartbeat_period * 2);
     467            0 :             if (!result) {
     468            0 :                 libspdm_free_session_id(spdm_context, session_id);
     469            0 :                 return libspdm_generate_error_response(
     470              :                     spdm_context, SPDM_ERROR_CODE_UNSPECIFIED,
     471              :                     0, response_size, response);
     472              :             }
     473              :         }
     474              :         #endif /* LIBSPDM_ENABLE_CAPABILITY_HBEAT_CAP */
     475              : 
     476            0 :         libspdm_set_session_state(spdm_context, session_id, LIBSPDM_SESSION_STATE_ESTABLISHED);
     477              :     }
     478              : 
     479           11 :     if (libspdm_is_capabilities_flag_supported(
     480              :             spdm_context, false,
     481              :             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP,
     482              :             SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP)) {
     483            0 :         session_info->heartbeat_period = spdm_context->local_context.heartbeat_period;
     484              :     } else {
     485           11 :         session_info->heartbeat_period = 0x00;
     486              :     }
     487              : 
     488           11 :     return LIBSPDM_STATUS_SUCCESS;
     489              : }
     490              : 
     491              : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
        

Generated by: LCOV version 2.0-1