2019-06-06 02:57:29 +00:00
|
|
|
idf_build_get_property(idf_target IDF_TARGET)
|
2020-03-26 02:53:50 +00:00
|
|
|
idf_build_get_property(python PYTHON)
|
2019-06-06 02:57:29 +00:00
|
|
|
|
2019-09-29 10:04:34 +00:00
|
|
|
idf_component_register(SRCS "esp_crt_bundle/esp_crt_bundle.c"
|
|
|
|
INCLUDE_DIRS "port/include" "mbedtls/include" "esp_crt_bundle/include"
|
2019-08-08 03:44:24 +00:00
|
|
|
REQUIRES lwip
|
2020-07-21 09:15:19 +00:00
|
|
|
PRIV_REQUIRES esp_pm soc
|
2019-08-08 03:44:24 +00:00
|
|
|
)
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2019-09-29 10:04:34 +00:00
|
|
|
if(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE)
|
|
|
|
set(bundle_name "x509_crt_bundle")
|
|
|
|
set(DEFAULT_CRT_DIR ${COMPONENT_DIR}/esp_crt_bundle)
|
|
|
|
|
|
|
|
# Generate custom certificate bundle using the generate_cert_bundle utility
|
|
|
|
set(GENERATE_CERT_BUNDLEPY ${python} ${COMPONENT_DIR}/esp_crt_bundle/gen_crt_bundle.py)
|
|
|
|
|
|
|
|
if(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL)
|
|
|
|
list(APPEND crt_paths ${DEFAULT_CRT_DIR}/cacrt_all.pem)
|
|
|
|
elseif(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN)
|
|
|
|
list(APPEND crt_paths ${DEFAULT_CRT_DIR}/cacrt_all.pem)
|
|
|
|
list(APPEND args --filter ${DEFAULT_CRT_DIR}/cmn_crt_authorities.csv)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE)
|
|
|
|
get_filename_component(custom_bundle_path
|
|
|
|
${CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH} ABSOLUTE BASE_DIR "${project_dir}")
|
|
|
|
list(APPEND crt_paths ${custom_bundle_path})
|
|
|
|
|
|
|
|
endif()
|
|
|
|
list(APPEND args --input ${crt_paths} -q)
|
|
|
|
|
|
|
|
get_filename_component(crt_bundle
|
|
|
|
${bundle_name}
|
|
|
|
ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
|
|
|
# Generate bundle according to config
|
|
|
|
add_custom_command(OUTPUT ${crt_bundle}
|
|
|
|
COMMAND ${GENERATE_CERT_BUNDLEPY} ${args}
|
|
|
|
DEPENDS ${custom_bundle_path}
|
|
|
|
VERBATIM)
|
|
|
|
|
|
|
|
add_custom_target(custom_bundle DEPENDS ${cert_bundle})
|
|
|
|
add_dependencies(${COMPONENT_LIB} custom_bundle)
|
|
|
|
|
|
|
|
|
|
|
|
target_add_binary_data(${COMPONENT_LIB} ${crt_bundle} BINARY)
|
|
|
|
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
|
|
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
|
|
|
|
"${crt_bundle}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2018-11-11 07:44:54 +00:00
|
|
|
# Only build mbedtls libraries
|
|
|
|
set(ENABLE_TESTING CACHE BOOL OFF)
|
|
|
|
set(ENABLE_PROGRAMS CACHE BOOL OFF)
|
|
|
|
|
|
|
|
# Needed to for include_next includes to work from within mbedtls
|
2019-05-10 02:53:08 +00:00
|
|
|
include_directories("${COMPONENT_DIR}/port/include")
|
2018-11-11 07:44:54 +00:00
|
|
|
|
|
|
|
# Import mbedtls library targets
|
|
|
|
add_subdirectory(mbedtls)
|
|
|
|
|
2018-11-08 05:56:33 +00:00
|
|
|
# Use port specific implementation of net_socket.c instead of one from mbedtls
|
|
|
|
get_target_property(src_tls mbedtls SOURCES)
|
|
|
|
list(REMOVE_ITEM src_tls net_sockets.c)
|
|
|
|
set_property(TARGET mbedtls PROPERTY SOURCES ${src_tls})
|
|
|
|
|
2018-11-11 07:44:54 +00:00
|
|
|
set(mbedtls_targets mbedtls mbedcrypto mbedx509)
|
|
|
|
|
2020-04-10 08:33:54 +00:00
|
|
|
set(mbedtls_target_sources "${COMPONENT_DIR}/port/mbedtls_debug.c"
|
|
|
|
"${COMPONENT_DIR}/port/net_sockets.c")
|
|
|
|
|
|
|
|
if(CONFIG_MBEDTLS_DYNAMIC_BUFFER)
|
|
|
|
set(mbedtls_target_sources ${mbedtls_target_sources}
|
|
|
|
"${COMPONENT_DIR}/port/dynamic/esp_mbedtls_dynamic_impl.c"
|
|
|
|
"${COMPONENT_DIR}/port/dynamic/esp_ssl_cli.c"
|
|
|
|
"${COMPONENT_DIR}/port/dynamic/esp_ssl_srv.c"
|
|
|
|
"${COMPONENT_DIR}/port/dynamic/esp_ssl_tls.c")
|
|
|
|
endif()
|
|
|
|
|
2018-11-11 07:44:54 +00:00
|
|
|
# Add port files to mbedtls targets
|
2020-04-10 08:33:54 +00:00
|
|
|
target_sources(mbedtls PRIVATE ${mbedtls_target_sources})
|
2019-08-12 12:32:14 +00:00
|
|
|
|
2020-08-13 08:30:59 +00:00
|
|
|
# Choose perihperal type
|
|
|
|
if(CONFIG_IDF_TARGET_ESP32)
|
|
|
|
set(SHA_PERIPHERAL_TYPE "parallel_engine")
|
2020-11-12 07:11:38 +00:00
|
|
|
set(AES_PERIPHERAL_TYPE "block")
|
2020-08-13 08:30:59 +00:00
|
|
|
else()
|
|
|
|
set(SHA_PERIPHERAL_TYPE "dma")
|
2020-11-12 07:11:38 +00:00
|
|
|
set(AES_PERIPHERAL_TYPE "dma")
|
2020-08-13 08:30:59 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-14 07:25:06 +00:00
|
|
|
if(SHA_PERIPHERAL_TYPE STREQUAL "dma")
|
|
|
|
target_include_directories(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/sha/dma/include")
|
|
|
|
|
|
|
|
if(CONFIG_IDF_TARGET_ESP32S2)
|
|
|
|
set(SHA_DMA_SRCS "${COMPONENT_DIR}/port/sha/dma/esp_sha_crypto_dma_impl.c")
|
|
|
|
else()
|
|
|
|
set(SHA_DMA_SRCS "${COMPONENT_DIR}/port/sha/dma/esp_sha_gdma_impl.c")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(AES_PERIPHERAL_TYPE STREQUAL "dma")
|
|
|
|
target_include_directories(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/aes/dma/include")
|
|
|
|
|
|
|
|
if(CONFIG_IDF_TARGET_ESP32S2)
|
|
|
|
set(AES_DMA_SRCS "${COMPONENT_DIR}/port/aes/dma/esp_aes_crypto_dma_impl.c")
|
|
|
|
else()
|
|
|
|
set(AES_DMA_SRCS "${COMPONENT_DIR}/port/aes/dma/esp_aes_gdma_impl.c")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-05-20 02:18:04 +00:00
|
|
|
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_hardware.c"
|
|
|
|
"${COMPONENT_DIR}/port/esp_mem.c"
|
|
|
|
"${COMPONENT_DIR}/port/esp_timing.c"
|
2020-08-13 08:30:59 +00:00
|
|
|
"${COMPONENT_DIR}/port/sha/esp_sha.c"
|
2020-11-12 07:11:38 +00:00
|
|
|
"${COMPONENT_DIR}/port/aes/esp_aes_xts.c"
|
|
|
|
"${COMPONENT_DIR}/port/aes/esp_aes_common.c"
|
|
|
|
"${COMPONENT_DIR}/port/aes/${AES_PERIPHERAL_TYPE}/esp_aes.c"
|
2020-08-13 08:30:59 +00:00
|
|
|
"${COMPONENT_DIR}/port/sha/${SHA_PERIPHERAL_TYPE}/sha.c"
|
2021-01-14 07:25:06 +00:00
|
|
|
"${SHA_DMA_SRCS}"
|
|
|
|
"${AES_DMA_SRCS}"
|
2020-05-20 02:18:04 +00:00
|
|
|
)
|
|
|
|
|
2020-06-16 12:40:12 +00:00
|
|
|
if(CONFIG_ESP_TLS_USE_DS_PERIPHERAL)
|
|
|
|
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp32s2/esp_rsa_sign_alt.c")
|
|
|
|
endif()
|
|
|
|
|
2020-05-20 02:18:04 +00:00
|
|
|
# Note: some mbedTLS hardware acceleration can be enabled/disabled by config.
|
|
|
|
#
|
|
|
|
# We don't need to filter aes.c as this uses a different prefix (esp_aes_x) and the
|
|
|
|
# config option only changes the prefixes in the header so mbedtls_aes_x compiles to esp_aes_x
|
|
|
|
#
|
|
|
|
# The other port-specific files don't override internal mbedTLS functions, they just add new functions.
|
|
|
|
|
|
|
|
if(CONFIG_MBEDTLS_HARDWARE_MPI)
|
|
|
|
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_bignum.c"
|
|
|
|
"${COMPONENT_DIR}/port/${idf_target}/bignum.c"
|
|
|
|
)
|
|
|
|
endif()
|
2019-09-29 10:04:34 +00:00
|
|
|
|
2020-05-20 02:18:04 +00:00
|
|
|
if(CONFIG_MBEDTLS_HARDWARE_SHA)
|
2020-08-13 08:30:59 +00:00
|
|
|
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/sha/${SHA_PERIPHERAL_TYPE}/esp_sha1.c"
|
|
|
|
"${COMPONENT_DIR}/port/sha/${SHA_PERIPHERAL_TYPE}/esp_sha256.c"
|
|
|
|
"${COMPONENT_DIR}/port/sha/${SHA_PERIPHERAL_TYPE}/esp_sha512.c"
|
2020-05-20 02:18:04 +00:00
|
|
|
)
|
|
|
|
endif()
|
2019-09-29 10:04:34 +00:00
|
|
|
|
2020-11-12 07:11:38 +00:00
|
|
|
if(CONFIG_MBEDTLS_HARDWARE_GCM)
|
|
|
|
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/aes/esp_aes_gcm.c")
|
|
|
|
endif()
|
2018-11-11 07:44:54 +00:00
|
|
|
|
|
|
|
foreach(target ${mbedtls_targets})
|
|
|
|
target_compile_definitions(${target} PUBLIC -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h")
|
|
|
|
endforeach()
|
|
|
|
|
2020-04-10 08:33:54 +00:00
|
|
|
if(CONFIG_MBEDTLS_DYNAMIC_BUFFER)
|
|
|
|
set(WRAP_FUNCTIONS
|
|
|
|
mbedtls_ssl_handshake_client_step
|
|
|
|
mbedtls_ssl_handshake_server_step
|
|
|
|
mbedtls_ssl_read
|
|
|
|
mbedtls_ssl_write
|
|
|
|
mbedtls_ssl_session_reset
|
|
|
|
mbedtls_ssl_free
|
|
|
|
mbedtls_ssl_setup
|
|
|
|
mbedtls_ssl_send_alert_message
|
|
|
|
mbedtls_ssl_close_notify)
|
|
|
|
|
|
|
|
foreach(wrap ${WRAP_FUNCTIONS})
|
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
2021-01-12 05:49:11 +00:00
|
|
|
if(CONFIG_MBEDTLS_HARDWARE_MPI)
|
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=mbedtls_mpi_exp_mod")
|
|
|
|
endif()
|
|
|
|
|
2019-08-18 05:28:52 +00:00
|
|
|
set_property(TARGET mbedcrypto APPEND PROPERTY LINK_INTERFACE_LIBRARIES mbedtls)
|
|
|
|
|
2018-11-11 07:44:54 +00:00
|
|
|
# Link mbedtls libraries to component library
|
2020-05-21 06:48:17 +00:00
|
|
|
target_link_libraries(${COMPONENT_LIB} PUBLIC ${mbedtls_targets})
|
2019-10-31 02:39:17 +00:00
|
|
|
|
2020-09-28 04:39:16 +00:00
|
|
|
if(CONFIG_ESP_TLS_USE_DS_PERIPHERAL)
|
|
|
|
# Link target (esp32s2) library to component library
|
|
|
|
target_link_libraries(${COMPONENT_LIB} PUBLIC ${target})
|
|
|
|
endif()
|
|
|
|
|
2020-04-06 14:42:52 +00:00
|
|
|
# Link esp-cryptoauthlib to mbedtls
|
|
|
|
if(CONFIG_ATCA_MBEDTLS_ECDSA)
|
|
|
|
idf_component_get_property(cryptoauthlib esp-cryptoauthlib COMPONENT_LIB)
|
|
|
|
target_link_libraries(${COMPONENT_LIB} PUBLIC ${cryptoauthlib})
|
|
|
|
endif()
|