netxduo icon indicating copy to clipboard operation
netxduo copied to clipboard

DTLS problem with cipher suite TLS_PSK_WITH_AES_128_CBC_SHA256

Open igortomiatti opened this issue 1 year ago • 6 comments

Hi,

I'm making a DTLS client application on an STM32 and I started testing it with a raspberrypi with GnuTLS Server, in the first tests I used the TLS_PSK_WITH_AES_128_CCM_8 cipher suite and everything worked correctly. However, I need to use the TLS_PSK_WITH_AES_128_CBC_SHA256 cipher suite and when I did the same test with the raspberrypi it didn't work as expected:

  • The nx_secure_dtls_client_session_start function returned 0x01
  • GnuTLS returned the error:

|<0xd8cde8>| Discarded message[0] due to invalid decryption |<0xd8cde8>| Discarded message[2] due to invalid decryption |<0xd8cde8>| Discarded message[3] due to invalid decryption |<0xd8cde8>| Discarded message[0] due to invalid decryption |<0xd8cde8>| Discarded message[2] due to invalid decryption |<0xd8cde8>| Discarded message[3] due to invalid decryption |<0xd8cde8>| Discarded message[0] due to invalid decryption |<0xd8cde8>| Discarded message[2] due to invalid decryption |<0xd8cde8>| Discarded message[3] due to invalid decryption |<0xd8cde8>| Discarded message[0] due to invalid decryption

I did the wireshark capture and it seems that the error occurs after Change Cipher Spec, because the client sends a Hello Request(Fragment) and Hello Request with the error: Fragment runs past the end of the message.

Image

Image

Then I did another test, I set up another STM32 board with a DTLS server and as expected the TLS_PSK_WITH_AES_128_CCM_8 cipher suite worked correctly, but the TLS_PSK_WITH_AES_128_CBC_SHA256 cipher suite also gave an error:

  • Client side: The nx_secure_dtls_client_session_start function returned 0x114 (Received an alert from the remote host during the DTLS handshake).
  • Server side: The nx_secure_dtls_server_session_start function returned 0x12A (Encryption padding check failure).

Is there any specific configuration for this cipher suite to work correctly?

igortomiatti avatar Feb 12 '25 18:02 igortomiatti

Are you using hardware accelerated encryption on the STM32?

If yes, disable it and test using only the software routines. The issue you are seeing may be in the hardware accelerated code rather in the NX Secure core code. A while back I had similar issues due to invalid padding in the vendor supplied hardware accelerated encryption routines (that was a different MCU vendor though).

hwmaier avatar Feb 12 '25 22:02 hwmaier

Hi,

I'm not using a hardware accelerator encryption.

The only STM32 security module I'm using is true random number generation, but I haven't integrated TRNG with NetXDuo yet.

igortomiatti avatar Feb 13 '25 13:02 igortomiatti

Can the members of @eclipse-threadx/iot-threadx-committers and @eclipse-threadx/iot-threadx-contributors comment on this issue, please?

fdesbiens avatar Feb 13 '25 15:02 fdesbiens

Hi, I'm also having a similar problem using the STM32 microcontroller with the TLS_PSK_WITH_AES_128_CBC_SHA256 cipher. And this error does not occur with other ciphers such as TLS_PSK_WITH_AES_128_CCM_8. But for the project is needed to use a SHA256 cipher.

Have you solved this in any way? @igortomiatti

LeeoMariani avatar Feb 26 '25 19:02 LeeoMariani

@eclipse-threadx/iot-threadx-committers and @eclipse-threadx/iot-threadx-contributors: your insights are needed.

fdesbiens avatar Feb 26 '25 21:02 fdesbiens

Hi, I'm also having a similar problem using the STM32 microcontroller with the TLS_PSK_WITH_AES_128_CBC_SHA256 cipher. And this error does not occur with other ciphers such as TLS_PSK_WITH_AES_128_CCM_8. But for the project is needed to use a SHA256 cipher.

Have you solved this in any way? @igortomiatti

Hi @LeeoMariani, I've done a few more tests, but I still haven't succeeded in getting this cipher suite to work.

igortomiatti avatar Mar 11 '25 16:03 igortomiatti