Hi Lindsay,
thanks for your question!
there is a slight mismatch between what you try to achieve and what the MaxFragmentLength (MFL) extension guarantees: If I understand you correctly, you need to ensure that the UDP payload of UDP datagrams doesn't exceed 512 Bytes, while the MFL extension only guarantees that the DTLS payload isn't larger than 512 Bytes. Due to the additional overhead of DTLS headers and encryption, an MFL of 512 Bytes can therefore still lead to datagrams of size > 512 Bytes (realistically: 560 Bytes) being generated.
What you should use instead is mbedtls_ssl_set_mtu()
, which informs Mbed TLS about the MTU of the underlying transport. If you configure an MTU of 512 Bytes here, Mbed TLS will incorporate record expansion to make sure that it only uses as much DTLS payload to ensure that the total datagram size doesn't exceed 512 Bytes.
The point of failure you describe is still puzzling, though: Is the CRT you're sending smaller than 512 Bytes, so that no fragmentation is necessary? Otherwise, I'd expect you run into problems already when the server is trying to send the Certificate
message, which happens before the ChangeCipherSpec
.
Please also consult the corresponding Mbed TLS Knowledge Base article for extensive documentation of MFL vs. MTU, and let us know if setting the MTU to 512 Bytes through mbedtls_ssl_set_mtu()
resolves your issue.
Best,
Hanno, Mbed TLS team member
I have an U-blox Sara N2 NB-IoT cellular modem connected with a ST Nucleo F207ZG dev board via UART. There is a limitation of 512 bytes per transmit when using the embedded UDP-stack in the modem. Both my DTLS client and the Pelion server support the SSL extension max_fragment_length and this is enabled in the client and presented to the server during the "client hello" handshake stage. The SSL handshake gets as far as the server-originated change cipher spec. but fails due to the outgoing message size being too large for the modem UDP-send command.
Am I wasting my time trying to get certificate-based SSL handshaking to work on such a constrained device, and should I be looking at PSK exchange instead? If anyone has successfully implemented certificate-based exchange in such a constrained setup I ask that they get in touch. ie. what mbedTLS configuration should I be using? I am currently using mbed OS 5.11.