Skip to content

Commit

Permalink
add 1.3 digest handling
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
  • Loading branch information
jyao1 committed Nov 30, 2023
1 parent 2e14477 commit 6400645
Showing 1 changed file with 79 additions and 3 deletions.
82 changes: 79 additions & 3 deletions spdm_dump/spdm/spdm_dump_spdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ value_string_entry_t m_spdm_other_param_value_string_table[] = {
size_t m_spdm_other_param_value_string_table_count =
LIBSPDM_ARRAY_SIZE(m_spdm_other_param_value_string_table);

value_string_entry_t m_spdm_cert_model_string_table[] = {
{ SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE, "NONE" },
{ SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT, "DEVICE" },
{ SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT, "ALIAS" },
{ SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT, "GENERIC" },
};
size_t m_spdm_cert_model_string_table_count =
LIBSPDM_ARRAY_SIZE(m_spdm_cert_model_string_table);

value_string_entry_t m_spdm_key_usage_value_string_table[] = {
{ SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE, "KEY_EX" },
{ SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE, "CHALL" },
{ SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE, "MEAS" },
{ SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE, "EP_INFO" },
{ SPDM_KEY_USAGE_BIT_MASK_STANDARDS_KEY_USE, "STD" },
{ SPDM_KEY_USAGE_BIT_MASK_VENDOR_KEY_USE, "VENDOR" },
};
size_t m_spdm_key_usage_value_string_table_count =
LIBSPDM_ARRAY_SIZE(m_spdm_key_usage_value_string_table);

value_string_entry_t m_spdm_measurement_type_value_string_table[] = {
{ SPDM_MEASUREMENT_BLOCK_MEASUREMENT_TYPE_IMMUTABLE_ROM,
"ImmutableROM" },
Expand Down Expand Up @@ -992,6 +1012,10 @@ void dump_spdm_digests(const void *buffer, size_t buffer_size)
size_t slot_count;
size_t index;
uint8_t *digest;
size_t additional_size;
spdm_key_pair_id_t *key_pair_id;
spdm_certificate_info_t *cert_info;
spdm_key_usage_bit_mask_t *key_usage_bit_mask;

printf("SPDM_DIGESTS ");

Expand All @@ -1010,19 +1034,71 @@ void dump_spdm_digests(const void *buffer, size_t buffer_size)
}
}

additional_size = 0;
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
if (((!m_encapsulated) && m_multi_key_conn_rsp) ||
(m_encapsulated && m_multi_key_conn_req)) {
additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
sizeof(spdm_key_usage_bit_mask_t);
}
}

hash_size = libspdm_get_hash_size(m_spdm_base_hash_algo);

message_size += slot_count * hash_size;
message_size += slot_count * (hash_size + additional_size);
if (buffer_size < message_size) {
printf("\n");
return;
}

if (!m_param_quite_mode) {
printf("(SlotMask=0x%02x) ", spdm_response->header.param2);
printf("(");
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
printf("SupportedSlotMask=0x%02x, ", spdm_response->header.param1);
}
printf("ProvisionedSlotMask=0x%02x) ", spdm_response->header.param2);

digest = (void *)(spdm_response + 1);
key_pair_id =
(spdm_key_pair_id_t *)((uint8_t *)digest + hash_size * slot_count);
cert_info =
(spdm_certificate_info_t *)((uint8_t *)key_pair_id + sizeof(spdm_key_pair_id_t) *
slot_count);
key_usage_bit_mask =
(spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info + sizeof(spdm_certificate_info_t) *
slot_count);
if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
if (((!m_encapsulated) && m_multi_key_conn_rsp) ||
(m_encapsulated && m_multi_key_conn_req)) {
printf("(KeyPairId=");
for (index = 0; index < slot_count; index++) {
printf("0x%02x,", key_pair_id[index]);
}
printf(" CertInfo=");
for (index = 0; index < slot_count; index++) {
printf("0x%02x(", cert_info[index]);
dump_entry_value(
m_spdm_cert_model_string_table,
LIBSPDM_ARRAY_SIZE(
m_spdm_cert_model_string_table),
cert_info[index]);
printf("),");
}
printf(" KeyUsage=");
for (index = 0; index < slot_count; index++) {
printf("0x%04x(", key_usage_bit_mask[index]);
dump_entry_flags(
m_spdm_key_usage_value_string_table,
LIBSPDM_ARRAY_SIZE(
m_spdm_key_usage_value_string_table),
key_usage_bit_mask[index]);
printf("),");
}
printf(") ");
}
}

if (m_param_all_mode) {
digest = (void *)(spdm_response + 1);
for (index = 0; index < slot_count; index++) {
printf("\n Digest_%d(", (uint32_t)index);
dump_data(digest, hash_size);
Expand Down

0 comments on commit 6400645

Please sign in to comment.