Skip to content

Commit

Permalink
[mbedTLS] Enable TLS 1.3 support
Browse files Browse the repository at this point in the history
Move library initialization to module registration functions.

Only set library debug threshold when verbose output is enabled.

TLSv1.3 functions seems to be a bit more verbose then expected, and
generate a lot of noise. Yet, some level of debugging without
recompiling the engine would be nice. We should discuss this upstream.
  • Loading branch information
Faless committed Sep 26, 2024
1 parent 395a4fc commit 936657c
Show file tree
Hide file tree
Showing 20 changed files with 16,933 additions and 16 deletions.
16 changes: 16 additions & 0 deletions modules/mbedtls/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ if env["builtin_mbedtls"]:
"platform.c",
"platform_util.c",
"poly1305.c",
"psa_crypto.c",
"psa_crypto_aead.c",
"psa_crypto_cipher.c",
"psa_crypto_client.c",
"psa_crypto_driver_wrappers_no_static.c",
"psa_crypto_ecp.c",
"psa_crypto_ffdh.c",
"psa_crypto_hash.c",
"psa_crypto_mac.c",
"psa_crypto_pake.c",
"psa_crypto_rsa.c",
"psa_crypto_se.c",
"psa_crypto_slot_management.c",
"psa_crypto_storage.c",
"psa_its_file.c",
"psa_util.c",
"ripemd160.c",
"rsa.c",
"rsa_alt_helpers.c",
Expand Down
4 changes: 0 additions & 4 deletions modules/mbedtls/crypto_mbedtls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,6 @@ Crypto *CryptoMbedTLS::create(bool p_notify_postinitialize) {
}

void CryptoMbedTLS::initialize_crypto() {
#ifdef DEBUG_ENABLED
mbedtls_debug_set_threshold(1);
#endif

Crypto::_create = create;
Crypto::_load_default_certificates = load_default_certificates;
X509CertificateMbedTLS::make_default();
Expand Down
27 changes: 27 additions & 0 deletions modules/mbedtls/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,34 @@
#include "packet_peer_mbed_dtls.h"
#include "stream_peer_mbedtls.h"

#if MBEDTLS_VERSION_MAJOR >= 3
#include <psa/crypto.h>
#endif

#ifdef TESTS_ENABLED
#include "tests/test_crypto_mbedtls.h"
#endif

static bool godot_mbedls_initialized = false;

void initialize_mbedtls_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}

#if MBEDTLS_VERSION_MAJOR >= 3
int status = psa_crypto_init();
ERR_FAIL_COND_MSG(status != PSA_SUCCESS, "Failed to initialize psa crypto. The mbedTLS modules will not work.");
#endif

#ifdef DEBUG_ENABLED
if (OS::get_singleton()->is_stdout_verbose()) {
mbedtls_debug_set_threshold(1);
}
#endif

godot_mbedls_initialized = true;

CryptoMbedTLS::initialize_crypto();
StreamPeerMbedTLS::initialize_tls();
PacketPeerMbedDTLS::initialize_dtls();
Expand All @@ -55,6 +74,14 @@ void uninitialize_mbedtls_module(ModuleInitializationLevel p_level) {
return;
}

if (!godot_mbedls_initialized) {
return;
}

#if MBEDTLS_VERSION_MAJOR >= 3
mbedtls_psa_crypto_free();
#endif

DTLSServerMbedTLS::finalize();
PacketPeerMbedDTLS::finalize_dtls();
StreamPeerMbedTLS::finalize_tls();
Expand Down
12 changes: 0 additions & 12 deletions thirdparty/mbedtls/include/godot_module_mbedtls_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@
// Disable deprecated
#define MBEDTLS_DEPRECATED_REMOVED

// mbedTLS 3.6 finally enabled TLSv1.3 by default, but it requires some mobule
// changes, and to enable PSA crypto (new "standard" API specification).
// Disable it for now.
#undef MBEDTLS_SSL_PROTO_TLS1_3

// Disable PSA Crypto.
#undef MBEDTLS_PSA_CRYPTO_CONFIG
#undef MBEDTLS_PSA_CRYPTO_C
#undef MBEDTLS_PSA_CRYPTO_STORAGE_C
#undef MBEDTLS_PSA_ITS_FILE_C
#undef MBEDTLS_LMS_C

#endif // GODOT_MBEDTLS_INCLUDE_H

#endif // GODOT_MODULE_MBEDTLS_CONFIG_H
Loading

0 comments on commit 936657c

Please sign in to comment.