-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Wilfred Mallawa <[email protected]>
- Loading branch information
Showing
5 changed files
with
569 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
unit_test/fuzzing/test_transport/test_spdm_transport_storage_decode_message/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
add_executable(test_spdm_transport_storage_decode_message) | ||
|
||
target_include_directories(test_spdm_transport_storage_decode_message | ||
PRIVATE | ||
${LIBSPDM_DIR}/unit_test/fuzzing/test_transport/test_spdm_transport_storage_decode_message | ||
${LIBSPDM_DIR}/include | ||
${LIBSPDM_DIR}/include/library | ||
${LIBSPDM_DIR}/unit_test/include | ||
${LIBSPDM_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common | ||
${LIBSPDM_DIR}/os_stub/include | ||
) | ||
|
||
if(TOOLCHAIN STREQUAL "KLEE") | ||
target_include_directories(test_spdm_transport_storage_decode_message | ||
PRIVATE | ||
$ENV{KLEE_SRC_PATH}/include | ||
) | ||
endif() | ||
|
||
target_sources(test_spdm_transport_storage_decode_message | ||
PRIVATE | ||
spdm_transport_storage_decode_message.c | ||
${PROJECT_SOURCE_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common/common.c | ||
${PROJECT_SOURCE_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common/toolchain_harness.c | ||
${PROJECT_SOURCE_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common/algo.c | ||
) | ||
|
||
if((TOOLCHAIN STREQUAL "KLEE") OR (TOOLCHAIN STREQUAL "CBMC")) | ||
target_link_libraries(test_spdm_transport_storage_decode_message | ||
PRIVATE | ||
$<TARGET_OBJECTS:memlib> | ||
$<TARGET_OBJECTS:debuglib> | ||
$<TARGET_OBJECTS:spdm_transport_storage_lib> | ||
$<TARGET_OBJECTS:spdm_common_lib> | ||
$<TARGET_OBJECTS:${CRYPTO_LIB_PATHS}> | ||
$<TARGET_OBJECTS:rnglib> | ||
$<TARGET_OBJECTS:cryptlib_${CRYPTO}> | ||
$<TARGET_OBJECTS:malloclib> | ||
$<TARGET_OBJECTS:spdm_crypt_lib> | ||
$<TARGET_OBJECTS:spdm_secured_message_lib> | ||
$<TARGET_OBJECTS:spdm_transport_test_lib> | ||
$<TARGET_OBJECTS:spdm_device_secret_lib_null> | ||
) | ||
else() | ||
target_link_libraries(test_spdm_transport_storage_decode_message | ||
PRIVATE | ||
memlib | ||
debuglib | ||
spdm_transport_storage_lib | ||
spdm_common_lib | ||
${CRYPTO_LIB_PATHS} | ||
rnglib | ||
cryptlib_${CRYPTO} | ||
malloclib | ||
spdm_crypt_lib | ||
spdm_secured_message_lib | ||
spdm_transport_test_lib | ||
spdm_device_secret_lib_null | ||
) | ||
endif() |
130 changes: 130 additions & 0 deletions
130
...nsport/test_spdm_transport_storage_decode_message/spdm_transport_storage_decode_message.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/** | ||
* Copyright Notice: | ||
* Copyright 2021-2022 DMTF. All rights reserved. | ||
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md | ||
**/ | ||
|
||
#include "internal/libspdm_responder_lib.h" | ||
#include "spdm_transport_storage_lib.h" | ||
#include "industry_standard/spdm_storage_binding.h" | ||
#include "industry_standard/pcidoe.h" | ||
#include "spdm_unit_fuzzing.h" | ||
#include "toolchain_harness.h" | ||
|
||
libspdm_test_context_t m_libspdm_transport_storage_test_context = { | ||
LIBSPDM_TEST_CONTEXT_VERSION, | ||
false, | ||
}; | ||
|
||
size_t libspdm_get_max_buffer_size(void) | ||
{ | ||
return LIBSPDM_MAX_SPDM_MSG_SIZE; | ||
} | ||
|
||
void libspdm_test_transport_storage_decode_message(void **state) | ||
{ | ||
libspdm_test_context_t *spdm_test_context = *state; | ||
void *transport_message, *message, *dec_message; | ||
size_t transport_message_size, message_size, dec_message_size; | ||
uint32_t *session_id; | ||
bool is_app_message, dec_is_app_message, is_request_message; | ||
libspdm_return_t ret; | ||
|
||
if (m_libspdm_transport_storage_test_context.test_buffer_size < sizeof(storage_spdm_transport_header)) { | ||
LIBSPDM_ASSERT(false); | ||
} | ||
|
||
/* Encode an SPDM Storage Message First (Test Setup) */ | ||
transport_message_size = LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE; | ||
transport_message = spdm_test_context->test_buffer; | ||
is_app_message = false; | ||
is_request_message = true; | ||
message_size = 12; | ||
message = (uint8_t *)transport_message + sizeof(storage_spdm_transport_header); | ||
|
||
ret = libspdm_transport_storage_encode_message( | ||
state, | ||
NULL, | ||
is_app_message, | ||
is_request_message, | ||
message_size, | ||
message, | ||
&transport_message_size, | ||
&transport_message); | ||
LIBSPDM_ASSERT(ret == LIBSPDM_STATUS_SUCCESS); | ||
|
||
ret = libspdm_transport_storage_decode_message( | ||
state, | ||
&session_id, | ||
&dec_is_app_message, | ||
is_request_message, | ||
transport_message_size, | ||
transport_message, | ||
&dec_message_size, | ||
&dec_message | ||
); | ||
/* Trivial Assertions */ | ||
LIBSPDM_ASSERT(ret == LIBSPDM_STATUS_SUCCESS); | ||
LIBSPDM_ASSERT(dec_is_app_message == false); | ||
LIBSPDM_ASSERT(dec_message_size == message_size); | ||
} | ||
|
||
void libspdm_test_transport_storage_decode_management_cmd(void **state) | ||
{ | ||
libspdm_test_context_t *spdm_test_context = *state; | ||
void *transport_message; | ||
size_t transport_message_size; | ||
size_t alloc_len; | ||
uint32_t decoded_alloc_len; | ||
uint8_t cmd_direction; | ||
uint8_t transport_operation, transport_command; | ||
libspdm_return_t ret; | ||
|
||
if (m_libspdm_transport_storage_test_context.test_buffer_size < sizeof(storage_spdm_transport_header)) { | ||
LIBSPDM_ASSERT(false); | ||
} | ||
|
||
transport_message_size = LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE; | ||
transport_message = spdm_test_context->test_buffer; | ||
cmd_direction = LIBSPDM_STORAGE_CMD_DIRECTION_IF_RECV; | ||
transport_operation = SPDM_STORAGE_OPERATION_CODE_DISCOVERY; | ||
alloc_len = 0xFF; | ||
|
||
/* Encode a management command first (Test Setup) */ | ||
ret = libspdm_transport_storage_encode_management_cmd( | ||
cmd_direction, | ||
transport_operation, | ||
0, | ||
&transport_message_size, | ||
&alloc_len, | ||
transport_message); | ||
LIBSPDM_ASSERT(ret == LIBSPDM_STATUS_SUCCESS); | ||
|
||
/* Attempt to decode with trivial assertions */ | ||
ret = libspdm_transport_storage_decode_management_cmd( | ||
transport_message_size, | ||
transport_message, | ||
&transport_command, | ||
&decoded_alloc_len | ||
); | ||
LIBSPDM_ASSERT(ret == LIBSPDM_STATUS_SUCCESS); | ||
LIBSPDM_ASSERT(transport_command == SPDM_STORAGE_OPERATION_CODE_DISCOVERY); | ||
LIBSPDM_ASSERT(decoded_alloc_len == sizeof(storage_spdm_transport_header)); | ||
} | ||
|
||
void libspdm_run_test_harness(void *test_buffer, size_t test_buffer_size) | ||
{ | ||
void *state; | ||
|
||
libspdm_setup_test_context(&m_libspdm_transport_storage_test_context); | ||
|
||
m_libspdm_transport_storage_test_context.test_buffer = test_buffer; | ||
m_libspdm_transport_storage_test_context.test_buffer_size = test_buffer_size; | ||
|
||
libspdm_unit_test_group_setup(&state); | ||
|
||
libspdm_test_transport_storage_decode_management_cmd(&state); | ||
libspdm_test_transport_storage_decode_message(&state); | ||
|
||
libspdm_unit_test_group_teardown(&state); | ||
} |
62 changes: 62 additions & 0 deletions
62
unit_test/fuzzing/test_transport/test_spdm_transport_storage_encode_message/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
add_executable(test_spdm_transport_storage_encode_message) | ||
|
||
target_include_directories(test_spdm_transport_storage_encode_message | ||
PRIVATE | ||
${LIBSPDM_DIR}/unit_test/fuzzing/test_transport/test_spdm_transport_storage_encode_message | ||
${LIBSPDM_DIR}/include | ||
${LIBSPDM_DIR}/include/library | ||
${LIBSPDM_DIR}/unit_test/include | ||
${LIBSPDM_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common | ||
${LIBSPDM_DIR}/os_stub/include | ||
) | ||
|
||
if(TOOLCHAIN STREQUAL "KLEE") | ||
target_include_directories(test_spdm_transport_storage_encode_message | ||
PRIVATE | ||
$ENV{KLEE_SRC_PATH}/include | ||
) | ||
endif() | ||
|
||
target_sources(test_spdm_transport_storage_encode_message | ||
PRIVATE | ||
spdm_transport_storage_encode_message.c | ||
${PROJECT_SOURCE_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common/common.c | ||
${PROJECT_SOURCE_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common/toolchain_harness.c | ||
${PROJECT_SOURCE_DIR}/unit_test/fuzzing/spdm_unit_fuzzing_common/algo.c | ||
) | ||
|
||
if((TOOLCHAIN STREQUAL "KLEE") OR (TOOLCHAIN STREQUAL "CBMC")) | ||
target_link_libraries(test_spdm_transport_storage_encode_message | ||
PRIVATE | ||
$<TARGET_OBJECTS:memlib> | ||
$<TARGET_OBJECTS:debuglib> | ||
$<TARGET_OBJECTS:spdm_transport_storage_lib> | ||
$<TARGET_OBJECTS:spdm_common_lib> | ||
$<TARGET_OBJECTS:${CRYPTO_LIB_PATHS}> | ||
$<TARGET_OBJECTS:rnglib> | ||
$<TARGET_OBJECTS:cryptlib_${CRYPTO}> | ||
$<TARGET_OBJECTS:malloclib> | ||
$<TARGET_OBJECTS:spdm_crypt_lib> | ||
$<TARGET_OBJECTS:spdm_secured_message_lib> | ||
$<TARGET_OBJECTS:spdm_transport_test_lib> | ||
$<TARGET_OBJECTS:spdm_device_secret_lib_null> | ||
) | ||
else() | ||
target_link_libraries(test_spdm_transport_storage_encode_message | ||
PRIVATE | ||
memlib | ||
debuglib | ||
spdm_transport_storage_lib | ||
spdm_common_lib | ||
${CRYPTO_LIB_PATHS} | ||
rnglib | ||
cryptlib_${CRYPTO} | ||
malloclib | ||
spdm_crypt_lib | ||
spdm_secured_message_lib | ||
spdm_transport_test_lib | ||
spdm_device_secret_lib_null | ||
) | ||
endif() |
Oops, something went wrong.