diff --git a/core/crypto/SCsub b/core/crypto/SCsub index 9b7953fdc5f..ac79e10d19a 100644 --- a/core/crypto/SCsub +++ b/core/crypto/SCsub @@ -20,12 +20,13 @@ if is_builtin or not has_module: # Only if the module is not enabled, we must compile here the required sources # to make a "light" build with only the necessary mbedtls files. if not has_module: - env_thirdparty = env_crypto.Clone() - env_thirdparty.disable_warnings() - # Custom config file - env_thirdparty.Append( + # Minimal mbedTLS config file + env_crypto.Append( CPPDEFINES=[("MBEDTLS_CONFIG_FILE", '\\"thirdparty/mbedtls/include/godot_core_mbedtls_config.h\\"')] ) + # Build minimal mbedTLS library (MD5/SHA/Base64/AES). + env_thirdparty = env_crypto.Clone() + env_thirdparty.disable_warnings() thirdparty_mbedtls_dir = "#thirdparty/mbedtls/library/" thirdparty_mbedtls_sources = [ "aes.c", @@ -40,8 +41,16 @@ if not has_module: ] thirdparty_mbedtls_sources = [thirdparty_mbedtls_dir + file for file in thirdparty_mbedtls_sources] env_thirdparty.add_source_files(thirdparty_obj, thirdparty_mbedtls_sources) + # Needed to force rebuilding the library when the configuration file is updated. + env_thirdparty.Depends(thirdparty_obj, "#thirdparty/mbedtls/include/godot_core_mbedtls_config.h") env.core_sources += thirdparty_obj - +elif is_builtin: + # Module mbedTLS config file + env_crypto.Append( + CPPDEFINES=[("MBEDTLS_CONFIG_FILE", '\\"thirdparty/mbedtls/include/godot_module_mbedtls_config.h\\"')] + ) + # Needed to force rebuilding the core files when the configuration file is updated. + thirdparty_obj = ["#thirdparty/mbedtls/include/godot_module_mbedtls_config.h"] # Godot source files diff --git a/modules/mbedtls/SCsub b/modules/mbedtls/SCsub index 9133fdef35d..7c1204d2b77 100644 --- a/modules/mbedtls/SCsub +++ b/modules/mbedtls/SCsub @@ -100,10 +100,14 @@ if env["builtin_mbedtls"]: thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] env_mbed_tls.Prepend(CPPPATH=["#thirdparty/mbedtls/include/"]) + env_mbed_tls.Append( + CPPDEFINES=[("MBEDTLS_CONFIG_FILE", '\\"thirdparty/mbedtls/include/godot_module_mbedtls_config.h\\"')] + ) env_thirdparty = env_mbed_tls.Clone() env_thirdparty.disable_warnings() env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) + env_thirdparty.Depends(thirdparty_obj, "#thirdparty/mbedtls/include/godot_module_mbedtls_config.h") env.modules_sources += thirdparty_obj diff --git a/modules/mbedtls/packet_peer_mbed_dtls.cpp b/modules/mbedtls/packet_peer_mbed_dtls.cpp index e8eb32f88d1..ed1a97cc2ce 100644 --- a/modules/mbedtls/packet_peer_mbed_dtls.cpp +++ b/modules/mbedtls/packet_peer_mbed_dtls.cpp @@ -29,7 +29,6 @@ /**************************************************************************/ #include "packet_peer_mbed_dtls.h" -#include "mbedtls/platform_util.h" #include "core/io/file_access.h" #include "core/io/stream_peer_tls.h" diff --git a/thirdparty/README.md b/thirdparty/README.md index b079e27d152..32bcea6c1bc 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -378,6 +378,7 @@ File extracted from upstream release tarball: Applied the patch in `patches/windows-arm64-hardclock.diff` - Added 2 files `godot_core_mbedtls_platform.c` and `godot_core_mbedtls_config.h` providing configuration for light bundling with core. +- Added the file `godot_module_mbedtls_config.h` to customize the build configuration when bundling the full library. ## meshoptimizer diff --git a/thirdparty/mbedtls/include/godot_core_mbedtls_config.h b/thirdparty/mbedtls/include/godot_core_mbedtls_config.h index 9e7b2742a7b..d27bf608fbe 100644 --- a/thirdparty/mbedtls/include/godot_core_mbedtls_config.h +++ b/thirdparty/mbedtls/include/godot_core_mbedtls_config.h @@ -1,3 +1,38 @@ +/**************************************************************************/ +/* godot_core_mbedtls_config.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef GODOT_CORE_MBEDTLS_CONFIG_H +#define GODOT_CORE_MBEDTLS_CONFIG_H + +#include + // For AES #define MBEDTLS_CIPHER_MODE_CBC #define MBEDTLS_CIPHER_MODE_CFB @@ -15,4 +50,4 @@ #define MBEDTLS_PLATFORM_ZEROIZE_ALT #define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES -#include +#endif // GODOT_CORE_MBEDTLS_CONFIG_H diff --git a/thirdparty/mbedtls/include/godot_module_mbedtls_config.h b/thirdparty/mbedtls/include/godot_module_mbedtls_config.h new file mode 100644 index 00000000000..c35f1580410 --- /dev/null +++ b/thirdparty/mbedtls/include/godot_module_mbedtls_config.h @@ -0,0 +1,58 @@ +/**************************************************************************/ +/* godot_module_mbedtls_config.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef GODOT_MODULE_MBEDTLS_CONFIG_H +#define GODOT_MODULE_MBEDTLS_CONFIG_H + +#include "platform_config.h" + +#ifdef GODOT_MBEDTLS_INCLUDE_H + +// Allow platforms to customize the mbedTLS configuration. +#include GODOT_MBEDTLS_INCLUDE_H + +#else + +// Include default mbedTLS config. +#include + +// Disable weak cryptography. +#undef MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED +#undef MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED +#undef MBEDTLS_SSL_CBC_RECORD_SPLITTING +#undef MBEDTLS_SSL_PROTO_TLS1 +#undef MBEDTLS_SSL_PROTO_TLS1_1 +#undef MBEDTLS_ARC4_C +#undef MBEDTLS_DES_C +#undef MBEDTLS_DHM_C + +#endif // GODOT_MBEDTLS_INCLUDE_H + +#endif // GODOT_MODULE_MBEDTLS_CONFIG_H