[STM32H563] Problems getting MQTT with TLSv1.3 to work using NetXDuo
Hello!
I am facing some problems with implementing TLSv1.3. I have enabled NX_SECURE_TLS_ENABLE_TLS_1_3 and NX_SECURE_TLS_TLS_1_3_ENABLED from CubeMX.
I added these into my code:
extern const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers_ecc;
extern const NX_CRYPTO_METHOD *nx_crypto_ecc_curves[];
extern const UINT nx_crypto_ecc_curves_size;
extern const USHORT nx_crypto_ecc_supported_groups[];
extern const UINT nx_crypto_ecc_supported_groups_size;
// ...
UINT tls_setup_callback(NXD_MQTT_CLIENT *client_pt,
NX_SECURE_TLS_SESSION *TLS_session_ptr,
NX_SECURE_X509_CERT *certificate_ptr,
NX_SECURE_X509_CERT *trusted_certificate_ptr)
{
// ...
/* Initialize TLS module */
nx_secure_tls_initialize();
/* Create a TLS session */
ret = nx_secure_tls_session_create(TLS_session_ptr, &nx_crypto_tls_ciphers_ecc,
crypto_metadata_client, sizeof(crypto_metadata_client));
if (ret != NX_SUCCESS)
{
return ret;
}
/* Force the use of TLS 1.3 */
ret = nx_secure_tls_session_protocol_version_override(TLS_session_ptr, NX_SECURE_TLS_VERSION_TLS_1_3);
if (ret != NX_SUCCESS)
{
return ret;
}
/* Enable ECC cipher suite to be used when using ECC generated keys */
ret = nx_secure_tls_ecc_initialize(TLS_session_ptr,
nx_crypto_ecc_supported_groups,
nx_crypto_ecc_supported_groups_size,
nx_crypto_ecc_curves);
if (ret != NX_SUCCESS)
{
return ret;
}
// ...
}Everything else stayed the same as it was when using TLSv1.2 (which is working).
The tls_setup_callback function finished without issues, but when trying to establish a connection, it will fail due to a handshake error. I also tried connecting with the same client key and certificate using OpenSSL command, and the connection was a success, so the key and certificate are not the issue here.
The program always goes to the NX_SECURE_TLS_ALERT case (in the nx_secure_tls_process_record.c file), where it then returns NX_SECURE_TLS_ALERT_RECEIVED (alert 0x28 (decimal value of 40), which indicates handshake failure).
Also tried to create a separate NX_SECURE_TLS_CRYPTO
const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers_ecc_1_3 =
{
/* Ciphersuite lookup table and size. */
_nx_crypto_ciphersuite_lookup_table_tls_1_3,
_nx_crypto_ciphersuite_lookup_table_tls_1_3_size,
/* X.509 certificate cipher table and size. */
_nx_crypto_x509_cipher_lookup_table_ecc,
_nx_crypto_x509_cipher_lookup_table_ecc_size,
/* TLS version-specific methods. */
/* For TLSv1.0 and TLSv1.1 */
// NULL,
// NULL,
// NULL,
/* For TLSv1.2 */
NULL,
NULL,
/* For TLSv1.3 */
&crypto_method_hkdf,
&crypto_method_hmac,
&crypto_method_ecdhe,
};where _nx_crypto_ciphersuite_lookup_table_tls_1_3 table is using only the TLS_AES_128_GCM_SHA256 cipher, which is definitely supported by the remote server (checked when tried to connect using the OpenSSL command and forcing it to use TLS_AES_128_GCM_SHA256). But no results, same alert level and error.
Is there anything else that needs to be done in the code in order to use TLSv1.3?
