Prefer X25519 for legacy WSS full handshakes
Prioritize X25519 while retaining enabled curve fallbacks and log the negotiated ECDHE group. Extend ABI checks, crypto benchmarks and backend group probes, and document the updated APP package.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#ifdef LIBRWS_USING_MBED_TLS
|
||||
#include "mbedtls/base64.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/ssl_internal.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1849,6 +1850,24 @@ void rws_debug(void *ctx, int level, const char *file, int line, const char *str
|
||||
LOG_I("%s", str ? str : NULL);
|
||||
}
|
||||
|
||||
/* Prefer a fast, widely supported full-handshake group on this MCU.
|
||||
* Retain all groups enabled by the shared SDK profile as fallbacks. */
|
||||
static const mbedtls_ecp_group_id rws_tls_preferred_curves[] = {
|
||||
MBEDTLS_ECP_DP_CURVE25519,
|
||||
MBEDTLS_ECP_DP_SECP256R1,
|
||||
MBEDTLS_ECP_DP_SECP384R1,
|
||||
MBEDTLS_ECP_DP_SECP521R1,
|
||||
MBEDTLS_ECP_DP_CURVE448,
|
||||
MBEDTLS_ECP_DP_BP512R1,
|
||||
MBEDTLS_ECP_DP_BP384R1,
|
||||
MBEDTLS_ECP_DP_BP256R1,
|
||||
MBEDTLS_ECP_DP_SECP224R1,
|
||||
MBEDTLS_ECP_DP_SECP224K1,
|
||||
MBEDTLS_ECP_DP_SECP192R1,
|
||||
MBEDTLS_ECP_DP_SECP192K1,
|
||||
MBEDTLS_ECP_DP_NONE
|
||||
};
|
||||
|
||||
static const char *rws_tls_phase_name(int state)
|
||||
{
|
||||
switch (state) {
|
||||
@@ -1875,6 +1894,13 @@ static int rws_tls_handshake_timed(mbedtls_ssl_context *ctx)
|
||||
break;
|
||||
if (ret != 0) ++retries;
|
||||
if (ctx->state != state) {
|
||||
if (state == MBEDTLS_SSL_SERVER_KEY_EXCHANGE && ctx->handshake) {
|
||||
mbedtls_ecp_group_id group = ctx->handshake->ecdh_ctx.grp_id;
|
||||
LOG_I("WSS TLS negotiated ECDHE group: %d (X25519=%d, P256=%d, P384=%d, P521=%d)\n",
|
||||
(int)group, (int)MBEDTLS_ECP_DP_CURVE25519,
|
||||
(int)MBEDTLS_ECP_DP_SECP256R1, (int)MBEDTLS_ECP_DP_SECP384R1,
|
||||
(int)MBEDTLS_ECP_DP_SECP521R1);
|
||||
}
|
||||
LOG_I("WSS TLS phase %s (%d): elapsed=%u ms, calls=%u ms, retries=%u\n",
|
||||
rws_tls_phase_name(state), state,
|
||||
(unsigned int)(ql_rtos_get_systicks() - phase_started) * 5,
|
||||
@@ -1936,6 +1962,10 @@ int rws_ssl_conn(_rws_socket *s)
|
||||
ret = mbedtls_ssl_config_defaults(&ssl->ssl_conf, MBEDTLS_SSL_IS_CLIENT,
|
||||
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
|
||||
if (ret != 0) goto exit;
|
||||
/* Equivalent to mbedtls_ssl_conf_curves(): this SDK does not export its
|
||||
setter to APP. The shared profile and ABI test cover curve_list. */
|
||||
ssl->ssl_conf.curve_list = rws_tls_preferred_curves;
|
||||
LOG_I("WSS TLS full handshake: prefer X25519, P256, P384, P521\n");
|
||||
mbedtls_ssl_conf_authmode(&ssl->ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED);
|
||||
mbedtls_ssl_conf_ca_chain(&ssl->ssl_conf, &ssl->cacert, NULL);
|
||||
mbedtls_ssl_conf_min_version(&ssl->ssl_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3);
|
||||
|
||||
Reference in New Issue
Block a user