I am using built-in DTLS for encrypting my UDP traffic. In order to save expensive data quota and reduce battery drain, I have to make use of session resumption, so that I do not have to perform the full handshake each time I connect to the server. The handshake including certificate verification works, but with session resumption I am running into problems:
I know I have to enable the session cache with setsockopt(), which I did (see below). It doesn't seem to work, because when I analyze the Client Hello packets the nRF9160 sends to the server, I can see that there is no session_ticket extension present, which suggests that session tickets are not supported. So i fall back to session IDs. My server provides a 32 byte session ID in the Server Hello packet. But after closing and reopening the session on the nRF9160, the session ID in the Client Hello packet is empty, suggesting that the nRF9160 did not cache the session data.
The server uses GNUTLS, and the session resumption mechanism was tested successfully with a separate Client (using openSSL).
I'm not sure about the correct way to enable the session cache with setsockopt(). The header net/socket.h does not provide that option. Whereas the header nrf_socket.h defines the option NRF_SO_SEC_SESSION_CACHE with numeric value 3, whis is the same as the numeric value of TLS_CIPHERSUITE_LIST in net/socket.h. So I certainly cannot use this option ID with setsockopt() from net/socket.h, as is will be interpreted as a ciphersuit list. Does this mean that I have to rewrite my application using all the corresponding nrf_socket functions defined in nrf_socket.h instead of the functions defined in net/socket.h? All the SDK samples use net/socket.h, not nrf_socket.h, btw, and in another thead I read that I should use the net/socket functions, which internally use the nrf_socket functions anyway, which makes me wonder why the option definitions are inconsistent.
Is this the right way to enable the session cache? Is there any documentation on the built-in TLS/DTLS support?
Here is the relevant code, which I am executing several times with variable pause in between: