-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #929 from pguyot/w44/ssl-over-socket-with-mbedtls
Add minimal support for ssl module using Mbed TLS and sockets Details of changes: - Add support for ssl client in binary and passive modes, with no certificate verification - Add APIs to otp_socket so it can be called from ssl bio callbacks - Fix a bug in lwIP otp_socket's recv revealed by ssl tests - Fix a bug in BSD otp_socket's recvfrom revealed by refactoring - Fix a bug in esp32 tests where main context and its resources were not properly destroyed - Update documentation and workflows to reflect the requirement on Mbed TLS - Fix exported types of inet module This code was tested on: - Pico-W - ESP32 using ESP-IDF 5.1 release branch - Unix (macOS) using atomvm_netbench associated test. The test takes 0.5s with Erlang/OTP or AtomVM on macOS. It takes 7.3s then 1.0s on ESP32 It takes 12.0s then from 2.2s to 2.6s on Pico-W These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
- Loading branch information
Showing
35 changed files
with
2,157 additions
and
221 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
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
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
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
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
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,97 @@ | ||
# | ||
# This file is part of AtomVM. | ||
# | ||
# Copyright 2023 Paul Guyot <pguyot@kallisys.net> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later | ||
# | ||
|
||
# Find MbedTLS | ||
# Search for MbedTLS 2.x or 3.x and define libraries like MbedTLS 3.x does. | ||
|
||
# This script is not called FindMbedTLS.cmake because it would conflict with | ||
# installed MbedTLS 3.x | ||
|
||
# If MBEDTLS_ROOT_DIR is set, no heuristic is applied. | ||
# It must be set to the parent directory of include/mbedtls/version.h | ||
# Libraries are at ${MBEDTLS_LIBRARIES_DIR} or, if unset, ${MBEDTLS_ROOT_DIR}/lib/ | ||
|
||
# If MBEDTLS_ROOT_DIR is not set, apply the following heuristic: | ||
# Try to find mbedtls 3.x CMake package with find_package | ||
# If it doesn't work, search for MBEDTLS_VERSION_NUMBER symbol as well as | ||
# the three libraries we need with check_symbol_exists and find_library | ||
|
||
if (MBEDTLS_ROOT_DIR) | ||
set(MbedTLS_FOUND TRUE) | ||
if (NOT MBEDTLS_LIBRARIES_DIR) | ||
set(MBEDTLS_LIBRARIES_DIR ${MBEDTLS_ROOT_DIR}/lib) | ||
endif() | ||
message(STATUS "Will use MbedTLS from ${MBEDTLS_ROOT_DIR} and ${MBEDTLS_LIBRARIES_DIR}") | ||
|
||
add_library(MbedTLS::mbedcrypto SHARED IMPORTED) | ||
set_target_properties(MbedTLS::mbedcrypto PROPERTIES | ||
IMPORTED_LOCATION "${MBEDTLS_LIBRARIES_DIR}/libmbedcrypto${CMAKE_SHARED_LIBRARY_SUFFIX}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_ROOT_DIR}/include/" | ||
) | ||
|
||
add_library(MbedTLS::mbedx509 SHARED IMPORTED) | ||
set_target_properties(MbedTLS::mbedx509 PROPERTIES | ||
IMPORTED_LOCATION "${MBEDTLS_LIBRARIES_DIR}/libmbedx509${CMAKE_SHARED_LIBRARY_SUFFIX}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_ROOT_DIR}/include/" | ||
INTERFACE_LINK_LIBRARIES "MbedTLS::mbedcrypto" | ||
) | ||
|
||
add_library(MbedTLS::mbedtls SHARED IMPORTED) | ||
set_target_properties(MbedTLS::mbedtls PROPERTIES | ||
IMPORTED_LOCATION "${MBEDTLS_LIBRARIES_DIR}/libmbedtls${CMAKE_SHARED_LIBRARY_SUFFIX}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_ROOT_DIR}/include/" | ||
INTERFACE_LINK_LIBRARIES "MbedTLS::mbedx509" | ||
) | ||
else() | ||
# MbedTLS 3.x is installed as a CMake package | ||
find_package(MbedTLS QUIET) | ||
if (MbedTLS_FOUND) | ||
message(STATUS "Found MbedTLS package ${MbedTLS_FOUND}") | ||
else() | ||
include(CheckSymbolExists) | ||
check_symbol_exists(MBEDTLS_VERSION_NUMBER "mbedtls/version.h" HAVE_MBEDTLS_VERSION_NUMBER) | ||
find_library(MBEDCRYPTO mbedcrypto) | ||
find_library(MBEDX509 mbedx509) | ||
find_library(MBEDTLS mbedtls) | ||
if (HAVE_MBEDTLS_VERSION_NUMBER | ||
AND NOT ${MBEDCRYPTO} STREQUAL "MBEDCRYPTO-NOTFOUND" | ||
AND NOT ${MBEDX509} STREQUAL "MBEDX509-NOTFOUND" | ||
AND NOT ${MBEDTLS} STREQUAL "MBEDTLS-NOTFOUND") | ||
message(STATUS "Found MbedTLS with mbedcrypto ${MBEDCRYPTO}, mbedx509 ${MBEDX509} and mbedtls ${MBEDTLS}") | ||
set(MbedTLS_FOUND TRUE) | ||
add_library(MbedTLS::mbedcrypto SHARED IMPORTED) | ||
set_target_properties(MbedTLS::mbedcrypto PROPERTIES | ||
IMPORTED_LOCATION "${MBEDCRYPTO}" | ||
) | ||
|
||
add_library(MbedTLS::mbedx509 SHARED IMPORTED) | ||
set_target_properties(MbedTLS::mbedx509 PROPERTIES | ||
IMPORTED_LOCATION "${MBEDX509}" | ||
INTERFACE_LINK_LIBRARIES "MbedTLS::mbedcrypto" | ||
) | ||
|
||
add_library(MbedTLS::mbedtls SHARED IMPORTED) | ||
set_target_properties(MbedTLS::mbedtls PROPERTIES | ||
IMPORTED_LOCATION "${MBEDTLS}" | ||
INTERFACE_LINK_LIBRARIES "MbedTLS::mbedx509" | ||
) | ||
endif() | ||
endif() | ||
endif() |
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
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
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ set(ERLANG_MODULES | |
logger_std_h | ||
proplists | ||
socket | ||
ssl | ||
string | ||
timer | ||
unicode | ||
|
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
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
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
Oops, something went wrong.