Skip to content

Commit

Permalink
Move libspdm_verify_peer_cert_chain_buffer to unit_test
Browse files Browse the repository at this point in the history
Fix #2108.

Signed-off-by: Steven Bellock <[email protected]>
  • Loading branch information
steven-bellock authored and jyao1 committed Jul 31, 2023
1 parent 66d1a0a commit f5e8613
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 57 deletions.
19 changes: 0 additions & 19 deletions include/internal/libspdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,25 +859,6 @@ bool libspdm_verify_peer_cert_chain_buffer_authority(libspdm_context_t *spdm_con
size_t cert_chain_buffer_size,
const void **trust_anchor,
size_t *trust_anchor_size);

/**
* This function verifies peer certificate chain buffer including spdm_cert_chain_t header.
*
* @param spdm_context A pointer to the SPDM context.
* @param cert_chain_buffer Certificate chain buffer including spdm_cert_chain_t header.
* @param cert_chain_buffer_size size in bytes of the certificate chain buffer.
* @param trust_anchor A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
* @param trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
*
* @retval true Peer certificate chain buffer verification passed.
* @retval false Peer certificate chain buffer verification failed.
**/
bool libspdm_verify_peer_cert_chain_buffer(libspdm_context_t *spdm_context,
const void *cert_chain_buffer,
size_t cert_chain_buffer_size,
const void **trust_anchor,
size_t *trust_anchor_size);

/**
* This function generates the challenge signature based upon m1m2 for authentication.
*
Expand Down
38 changes: 0 additions & 38 deletions library/spdm_common_lib/libspdm_com_crypto_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,44 +733,6 @@ bool libspdm_verify_peer_cert_chain_buffer_authority(libspdm_context_t *spdm_con

return true;
}

/**
* This function verifies peer certificate chain buffer including spdm_cert_chain_t header.
*
* @param spdm_context A pointer to the SPDM context.
* @param cert_chain_buffer Certificate chain buffer including spdm_cert_chain_t header.
* @param cert_chain_buffer_size size in bytes of the certificate chain buffer.
* @param trust_anchor A buffer to hold the trust_anchor which is used to validate the peer certificate, if not NULL.
* @param trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
*
* @retval true Peer certificate chain buffer verification passed.
* @retval false Peer certificate chain buffer verification failed.
**/
bool libspdm_verify_peer_cert_chain_buffer(libspdm_context_t *spdm_context,
const void *cert_chain_buffer,
size_t cert_chain_buffer_size,
const void **trust_anchor,
size_t *trust_anchor_size)
{
bool result;

/*verify peer cert chain integrity*/
result = libspdm_verify_peer_cert_chain_buffer_integrity(spdm_context, cert_chain_buffer,
cert_chain_buffer_size);
if (!result) {
return false;
}

/*verify peer cert chain authority*/
result = libspdm_verify_peer_cert_chain_buffer_authority(spdm_context, cert_chain_buffer,
cert_chain_buffer_size, trust_anchor,
trust_anchor_size);
if (!result) {
return false;
}

return true;
}
#endif

/**
Expand Down
39 changes: 39 additions & 0 deletions unit_test/test_spdm_common/context_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,45 @@ void spdm_device_release_receiver_buffer (void *context, const void *msg_buf_ptr

static uint32_t libspdm_opaque_data = 0xDEADBEEF;

/**
* This function verifies peer certificate chain buffer including spdm_cert_chain_t header.
*
* @param spdm_context A pointer to the SPDM context.
* @param cert_chain_buffer Certificate chain buffer including spdm_cert_chain_t header.
* @param cert_chain_buffer_size Size in bytes of the certificate chain buffer.
* @param trust_anchor A buffer to hold the trust_anchor which is used to validate the
* peer certificate, if not NULL.
* @param trust_anchor_size A buffer to hold the trust_anchor_size, if not NULL.
*
* @retval true Peer certificate chain buffer verification passed.
* @retval false Peer certificate chain buffer verification failed.
**/
static bool libspdm_verify_peer_cert_chain_buffer(void *spdm_context,
const void *cert_chain_buffer,
size_t cert_chain_buffer_size,
const void **trust_anchor,
size_t *trust_anchor_size)
{
bool result;

/*verify peer cert chain integrity*/
result = libspdm_verify_peer_cert_chain_buffer_integrity(spdm_context, cert_chain_buffer,
cert_chain_buffer_size);
if (!result) {
return false;
}

/*verify peer cert chain authority*/
result = libspdm_verify_peer_cert_chain_buffer_authority(spdm_context, cert_chain_buffer,
cert_chain_buffer_size, trust_anchor,
trust_anchor_size);
if (!result) {
return false;
}

return true;
}

/**
* Return the size in bytes of multi element opaque data supported version.
*
Expand Down

0 comments on commit f5e8613

Please sign in to comment.