Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SPDM 1.3 new feature:get_key_pair_info #2771

Merged
merged 3 commits into from
Aug 20, 2024

Conversation

Wenxing-hou
Copy link

Refer the issue: #2293

@Wenxing-hou Wenxing-hou marked this pull request as draft July 15, 2024 08:44
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
}

if ((key_pair_id == 0) || (key_pair_id > SPDM_MAX_SLOT_COUNT)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steven-bellock, do you agree this check: key_pair_id > SPDM_MAX_SLOT_COUNT ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of KeyPairIds can be larger than the number of certificate slots. But we can run that by the SPDM Working Group to ensure that's what was intended in the specification.

@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 2 times, most recently from 2ce3544 to 512d4a6 Compare July 15, 2024 09:01
include/internal/libspdm_common_lib.h Outdated Show resolved Hide resolved
include/library/spdm_lib_config.h Outdated Show resolved Hide resolved
@@ -503,6 +503,7 @@ libspdm_return_t libspdm_set_data(void *spdm_context, libspdm_data_type_t data_t
return LIBSPDM_STATUS_INVALID_PARAMETER;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check at line 499 should be > LIBSPDM_MAX_KEY_PAIR_COUNT.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case LIBSPDM_DATA_LOCAL_KEY_PAIR_ID:
if (parameter->location != LIBSPDM_DATA_LOCATION_LOCAL) {
return LIBSPDM_STATUS_INVALID_PARAMETER;
}
slot_id = parameter->additional_data[0];
if (slot_id >= SPDM_MAX_SLOT_COUNT) {
return LIBSPDM_STATUS_INVALID_PARAMETER;
}
if (data_size != sizeof(spdm_key_pair_id_t)) {
return LIBSPDM_STATUS_INVALID_PARAMETER;
}
context->local_context.local_key_pair_id[slot_id] = *(spdm_key_pair_id_t *)data;
break;

This set data operation is just to create a association between slot_id and key_pair_id.

Do you mean we need add a check for the data? The set data(key pair id) should < LIBSPDM_MAX_KEY_PAIR_COUNT.

library/spdm_requester_lib/libspdm_req_get_key_pair_info.c Outdated Show resolved Hide resolved
library/spdm_requester_lib/libspdm_req_get_key_pair_info.c Outdated Show resolved Hide resolved
library/spdm_requester_lib/libspdm_req_get_key_pair_info.c Outdated Show resolved Hide resolved
library/spdm_requester_lib/libspdm_req_get_key_pair_info.c Outdated Show resolved Hide resolved
@steven-bellock
Copy link
Contributor

For the Requester API I'm not sure there's much value to storing the KEY_PAIR_INFO info into the spdm_context. The Requester already gets its relevant key usage information from GET_DIGESTS. KEY_PAIR_INFO is really for SET_KEY_PAIR_INFO, so I could see libspdm_get_key_pair_info looking like

libspdm_get_key_pair_info(
  void *spdm_context,
  const uint32_t *session_id,
  uint8_t key_pair_id,
  uint8_t *total_key_pairs,
  uint16_t *capabilities
  .
  .
  )

the values returned can then be evaluated and used in libspdm_set_key_pair_info.

@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 2 times, most recently from c3df0d7 to e9b6e59 Compare July 19, 2024 02:28
@jyao1
Copy link
Member

jyao1 commented Jul 22, 2024

The keypairinfo should be saved to device NVS.

@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 5 times, most recently from d2deba1 to c8eb63a Compare July 25, 2024 01:37
libspdm_key_pair_info_t key_pair_info[LIBSPDM_MAX_KEY_PAIR_COUNT];

/*provisioned key pair info*/
uint8_t public_key_info_rsa2048[] = {0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to add all algorithms.

@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 3 times, most recently from 57ef870 to eb82b98 Compare July 26, 2024 08:34
@Wenxing-hou Wenxing-hou marked this pull request as ready for review July 26, 2024 08:38
@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 2 times, most recently from 136ed0f to ed66ff2 Compare July 29, 2024 01:36
@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 6 times, most recently from 7b2e16b to aec9ac5 Compare August 5, 2024 08:28
@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 3 times, most recently from 66670a6 to 8295e85 Compare August 6, 2024 07:16
Copy link
Contributor

@steven-bellock steven-bellock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed https://github.com/DMTF/SPDM-WG/issues/3543. There may be more checks if the Responder's SET_KEY_PAIR_INFO_CAP == 0.

unit_test/test_spdm_requester/get_key_pair_info.c Outdated Show resolved Hide resolved
unit_test/test_spdm_requester/get_key_pair_info.c Outdated Show resolved Hide resolved
unit_test/test_spdm_responder/key_pair_info.c Outdated Show resolved Hide resolved
* @param spdm_context A pointer to the SPDM context.
* @param key_pair_id Indicate which key pair ID's information to retrieve.
*
* @param total_key_pairs Indicate the total number of key pairs on the responder.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As was clarified in https://github.com/DMTF/SPDM-WG/issues/3526#issuecomment-2233350803, total_key_pairs is fixed. As such it can be stored in the spdm_context and removed from this function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. The total_key_pair is still returned in the function.
Because the key pair info is provisioned by the responder device, the key pair number should be consistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll see what @jyao1's opinion is when he gets back.

Copy link
Member

@jyao1 jyao1 Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we design a new API named libspdm_get_total_key_pairs() ?

Then, we don't need total_key_pairs parameter in this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we design a new API named libspdm_get_total_key_pairs() ?

If it's going to be returned in a function then it should be in libspdm_read_key_pair_info. What I, and the SPDM specification, is saying is that since total_key_pairs is fixed at the beginning of the connection and cannot change then just put it in the spdm_context.

Copy link
Member

@jyao1 jyao1 Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with that. We can add LIBSPDM_DATA_TOTAL_KEY_PAIRS_NUMBER data type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just LIBSPDM_DATA_TOTAL_KEY_PAIRS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just LIBSPDM_DATA_TOTAL_KEY_PAIRS.

This will cause misunderstanding. LIBSPDM_DATA_TOTAL_KEY_PAIRS may be interpreted as total key pairs information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steven-bellock
Copy link
Contributor

As was clarified in https://github.com/DMTF/SPDM-WG/issues/3543#issuecomment-2273487285 if the Responder's SET_KEY_PAIR_INFO_CAP == 0 then KEY_PAIR_INFO.Capabilities must be 0 and the Requester can check that. In addition the check

    if ((spdm_response->capabilities & SPDM_KEY_PAIR_CAP_SHAREABLE_CAP) == 0) {
        if (!libspdm_onehot0(spdm_response->assoc_cert_slot_mask)) {
            status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
            goto receive_done;
        }
    }

needs to be removed.

@Wenxing-hou Wenxing-hou force-pushed the add_get_key_pair branch 2 times, most recently from 1f59699 to c511829 Compare August 8, 2024 09:44
@Wenxing-hou
Copy link
Author

As was clarified in DMTF/SPDM-WG#3543 (comment) if the Responder's SET_KEY_PAIR_INFO_CAP == 0 then KEY_PAIR_INFO.Capabilities must be 0 and the Requester can check that. In addition the check

    if ((spdm_response->capabilities & SPDM_KEY_PAIR_CAP_SHAREABLE_CAP) == 0) {
        if (!libspdm_onehot0(spdm_response->assoc_cert_slot_mask)) {
            status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
            goto receive_done;
        }
    }

needs to be removed.

Yes. I have added the check:

    /*If responder doesn't support SET_KEY_PAIR_INFO_CAP,the capabilities should be 0*/
    if ((!libspdm_is_capabilities_flag_supported(
            spdm_context, true, 0,
            SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_SET_KEY_PAIR_INFO_CAP)) &&
        ((spdm_response->capabilities & SPDM_KEY_PAIR_CAP_MASK) != 0)) {
        status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
        goto receive_done;
    }

And I have deleted the assoc_cert_slot_mask check in get_key_pair_info.

@@ -421,6 +421,12 @@ Refer to spdm_server_init() in [spdm_responder.c](https://github.com/DMTF/spdm-e

1.7, if PSK is required, optionally deploy PSK Hint in the call to libspdm_start_session().

1.8, if responder can support multi key pairs, the total_key_pairs need be set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Responder sets GET_KEY_PAIR_INFO_CAP then LIBSPDM_DATA_TOTAL_KEY_PAIRS must be set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have fixed it.


total_key_pairs = spdm_context->local_context.total_key_pairs;
key_pair_id = spdm_request->key_pair_id;
if ((key_pair_id == 0) || (key_pair_id >= total_key_pairs)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key_pair_id > total_key_pairs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have fixed it.

@@ -0,0 +1,157 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File should be libspdm_rsp_get_key_pair_info.c.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have changed the file name.

Copy link
Contributor

@steven-bellock steven-bellock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the pull request is in a good place to start testing.

@jyao1 jyao1 merged commit dd2b624 into DMTF:main Aug 20, 2024
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants