Repository: godotengine/godot (language: cpp)

Issue:
Build error on Fedora 41 with `builtin_mbedtls=no`
### Tested versions

- Reproducible in: 4.4.beta https://github.com/godotengine/godot/commit/93d270693079ea7802c9e1334a2e0ecd8529eeed

### System information

Godot v4.4.beta (93d270693) - Fedora Linux 41 (KDE Plasma) on X11 - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4090 (nvidia; 565.77) - 13th Gen Intel(R) Core(TM) i9-13900K (32 threads)

### Issue description

I get a build error on Fedora 41 with `builtin_mbedtls=no`:

```
modules/mbedtls/tls_context_mbedtls.cpp: In member function 'Error TLSContextMbedTLS::init_server(int, Ref<TLSOptions>, Ref<CookieContextMbedTLS>)':
modules/mbedtls/tls_context_mbedtls.cpp:151:57: error: 'MBEDTLS_SSL_VERSION_TLS1_2' was not declared in this scope; did you mean 'MBEDTLS_SSL_PROTO_TLS1_2'?
  151 |                 mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
      |                                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                         MBEDTLS_SSL_PROTO_TLS1_2
modules/mbedtls/tls_context_mbedtls.cpp:151:17: error: 'mbedtls_ssl_conf_max_tls_version' was not declared in this scope; did you mean 'mbedtls_ssl_conf_max_version'?
  151 |                 mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 mbedtls_ssl_conf_max_version
modules/mbedtls/tls_context_mbedtls.cpp: In member function 'Error TLSContextMbedTLS::init_client(int, const String&, Ref<TLSOptions>)':
modules/mbedtls/tls_context_mbedtls.cpp:198:57: error: 'MBEDTLS_SSL_VERSION_TLS1_2' was not declared in this scope; did you mean 'MBEDTLS_SSL_PROTO_TLS1_2'?
  198 |                 mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
      |                                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                         MBEDTLS_SSL_PROTO_TLS1_2
modules/mbedtls/tls_context_mbedtls.cpp:198:17: error: 'mbedtls_ssl_conf_max_tls_version' was not declared in this scope; did you mean 'mbedtls_ssl_conf_max_version'?
  198 |                 mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 mbedtls_ssl_conf_max_version
```

In comparison, it works with `builtin_mbedtls=yes` (the default). This is likely a regression from https://github.com/godotengine/godot/pull/102774. cc @Faless 

### Steps to reproduce

- Run `scons builtin_mbedtls=no` on Fedora 41 with the system mbedTLS package installed.

### Minimal reproduction project (MRP)

N/A


Discussion / hints:

Fix patch:
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 79bf8975411b..94c975b468ef 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -2207,6 +2207,7 @@
 		<member name="network/tls/enable_tls_v1.3" type="bool" setter="" getter="" default="false">
 			If [code]true[/code], enable TLSv1.3 negotiation.
 			[b]Note:[/b] This is experimental, and may cause connections to fail in some cases (notably, if the remote server uses TLS handshake fragmentation).
+			[b]Note:[/b] Only supported when using Mbed TLS 3.0 or later (Linux distribution packages may be compiled against older system Mbed TLS packages), otherwise the maximum supported TLS version is always TLSv1.2.
 		</member>
 		<member name="physics/2d/default_angular_damp" type="float" setter="" getter="" default="1.0">
 			The default rotational motion damping in 2D. Damping is used to gradually slow down physical objects over time. RigidBodies will fall back to this value when combining their own damping values and no area damping value is present.
diff --git a/modules/mbedtls/tls_context_mbedtls.cpp b/modules/mbedtls/tls_context_mbedtls.cpp
index 33c4cfd5450e..f7d3422f9fad 100644
--- a/modules/mbedtls/tls_context_mbedtls.cpp
+++ b/modules/mbedtls/tls_context_mbedtls.cpp
@@ -147,9 +147,11 @@ Error TLSContextMbedTLS::init_server(int p_transport, Ref<TLSOptions> p_options,
 		mbedtls_ssl_conf_dtls_cookies(&conf, mbedtls_ssl_cookie_write, mbedtls_ssl_cookie_check, &(cookies->cookie_ctx));
 	}
 
+#if MBEDTLS_VERSION_MAJOR >= 3
 	if (Engine::get_singleton()->is_editor_hint() || !(bool)GLOBAL_GET("network/tls/enable_tls_v1.3")) {
 		mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
 	}
+#endif
 
 	mbedtls_ssl_setup(&tls, &conf);
 	return OK;
@@ -194,9 +196,11 @@ Error TLSContextMbedTLS::init_client(int p_transport, const String &p_hostname,
 		}
 	}
 
+#if MBEDTLS_VERSION_MAJOR >= 3
 	if (Engine::get_singleton()->is_editor_hint() || !(bool)GLOBAL_GET("network/tls/enable_tls_v1.3")) {
 		mbedtls_ssl_conf_max_tls_version(&conf, MBEDTLS_SSL_VERSION_TLS1_2);
 	}
+#endif
 
 	// Set valid CAs
 	mbedtls_ssl_conf_ca_chain(&conf, &(cas->cert), nullptr);


Test patch: