From fe4918ef46abca0f3de2443bc4bb369d394bbb18 Mon Sep 17 00:00:00 2001 From: Xiaohanjlll Date: Fri, 15 Mar 2024 16:47:28 +0800 Subject: [PATCH] Increase and enhance fuzzy testing Signed-off-by: Xiaohanjlll --- .../get_capabilities.c | 22 +++- .../negotiate_algorithms.c | 104 ++++++++++++++++- .../algorithms.c | 101 +++++++++++++++- .../capabilities.c | 19 ++- .../certificate.c | 10 +- .../challenge_auth.c | 109 +++++++++++++++++- .../test_spdm_responder_csr/csr.c | 10 +- .../test_spdm_responder_digests/digests.c | 10 +- .../finish_rsp.c | 8 +- .../heartbeat_ack.c | 10 +- .../key_exchange.c | 10 +- .../key_update.c | 10 +- .../measurements.c | 10 +- .../psk_exchange_rsp.c | 10 +- .../psk_finish_rsp.c | 10 +- .../set_certificate_rsp.c | 9 +- .../test_spdm_responder_version/version.c | 10 +- 17 files changed, 437 insertions(+), 35 deletions(-) diff --git a/unit_test/fuzzing/test_requester/test_spdm_requester_get_capabilities/get_capabilities.c b/unit_test/fuzzing/test_requester/test_spdm_requester_get_capabilities/get_capabilities.c index ed959786558..32092df8a87 100644 --- a/unit_test/fuzzing/test_requester/test_spdm_requester_get_capabilities/get_capabilities.c +++ b/unit_test/fuzzing/test_requester/test_spdm_requester_get_capabilities/get_capabilities.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -10,6 +10,13 @@ uint8_t temp_buf[LIBSPDM_RECEIVER_BUFFER_SIZE]; +spdm_version_number_t m_version[] = { + SPDM_MESSAGE_VERSION_10, + SPDM_MESSAGE_VERSION_11, + SPDM_MESSAGE_VERSION_12, + SPDM_MESSAGE_VERSION_13, +}; + size_t libspdm_get_max_buffer_size(void) { return LIBSPDM_MAX_SPDM_MSG_SIZE; @@ -63,7 +70,14 @@ void libspdm_test_requester_get_capabilities(void **State) SPDM_VERSION_NUMBER_SHIFT_BIT; spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION; - libspdm_get_capabilities(spdm_context); + for (uint8_t index = 0; index < sizeof(m_version)/sizeof(spdm_version_number_t); index++) { + spdm_context->connection_info.version = m_version[index] << + SPDM_VERSION_NUMBER_SHIFT_BIT; + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION; + libspdm_reset_message_a(spdm_context); + + libspdm_get_capabilities(spdm_context); + } } libspdm_test_context_t m_libspdm_test_requester_context = { @@ -82,10 +96,8 @@ void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) m_libspdm_test_requester_context.test_buffer = test_buffer; m_libspdm_test_requester_context.test_buffer_size = test_buffer_size; - libspdm_unit_test_group_setup(&State); - /* Successful response*/ + libspdm_unit_test_group_setup(&State); libspdm_test_requester_get_capabilities(&State); - libspdm_unit_test_group_teardown(&State); } diff --git a/unit_test/fuzzing/test_requester/test_spdm_requester_negotiate_algorithms/negotiate_algorithms.c b/unit_test/fuzzing/test_requester/test_spdm_requester_negotiate_algorithms/negotiate_algorithms.c index ee27c833b36..be7c28e1d5e 100644 --- a/unit_test/fuzzing/test_requester/test_spdm_requester_negotiate_algorithms/negotiate_algorithms.c +++ b/unit_test/fuzzing/test_requester/test_spdm_requester_negotiate_algorithms/negotiate_algorithms.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -61,6 +61,8 @@ void libspdm_test_requester_negotiate_algorithms_case1(void **State) m_libspdm_use_measurement_hash_algo; spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo; spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo; + spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP; + spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF; libspdm_reset_message_a(spdm_context); libspdm_negotiate_algorithms(spdm_context); @@ -79,6 +81,8 @@ void libspdm_test_requester_negotiate_algorithms_case2(void **State) m_libspdm_use_measurement_hash_algo; spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo; spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo; + spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP; + spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF; libspdm_reset_message_a(spdm_context); libspdm_negotiate_algorithms(spdm_context); @@ -161,6 +165,98 @@ void libspdm_test_requester_negotiate_algorithms_case4(void **State) libspdm_negotiate_algorithms(spdm_context); } +void libspdm_test_requester_negotiate_algorithms_case5(void **State) +{ + libspdm_test_context_t *spdm_test_context; + libspdm_context_t *spdm_context; + spdm_test_context = *State; + uint32_t connection_capability_flags; + + spdm_context = spdm_test_context->spdm_context; + + spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 << + SPDM_VERSION_NUMBER_SHIFT_BIT; + spdm_context->local_context.algorithm.measurement_hash_algo = + m_libspdm_use_measurement_hash_algo; + spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo; + spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo; + spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo; + spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo; + spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo; + spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo; + spdm_context->local_context.algorithm.other_params_support = 0; + + spdm_context->local_context.capability.flags = SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP | + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP| + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP| + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP| + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP; + connection_capability_flags = + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP; + + spdm_context->connection_info.capability.flags = connection_capability_flags; + + /* Sub Case 0: Initially*/ + libspdm_negotiate_algorithms(spdm_context); + + /* Sub Case 1: MEL_CAP set 1,mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/ + spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP; + libspdm_reset_message_a(spdm_context); + spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF; + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_negotiate_algorithms(spdm_context); + + /* Sub Case 2: MEL_CAP set 1, mel_specification set 0*/ + spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP; + libspdm_reset_message_a(spdm_context); + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + spdm_context->local_context.algorithm.mel_spec = 0; + libspdm_negotiate_algorithms(spdm_context); + + /* Sub Case 3:MEL_CAP set 0, mel_specification set SPDM_MEL_SPECIFICATION_DMTF*/ + spdm_context->connection_info.capability.flags = connection_capability_flags; + libspdm_reset_message_a(spdm_context); + spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF; + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_negotiate_algorithms(spdm_context); + + /* Sub Case 4: MEL_CAP set 0, mel_specification set 0*/ + spdm_context->connection_info.capability.flags = connection_capability_flags; + libspdm_reset_message_a(spdm_context); + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + spdm_context->local_context.algorithm.mel_spec = 0; + libspdm_negotiate_algorithms(spdm_context); + + /* Sub Case 5: MULTI_KEY_CAP set 01*/ + spdm_context->connection_info.capability.flags = + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY; + spdm_context->local_context.capability.flags = + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY; + spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN; + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_reset_message_a(spdm_context); + + libspdm_negotiate_algorithms(spdm_context); + + /* Sub Case 6: MULTI_KEY_CAP set 10*/ + spdm_context->connection_info.capability.flags = + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG; + spdm_context->local_context.capability.flags = + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_NEG; + spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN; + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_reset_message_a(spdm_context); + + libspdm_negotiate_algorithms(spdm_context); +} + libspdm_test_context_t m_libspdm_test_requester_context = { LIBSPDM_TEST_CONTEXT_VERSION, true, @@ -191,7 +287,13 @@ void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) libspdm_test_requester_negotiate_algorithms_case3(&State); libspdm_unit_test_group_teardown(&State); + /* V1.2 response*/ libspdm_unit_test_group_setup(&State); libspdm_test_requester_negotiate_algorithms_case4(&State); libspdm_unit_test_group_teardown(&State); + + /* V1.3 response*/ + libspdm_unit_test_group_setup(&State); + libspdm_test_requester_negotiate_algorithms_case5(&State); + libspdm_unit_test_group_teardown(&State); } diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_algorithms/algorithms.c b/unit_test/fuzzing/test_responder/test_spdm_responder_algorithms/algorithms.c index 0cbc47407dd..1eb5c63ffe3 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_algorithms/algorithms.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_algorithms/algorithms.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -358,6 +358,94 @@ void libspdm_test_responder_algorithms_case11(void **State) spdm_test_context->test_buffer, &response_size, response); } +void libspdm_test_responder_algorithms_case12(void **State) +{ + libspdm_test_context_t *spdm_test_context; + libspdm_context_t *spdm_context; + size_t response_size; + uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE]; + + spdm_test_context = *State; + spdm_context = spdm_test_context->spdm_context; + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + + spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 << + SPDM_VERSION_NUMBER_SHIFT_BIT; + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo; + spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo; + spdm_context->local_context.algorithm.measurement_hash_algo = 0; + spdm_context->local_context.algorithm.measurement_spec = 0; + spdm_context->local_context.capability.flags = 0; + spdm_context->local_context.algorithm.other_params_support = 0; + spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF; + libspdm_reset_message_a(spdm_context); + + spdm_context->connection_info.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN; + + /* Sub Case 1: MEL_CAP set 1*/ + spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP; + + response_size = sizeof(response); + libspdm_get_response_algorithms(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + + /* Sub Case 2: MEL_CAP set 0*/ + spdm_context->local_context.capability.flags = 0; + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_reset_message_a(spdm_context); + + response_size = sizeof(response); + libspdm_get_response_algorithms(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_reset_message_a(spdm_context); + + spdm_context->local_context.algorithm.other_params_support = 0; + spdm_context->connection_info.capability.flags = + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY; + + response_size = sizeof(response); + libspdm_get_response_algorithms(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_reset_message_a(spdm_context); + + spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN; + spdm_context->connection_info.capability.flags = + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_ONLY; + + response_size = sizeof(response); + libspdm_get_response_algorithms(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_reset_message_a(spdm_context); + + spdm_context->local_context.algorithm.other_params_support = 0; + spdm_context->connection_info.capability.flags = + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG; + + response_size = sizeof(response); + libspdm_get_response_algorithms(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES; + libspdm_reset_message_a(spdm_context); + + spdm_context->local_context.algorithm.other_params_support = SPDM_ALGORITHMS_MULTI_KEY_CONN; + spdm_context->connection_info.capability.flags = + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MULTI_KEY_CAP_NEG; + + response_size = sizeof(response); + libspdm_get_response_algorithms(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + +} + libspdm_test_context_t libspdm_test_responder_context = { LIBSPDM_TEST_CONTEXT_VERSION, false, @@ -366,8 +454,15 @@ libspdm_test_context_t libspdm_test_responder_context = { void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&libspdm_test_responder_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_NEGOTIATE_ALGORITHMS) { + spdm_request_header->request_response_code = SPDM_NEGOTIATE_ALGORITHMS; + } + libspdm_test_responder_context.test_buffer = test_buffer; libspdm_test_responder_context.test_buffer_size = test_buffer_size; @@ -425,4 +520,8 @@ void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) libspdm_test_responder_algorithms_case11(&State); libspdm_unit_test_group_teardown(&State); + /* V1.3 requester*/ + libspdm_unit_test_group_setup(&State); + libspdm_test_responder_algorithms_case12(&State); + libspdm_unit_test_group_teardown(&State); } diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_capabilities/capabilities.c b/unit_test/fuzzing/test_responder/test_spdm_responder_capabilities/capabilities.c index 04f32bf2d1e..484c207b805 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_capabilities/capabilities.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_capabilities/capabilities.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -83,19 +83,30 @@ libspdm_test_context_t libspdm_test_responder_context = { void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&libspdm_test_responder_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_GET_CAPABILITIES) { + spdm_request_header->request_response_code = SPDM_GET_CAPABILITIES; + } + libspdm_test_responder_context.test_buffer = test_buffer; libspdm_test_responder_context.test_buffer_size = test_buffer_size; - libspdm_unit_test_group_setup(&State); - /* Success Case */ + libspdm_unit_test_group_setup(&State); libspdm_test_responder_capabilities_case1(&State); + libspdm_unit_test_group_teardown(&State); + /* connection_state Check*/ + libspdm_unit_test_group_setup(&State); libspdm_test_responder_capabilities_case2(&State); + libspdm_unit_test_group_teardown(&State); + /* response_state*/ + libspdm_unit_test_group_setup(&State); libspdm_test_responder_capabilities_case3(&State); - libspdm_unit_test_group_teardown(&State); } diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_certificate/certificate.c b/unit_test/fuzzing/test_responder/test_spdm_responder_certificate/certificate.c index 6a4c79e300b..58a8ac67b02 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_certificate/certificate.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_certificate/certificate.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -188,9 +188,15 @@ void libspdm_test_responder_certificate_case5(void **State) void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_certificate_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_GET_CERTIFICATE) { + spdm_request_header->request_response_code = SPDM_GET_CERTIFICATE; + } + m_libspdm_responder_certificate_test_context.test_buffer = test_buffer; m_libspdm_responder_certificate_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_challenge_auth/challenge_auth.c b/unit_test/fuzzing/test_responder/test_spdm_responder_challenge_auth/challenge_auth.c index 8d152e8181b..d80c60a623a 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_challenge_auth/challenge_auth.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_challenge_auth/challenge_auth.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -258,6 +258,8 @@ void libspdm_test_responder_challenge_case6(void **State) spdm_context->local_context.local_cert_chain_provision[0] = data; spdm_context->local_context.local_cert_chain_provision_size[0] = data_size; + spdm_context->encap_context.req_slot_id = 0xFF; + libspdm_secret_lib_challenge_opaque_data_size = 0; spdm_context->local_context.basic_mut_auth_requested = 1; response_size = sizeof(response); @@ -267,12 +269,106 @@ void libspdm_test_responder_challenge_case6(void **State) free(data); } +void libspdm_test_responder_challenge_case7(void **State) +{ + libspdm_test_context_t *spdm_test_context; + libspdm_context_t *spdm_context; + size_t response_size; + uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE]; + void *data; + size_t data_size; + + spdm_test_context = *State; + spdm_context = spdm_test_context->spdm_context; + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED; + spdm_context->local_context.capability.flags = 0; + spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP; + spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo; + spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo; + spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec; + spdm_context->connection_info.algorithm.measurement_hash_algo = + m_libspdm_use_measurement_hash_algo; + spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 << + SPDM_VERSION_NUMBER_SHIFT_BIT; + libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo, + m_libspdm_use_asym_algo, &data, + &data_size, + NULL, NULL); + spdm_context->local_context.local_cert_chain_provision[0] = data; + spdm_context->local_context.local_cert_chain_provision_size[0] = data_size; + + libspdm_secret_lib_challenge_opaque_data_size = 0; + libspdm_reset_message_c(spdm_context); + + response_size = sizeof(response); + + libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + free(data); +} + +void libspdm_test_responder_challenge_case8(void **State) +{ + libspdm_test_context_t *spdm_test_context; + libspdm_context_t *spdm_context; + size_t response_size; + uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE]; + void *data; + size_t data_size; + + spdm_test_context = *State; + spdm_context = spdm_test_context->spdm_context; + + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED; + spdm_context->local_context.capability.flags = 0; + spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP; + spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo; + spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo; + spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec; + spdm_context->connection_info.algorithm.measurement_hash_algo = + m_libspdm_use_measurement_hash_algo; + spdm_context->connection_info.multi_key_conn_rsp = true; + + spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 << + SPDM_VERSION_NUMBER_SHIFT_BIT; + libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo, + m_libspdm_use_asym_algo, &data, + &data_size, NULL, NULL); + spdm_context->local_context.local_cert_chain_provision[0] = data; + spdm_context->local_context.local_cert_chain_provision_size[0] = data_size; + + libspdm_secret_lib_challenge_opaque_data_size = 0; + libspdm_reset_message_c(spdm_context); +#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT + spdm_context->transcript.message_m.buffer_size = + spdm_context->transcript.message_m.max_buffer_size; +#endif + + for (uint8_t i = 0; i < SPDM_MAX_SLOT_COUNT; i++) { + spdm_context->local_context.local_key_usage_bit_mask[i] = + SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE | + SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE; + } + + response_size = sizeof(response); + libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size, + spdm_test_context->test_buffer, &response_size, response); + free(data); +} + void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_challenge_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_CHALLENGE) { + spdm_request_header->request_response_code = SPDM_CHALLENGE; + } + m_libspdm_responder_challenge_test_context.test_buffer = test_buffer; m_libspdm_responder_challenge_test_context.test_buffer_size = test_buffer_size; @@ -306,6 +402,15 @@ void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) libspdm_test_responder_challenge_case6(&State); libspdm_unit_test_group_teardown(&State); + /* V1.2 requester*/ + libspdm_unit_test_group_setup(&State); + libspdm_test_responder_challenge_case7(&State); + libspdm_unit_test_group_teardown(&State); + + /* V1.3 requester*/ + libspdm_unit_test_group_setup(&State); + libspdm_test_responder_challenge_case8(&State); + libspdm_unit_test_group_teardown(&State); } #else size_t libspdm_get_max_buffer_size(void) diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_csr/csr.c b/unit_test/fuzzing/test_responder/test_spdm_responder_csr/csr.c index e6f89b2190e..e602eb4af38 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_csr/csr.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_csr/csr.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -94,9 +94,15 @@ libspdm_test_context_t m_libspdm_responder_csr_test_context = { void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_csr_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_GET_CSR) { + spdm_request_header->request_response_code = SPDM_GET_CSR; + } + m_libspdm_responder_csr_test_context.test_buffer = test_buffer; m_libspdm_responder_csr_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_digests/digests.c b/unit_test/fuzzing/test_responder/test_spdm_responder_digests/digests.c index 2542352312f..7e711d34d1d 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_digests/digests.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_digests/digests.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -133,9 +133,15 @@ libspdm_test_context_t m_libspdm_responder_digests_test_context = { void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_digests_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_GET_DIGESTS) { + spdm_request_header->request_response_code = SPDM_GET_CSR; + } + m_libspdm_responder_digests_test_context.test_buffer = test_buffer; m_libspdm_responder_digests_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_finish_rsp/finish_rsp.c b/unit_test/fuzzing/test_responder/test_spdm_responder_finish_rsp/finish_rsp.c index e9fd9695d04..ce34955270e 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_finish_rsp/finish_rsp.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_finish_rsp/finish_rsp.c @@ -506,9 +506,15 @@ void libspdm_test_responder_finish_case8(void **State) void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_finish_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_FINISH) { + spdm_request_header->request_response_code = SPDM_FINISH; + } + m_libspdm_responder_finish_test_context.test_buffer = (void *)test_buffer; m_libspdm_responder_finish_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_heartbeat_ack/heartbeat_ack.c b/unit_test/fuzzing/test_responder/test_spdm_responder_heartbeat_ack/heartbeat_ack.c index 0d64bd55f26..a3f289a8470 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_heartbeat_ack/heartbeat_ack.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_heartbeat_ack/heartbeat_ack.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -206,9 +206,15 @@ void libspdm_test_responder_heartbeat_case4(void **State) void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_heartbeat_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_HEARTBEAT) { + spdm_request_header->request_response_code = SPDM_HEARTBEAT; + } + m_libspdm_responder_heartbeat_test_context.test_buffer = (void *)test_buffer; m_libspdm_responder_heartbeat_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_key_exchange/key_exchange.c b/unit_test/fuzzing/test_responder/test_spdm_responder_key_exchange/key_exchange.c index 916f7afc9e7..7e8c00c6833 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_key_exchange/key_exchange.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_key_exchange/key_exchange.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -614,9 +614,15 @@ void libspdm_test_responder_key_exchange_case8(void **State) void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_key_exchange_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_KEY_EXCHANGE) { + spdm_request_header->request_response_code = SPDM_KEY_EXCHANGE; + } + m_libspdm_responder_key_exchange_test_context.test_buffer = test_buffer; m_libspdm_responder_key_exchange_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_key_update/key_update.c b/unit_test/fuzzing/test_responder/test_spdm_responder_key_update/key_update.c index 93b6c3a0d9a..341972d86d3 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_key_update/key_update.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_key_update/key_update.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -158,9 +158,15 @@ void libspdm_test_responder_key_update(void **State) void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_key_update_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_KEY_UPDATE) { + spdm_request_header->request_response_code = SPDM_KEY_UPDATE; + } + m_libspdm_responder_key_update_test_context.test_buffer = test_buffer; m_libspdm_responder_key_update_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_measurements/measurements.c b/unit_test/fuzzing/test_responder/test_spdm_responder_measurements/measurements.c index eb8d855f4ce..3251aa5e098 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_measurements/measurements.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_measurements/measurements.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -244,9 +244,15 @@ libspdm_test_context_t m_libspdm_responder_measurements_test_context = { void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_measurements_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_GET_MEASUREMENTS) { + spdm_request_header->request_response_code = SPDM_GET_MEASUREMENTS; + } + m_libspdm_responder_measurements_test_context.test_buffer = test_buffer; m_libspdm_responder_measurements_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_psk_exchange_rsp/psk_exchange_rsp.c b/unit_test/fuzzing/test_responder/test_spdm_responder_psk_exchange_rsp/psk_exchange_rsp.c index 463e5efa4a3..3de50cc3755 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_psk_exchange_rsp/psk_exchange_rsp.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_psk_exchange_rsp/psk_exchange_rsp.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -546,9 +546,15 @@ void libspdm_test_responder_psk_exchange_case7(void **State) void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_psk_exchange_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_PSK_EXCHANGE) { + spdm_request_header->request_response_code = SPDM_PSK_EXCHANGE; + } + m_libspdm_responder_psk_exchange_test_context.test_buffer = (void *)test_buffer; m_libspdm_responder_psk_exchange_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_psk_finish_rsp/psk_finish_rsp.c b/unit_test/fuzzing/test_responder/test_spdm_responder_psk_finish_rsp/psk_finish_rsp.c index f02d3a42631..8871be5959c 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_psk_finish_rsp/psk_finish_rsp.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_psk_finish_rsp/psk_finish_rsp.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -281,9 +281,15 @@ void libspdm_test_responder_psk_finish_rsp_case3(void **State) void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_psk_finish_rsp_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_PSK_FINISH) { + spdm_request_header->request_response_code = SPDM_PSK_FINISH; + } + m_libspdm_responder_psk_finish_rsp_test_context.test_buffer = test_buffer; m_libspdm_responder_psk_finish_rsp_test_context.test_buffer_size = test_buffer_size; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_set_certificate/set_certificate_rsp.c b/unit_test/fuzzing/test_responder/test_spdm_responder_set_certificate/set_certificate_rsp.c index 33e8fcc9be7..854677bf4a5 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_set_certificate/set_certificate_rsp.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_set_certificate/set_certificate_rsp.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -97,8 +97,15 @@ void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) void *State; size_t buffer_size; + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_set_certificate_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_SET_CERTIFICATE) { + spdm_request_header->request_response_code = SPDM_SET_CERTIFICATE; + } + buffer_size = test_buffer_size; if(buffer_size > LIBSPDM_MAX_CERT_CHAIN_SIZE) { buffer_size = LIBSPDM_MAX_CERT_CHAIN_SIZE; diff --git a/unit_test/fuzzing/test_responder/test_spdm_responder_version/version.c b/unit_test/fuzzing/test_responder/test_spdm_responder_version/version.c index e418b8334f1..cf800322743 100644 --- a/unit_test/fuzzing/test_responder/test_spdm_responder_version/version.c +++ b/unit_test/fuzzing/test_responder/test_spdm_responder_version/version.c @@ -1,6 +1,6 @@ /** * Copyright Notice: - * Copyright 2021-2022 DMTF. All rights reserved. + * Copyright 2021-2024 DMTF. All rights reserved. * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md **/ @@ -38,9 +38,15 @@ libspdm_test_context_t m_libspdm_responder_version_test_context = { void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) { void *State; - + spdm_message_header_t *spdm_request_header; libspdm_setup_test_context(&m_libspdm_responder_version_test_context); + spdm_request_header = (spdm_message_header_t*)test_buffer; + + if (spdm_request_header->request_response_code != SPDM_GET_VERSION) { + spdm_request_header->request_response_code = SPDM_GET_VERSION; + } + m_libspdm_responder_version_test_context.test_buffer = test_buffer; m_libspdm_responder_version_test_context.test_buffer_size = test_buffer_size;