Skip to content

Commit 293bf99

Browse files
committed
Allow Requester to input opaque data for finish and psk_finish
fix #3402 Signed-off-by: Aaron Li <[email protected]>
1 parent 7e0037e commit 293bf99

File tree

3 files changed

+121
-49
lines changed

3 files changed

+121
-49
lines changed

include/library/spdm_requester_lib.h

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,14 @@ libspdm_return_t libspdm_get_supported_algorithms(void *spdm_context,
521521
uint8_t *spdm_version);
522522

523523
/**
524-
* This function sends KEY_EXCHANGE/FINISH or PSK_EXCHANGE/PSK_FINISH to start an SPDM Session.
524+
* This function sends KEY_EXCHANGE or PSK_EXCHANGE to start an SPDM Session.
525525
*
526526
* If encapsulated mutual authentication is requested from the responder,
527527
* this function also perform the encapsulated mutual authentication.
528528
*
529529
* @param spdm_context A pointer to the SPDM context.
530-
* @param use_psk False means to use KEY_EXCHANGE/FINISH to start a session.
531-
* True means to use PSK_EXCHANGE/PSK_FINISH to start a session.
530+
* @param use_psk False means to use KEY_EXCHANGE to start a session.
531+
* True means to use PSK_EXCHANGE to start a session.
532532
* @param psk_hint The psk_hint in PSK_EXCHANGE. It is ignored if use_psk is false.
533533
* @param psk_hint_size The size in bytes of psk_hint. It is ignored if use_psk is false.
534534
* @param measurement_hash_type The type of the measurement hash.
@@ -561,25 +561,50 @@ libspdm_return_t libspdm_get_supported_algorithms(void *spdm_context,
561561
* Opaque data should be less than 1024 bytes.
562562
* On output, the size of the opaque data.
563563
**/
564-
libspdm_return_t libspdm_start_session_ex(void *spdm_context, bool use_psk,
565-
const void *psk_hint,
566-
uint16_t psk_hint_size,
567-
uint8_t measurement_hash_type,
568-
uint8_t slot_id,
569-
uint8_t session_policy,
570-
uint32_t *session_id,
571-
uint8_t *heartbeat_period,
572-
void *measurement_hash,
573-
const void *requester_random_in,
574-
size_t requester_random_in_size,
575-
void *requester_random,
576-
size_t *requester_random_size,
577-
void *responder_random,
578-
size_t *responder_random_size,
579-
const void *requester_opaque_data,
580-
size_t requester_opaque_data_size,
581-
void *responder_opaque_data,
582-
size_t *responder_opaque_data_size);
564+
libspdm_return_t libspdm_start_session_exchange(void *spdm_context, bool use_psk,
565+
const void *psk_hint,
566+
uint16_t psk_hint_size,
567+
uint8_t measurement_hash_type,
568+
uint8_t slot_id,
569+
uint8_t session_policy,
570+
uint32_t *session_id,
571+
uint8_t *heartbeat_period,
572+
void *measurement_hash,
573+
const void *requester_random_in,
574+
size_t requester_random_in_size,
575+
void *requester_random,
576+
size_t *requester_random_size,
577+
void *responder_random,
578+
size_t *responder_random_size,
579+
const void *requester_opaque_data,
580+
size_t requester_opaque_data_size,
581+
void *responder_opaque_data,
582+
size_t *responder_opaque_data_size);
583+
584+
/**
585+
* This function sends FINISH or PSK_FINISH to start an SPDM Session.
586+
*
587+
* @param spdm_context A pointer to the SPDM context.
588+
* @param session_id The session ID of the session.
589+
* @param requester_opaque_data A buffer to hold the requester opaque data, if not NULL.
590+
* If not NULL, this function will not generate any opaque data,
591+
* including secured message versions.
592+
* This parameter is only used for SPDM 1.4 and later
593+
* @param requester_opaque_data_size The size of the opaque data, if requester_opaque_data is not NULL.
594+
* This parameter is only used for SPDM 1.4 and later
595+
* @param responder_opaque_data A buffer to hold the responder opaque data, if not NULL.
596+
* This parameter is only used for SPDM 1.4 and later
597+
* @param responder_opaque_data_size On input, the size of the opaque data buffer.
598+
* Opaque data should be less than 1024 bytes.
599+
* On output, the size of the opaque data.
600+
* This parameter is only used for SPDM 1.4 and later
601+
*/
602+
libspdm_return_t libspdm_start_session_finish(void *spdm_context,
603+
uint32_t session_id,
604+
const void *requester_opaque_data,
605+
size_t requester_opaque_data_size,
606+
void *responder_opaque_data,
607+
size_t *responder_opaque_data_size);
583608

