This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DTLS Session Resumption on nRF9160, modem FW v1.1.0

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:

Parents
  • Hi,

     

    For this specific SO_SEC option, it seems that the offloading does not handle it:

    https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/lib/bsdlib/nrf91_sockets.c#L110

     

    the offloading API in zephyr does not have a SEC_SESSION_CACHE defined, so the nrf91_sockets.c cannot handle it properly from an offloading point-of-view. The "NRF_SO_SEC_SESSION_CACHE" must be set using nrf_setsockopt() directly at this time, unfortunately. I'll make the developers aware of this issue.

     

    Kind regards,

    Håkon

  • OK, this is what I do, but it doesn't work. I always get an empty session ID in the Client Hello messages.

    Does the nRF9160 support session IDs and session tickets, or only one of the two?

    How long does it cache a session? Can this timeout be configured?

    Is there any documentation on nRF9160 TLS/DTLS capability?

    BTW, in my code above I forgot to post the SEC_SESSION_CACHE option:

Reply
  • OK, this is what I do, but it doesn't work. I always get an empty session ID in the Client Hello messages.

    Does the nRF9160 support session IDs and session tickets, or only one of the two?

    How long does it cache a session? Can this timeout be configured?

    Is there any documentation on nRF9160 TLS/DTLS capability?

    BTW, in my code above I forgot to post the SEC_SESSION_CACHE option:

Children
  • Hi,

     

    The type it takes in is "nrf_sec_session_cache_t", which is a uint8_t. passing a int shall give an err return.

    Could you try passing this type? Remember to always check the return code.

     

    Kind regards,

    Håkon

  • Sorry, that was an error in my previous post, which I thought I have edited, but the edit does not show... Anyway, actually I am using nrf_sec_session_cache_t used in the struct nrf_sec_config_t, and I am also checking the error code:

  • Hi,

     

    My apologies for the late answer, it took a bit longer than expected to find who worked on this specific feature internally.

    I have been reaching out internally to the teams working on the net stack, and unfortunately gotten this confirmed; session cache is not fully implemented in bsdlib.

    I have also requested that this is to be documented in bsdlib.

     

    Kind regards,

    Håkon

  • OK, thank you for clarifying this!