Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ set(GCOV ${GCOV} CACHE STRING "Choose the target of Gcov: ON OFF, and default i
set(STACK_USAGE ${STACK_USAGE} CACHE STRING "Choose the target of STACK_USAGE: ON OFF, and default is OFF" FORCE)
set(BUILD_LINUX_SHARED_LIB ${BUILD_LINUX_SHARED_LIB} CACHE STRING "Choose if libspdm shared library should be built for linux: ON OFF, and default is OFF" FORCE)
set(X509_IGNORE_CRITICAL ${X509_IGNORE_CRITICAL} CACHE STRING "Choose if libspdm-provided cryptography libraries (OpenSSL and MbedTLS) ignore unsupported critical extensions in certificates : ON OFF, and default is OFF" FORCE)
set(DEVICE ${DEVICE} CACHE STRING "Choose the test device: sample tpm, and default is sample" FORCE)

option(LIBSPDM_TPM_SUPPORT "Add TPM support in crypt_ext" OFF)

if(NOT GCOV)
set(GCOV "OFF")
Expand All @@ -53,6 +56,11 @@ if(NOT X509_IGNORE_CRITICAL)
set(X509_IGNORE_CRITICAL "OFF")
endif()

if (NOT DEVICE)
set(DEVICE "sample")
endif()


set(LIBSPDM_DIR ${PROJECT_SOURCE_DIR})

#
Expand All @@ -62,6 +70,7 @@ set(COMPILED_LIBCRYPTO_PATH ${COMPILED_LIBCRYPTO_PATH} CACHE STRING "Optionally
set(COMPILED_LIBSSL_PATH ${COMPILED_LIBSSL_PATH} CACHE STRING "Optionally provide a path to libssl" FORCE)

message("CMAKE_GENERATOR = ${CMAKE_GENERATOR}")
message("DEVICE = ${DEVICE}")

if(ARCH STREQUAL "x64")
message("ARCH = x64")
Expand Down Expand Up @@ -213,6 +222,14 @@ else()
message(FATAL_ERROR "Unknown CRYPTO")
endif()

if (LIBSPDM_TPM_SUPPORT)
if (NOT CRYPTO STREQUAL "openssl")
message(FATAL_ERROR "${CRYPTO} does not support TPM")
endif ()
message(STATUS "crypt_ext tpm supported enabled")
add_definitions(-DLIBSPDM_TPM_SUPPORT=1)
endif()

if (X509_IGNORE_CRITICAL STREQUAL "ON")
if (CRYPTO STREQUAL "openssl")
add_definitions(-DOPENSSL_IGNORE_CRITICAL=1)
Expand Down Expand Up @@ -981,7 +998,7 @@ if(ENABLE_CODEQL STREQUAL "ON")
add_subdirectory(os_stub/platform_lib)
add_subdirectory(os_stub/platform_lib_null)
add_subdirectory(os_stub/malloclib)
add_subdirectory(os_stub/spdm_device_secret_lib_sample)
add_subdirectory(os_stub/spdm_device_secret_lib_${DEVICE})
add_subdirectory(os_stub/spdm_device_secret_lib_null)
add_subdirectory(os_stub/spdm_cert_verify_callback_sample)
add_subdirectory(os_stub/cryptlib_null)
Expand Down Expand Up @@ -1020,7 +1037,7 @@ else()
add_subdirectory(os_stub/platform_lib)
add_subdirectory(os_stub/platform_lib_null)
add_subdirectory(os_stub/malloclib)
add_subdirectory(os_stub/spdm_device_secret_lib_sample)
add_subdirectory(os_stub/spdm_device_secret_lib_${DEVICE})
add_subdirectory(os_stub/spdm_device_secret_lib_null)
add_subdirectory(os_stub/spdm_cert_verify_callback_sample)

Expand Down
8 changes: 8 additions & 0 deletions os_stub/cryptlib_openssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ if(ENABLE_BINARY_BUILD STREQUAL "1")
target_link_libraries(cryptlib_openssl PUBLIC ssl crypto memlib)
else()
target_link_libraries(cryptlib_openssl PUBLIC openssllib memlib)
target_link_libraries(cryptlib_openssl PUBLIC openssllib memlib)
endif()

if (LIBSPDM_TPM_SUPPORT)
target_sources(cryptlib_openssl
PRIVATE
tpm/tpm.c)
target_link_libraries(cryptlib_openssl PUBLIC tss2-esys tss2-tctildr tss2-rc)
endif ()
14 changes: 9 additions & 5 deletions os_stub/cryptlib_openssl/pk/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,6 @@ bool libspdm_x509_verify_cert_chain(const uint8_t *root_cert, size_t root_cert_l


/* Verify current_cert with preceding cert;*/

verify_flag =
libspdm_x509_verify_cert(current_cert, current_cert_len,
preceding_cert, preceding_cert_len);
Expand Down Expand Up @@ -2458,6 +2457,7 @@ bool libspdm_gen_x509_csr_with_pqc(
X509_NAME *x509_name;
EVP_PKEY *private_key;
EVP_PKEY *public_key;
bool owned_keys = false;
EVP_MD *md;
uint8_t *csr_p;
STACK_OF(X509_EXTENSION) *exts;
Expand Down Expand Up @@ -2536,11 +2536,13 @@ bool libspdm_gen_x509_csr_with_pqc(
EVP_PKEY_free(private_key);
EVP_PKEY_free(public_key);

private_key = EVP_PKEY_dup(ec_pkey);
public_key = EVP_PKEY_dup(ec_pkey);
/* Can't DUP hardware backed keys */
private_key = ec_pkey;
public_key = ec_pkey;
if (private_key == NULL || public_key == NULL) {
goto free_all;
}
owned_keys = true;
break;
}
case LIBSPDM_CRYPTO_NID_SM2_DSA_P256: {
Expand Down Expand Up @@ -2763,8 +2765,10 @@ bool libspdm_gen_x509_csr_with_pqc(
EVP_MD_free((EVP_MD *)md);
}
X509_REQ_free(x509_req);
EVP_PKEY_free(private_key);
EVP_PKEY_free(public_key);
if (!owned_keys) {
EVP_PKEY_free(private_key);
EVP_PKEY_free(public_key);
}

return (ret != 0);
}
Expand Down
Loading