584609
/**
585610
* This function sends END_SESSION to stop an SPDM Session.

library/spdm_requester_lib/libspdm_req_communication.c

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,25 @@ libspdm_return_t libspdm_start_session(void *spdm_context, bool use_psk,
198198
return status;
199199
}
200200

201-
libspdm_return_t libspdm_start_session_ex(void *spdm_context, bool use_psk,
202-
const void *psk_hint,
203-
uint16_t psk_hint_size,
204-
uint8_t measurement_hash_type,
205-
uint8_t slot_id,
206-
uint8_t session_policy,
207-
uint32_t *session_id,
208-
uint8_t *heartbeat_period,
209-
void *measurement_hash,
210-
const void *requester_random_in,
211-
size_t requester_random_in_size,
212-
void *requester_random,
213-
size_t *requester_random_size,
214-
void *responder_random,
215-
size_t *responder_random_size,
216-
const void *requester_opaque_data,
217-
size_t requester_opaque_data_size,
218-
void *responder_opaque_data,
219-
size_t *responder_opaque_data_size)
201+
libspdm_return_t libspdm_start_session_exchange(void *spdm_context, bool use_psk,
202+
const void *psk_hint,
203+
uint16_t psk_hint_size,
204+
uint8_t measurement_hash_type,
205+
uint8_t slot_id,
206+
uint8_t session_policy,
207+
uint32_t *session_id,
208+
uint8_t *heartbeat_period,
209+
void *measurement_hash,
210+
const void *requester_random_in,
211+
size_t requester_random_in_size,
212+
void *requester_random,
213+
size_t *requester_random_size,
214+
void *responder_random,
215+
size_t *responder_random_size,
216+
const void *requester_opaque_data,
217+
size_t requester_opaque_data_size,
218+
void *responder_opaque_data,
219+
size_t *responder_opaque_data_size)
220220
{
221221
libspdm_return_t status;
222222
libspdm_context_t *context;
@@ -293,13 +293,6 @@ libspdm_return_t libspdm_start_session_ex(void *spdm_context, bool use_psk,
293293
session_info->mut_auth_requested));
294294
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
295295
}
296-
297-
if (req_slot_id_param == 0xF) {
298-
req_slot_id_param = 0xFF;
299-
}
300-
status = libspdm_send_receive_finish(context, *session_id, req_slot_id_param);
301-
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
302-
"libspdm_start_session - libspdm_send_receive_finish - %xu\n", status));
303296
#else /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
304297
LIBSPDM_ASSERT(false);
305298
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
@@ -321,12 +314,65 @@ libspdm_return_t libspdm_start_session_ex(void *spdm_context, bool use_psk,
321314
status));
322315
return status;
323316
}
317+
#else /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
318+
LIBSPDM_ASSERT(false);
319+
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
320+
#endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
321+
}
322+
323+
return status;
324+
}
325+
326+
libspdm_return_t libspdm_start_session_finish(void *spdm_context,
327+
uint32_t session_id,
328+
const void *requester_opaque_data,
329+
size_t requester_opaque_data_size,
330+
void *responder_opaque_data,
331+
size_t *responder_opaque_data_size)
332+
{
333+
libspdm_return_t status;
334+
libspdm_context_t *context;
335+
libspdm_session_info_t *session_info;
336+
337+
#if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
338+
uint8_t req_slot_id_param;
339+
#endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP */
340+
341+
context = spdm_context;
342+
status = LIBSPDM_STATUS_UNSUPPORTED_CAP;
343+
344+
session_info = libspdm_get_session_info_via_session_id(context, session_id);
345+
if (session_info == NULL) {
346+
LIBSPDM_ASSERT(false);
347+
return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
348+
}
324349

350+
if (!session_info->use_psk) {
351+
#if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
352+
req_slot_id_param = session_info->local_used_cert_chain_slot_id;
353+
if (req_slot_id_param == 0xF) {
354+
req_slot_id_param = 0xFF;
355+
}
356+
status = libspdm_send_receive_finish_ex(
357+
context, session_id, req_slot_id_param,
358+
requester_opaque_data, requester_opaque_data_size,
359+
responder_opaque_data, responder_opaque_data_size);
360+
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
361+
"libspdm_start_session - libspdm_send_receive_finish - %xu\n", status));
362+
#else /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
363+
LIBSPDM_ASSERT(false);
364+
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
365+
#endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
366+
} else {
367+
#if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
325368
/* send PSK_FINISH only if Responder supports context.*/
326369
if (libspdm_is_capabilities_flag_supported(
327370
context, true, 0,
328371
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT)) {
329-
status = libspdm_send_receive_psk_finish(context, *session_id);
372+
status = libspdm_send_receive_psk_finish_ex(
373+
context, session_id,
374+
requester_opaque_data, requester_opaque_data_size,
375+
responder_opaque_data, responder_opaque_data_size);
330376
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
331377
"libspdm_start_session - libspdm_send_receive_psk_finish - %xu\n",
332378
status));

library/spdm_requester_lib/libspdm_req_key_exchange.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ static libspdm_return_t libspdm_try_send_receive_key_exchange(
748748
goto receive_done;
749749
}
750750
session_info->peer_used_cert_chain_slot_id = slot_id;
751+
session_info->local_used_cert_chain_slot_id = *req_slot_id_param;
751752

752753
/* -=[Process Response Phase]=- */
753754
status = libspdm_append_message_k(spdm_context, session_info, true, spdm_request,

0 commit comments

Comments
 (0)