Skip to content

Commit 7b5fda1

Browse files
committed
fix(libtls): enable SHA-384/512 and modern TLS extensions to fix cert verify
The default mbedtls_config.h profile force-undefs MBEDTLS_SHA384_C and MBEDTLS_SHA512_C when ENABLE_CUSTOM_CONFIG=n. As a result mbedTLS cannot recognize the sha384WithRSAEncryption OID (1.2.840.113549.1.1.12), so any intermediate CA signed with RSA-SHA384 is silently dropped from the peer chain with MBEDTLS_ERR_OID_NOT_FOUND. The verify_cb only sees the leaf, the issuer cannot be located, and verification fails with NOT_TRUSTED (flag 0x8) on otherwise valid chains - e.g. *.wgine.com leaf signed by GoGetSSL RSA DV CA (RSA-SHA384) chained up to AAA Certificate Services. Fix: - enable MBEDTLS_SHA384_C / MBEDTLS_SHA512_C by default (root cause) - enable MBEDTLS_SSL_RENEGOTIATION / _ALPN / _SESSION_TICKETS so the ClientHello carries the standard modern extensions - drop the ECDHE-RSA-AES128-CBC-SHA256 suite, add ChaCha20-Poly1305 AEAD suites and reorder ECDSA-first to match common server preference Made-with: Cursor
1 parent effe2f1 commit 7b5fda1

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

src/libtls/port/tuya_tls_config.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@
16521652
* configuration of this extension).
16531653
*
16541654
*/
1655-
//#define MBEDTLS_SSL_RENEGOTIATION
1655+
#define MBEDTLS_SSL_RENEGOTIATION
16561656

16571657
/**
16581658
* \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
@@ -1784,7 +1784,7 @@
17841784
*
17851785
* Comment this macro to disable support for ALPN.
17861786
*/
1787-
//#define MBEDTLS_SSL_ALPN
1787+
#define MBEDTLS_SSL_ALPN
17881788

17891789
/**
17901790
* \def MBEDTLS_SSL_DTLS_ANTI_REPLAY
@@ -1910,7 +1910,7 @@
19101910
#undef MBEDTLS_SSL_SESSION_TICKETS
19111911
#endif
19121912
#else
1913-
// #define MBEDTLS_SSL_SESSION_TICKETS
1913+
#define MBEDTLS_SSL_SESSION_TICKETS
19141914
#endif
19151915
/**
19161916
* \def MBEDTLS_SSL_EXPORT_KEYS
@@ -3231,8 +3231,14 @@
32313231
#undef MBEDTLS_SHA384_C
32323232
#endif
32333233
#else
3234-
#undef MBEDTLS_SHA512_C
3235-
#undef MBEDTLS_SHA384_C
3234+
/* Enabled by default. Many real-world intermediate CAs are signed with
3235+
* sha384WithRSAEncryption (OID 1.2.840.113549.1.1.12). Without SHA-384/512
3236+
* compiled in, mbedtls_x509_crt_parse silently drops these certs from the
3237+
* peer chain with MBEDTLS_ERR_OID_NOT_FOUND, leaving only the leaf and
3238+
* triggering MBEDTLS_X509_BADCERT_NOT_TRUSTED on otherwise valid chains
3239+
* (e.g. *.wgine.com leaf -> GoGetSSL RSA DV CA SHA-384 intermediate). */
3240+
#define MBEDTLS_SHA512_C
3241+
#define MBEDTLS_SHA384_C
32363242
#endif
32373243

32383244

src/tuya_cloud_service/tls/tuya_tls.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,16 @@ static OPERATE_RET mbedtls_cert_pkey_parse(tuya_tls_hander p_tls_handler)
402402
return OPRT_OK;
403403
}
404404

405-
static int tuya_tls_ciphersuite_list[] = {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
406-
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
407-
MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 0};
405+
/* Modern AEAD-only suite list. CBC mode dropped (no longer recommended) and
406+
* ChaCha20-Poly1305 added so we negotiate one of the AEAD suites that every
407+
* mainstream TLS 1.2 server supports. */
408+
static int tuya_tls_ciphersuite_list[] = {
409+
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
410+
MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
411+
MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
412+
MBEDTLS_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
413+
0,
414+
};
408415

409416
/**
410417
* @brief Initializes the Tuya TLS module.

0 commit comments

Comments
 (0)