[riot-notifications] [RIOT-OS/RIOT] sock/dtls: add function to retrieve epoch of session (#15881)

János Brodbeck notifications at github.com
Thu Jan 28 15:49:31 CET 2021


### Contribution description
This PR adds a new function to the DTLS sock API: `sock_dtls_session_get_epoch()`. This function retrieves the current epoch of a session. The epoch is used for example in coap to match request and response for DTLS secured coap messaging. The epoch must be the same for request and response in that case (see [RFC 7252](https://tools.ietf.org/html/rfc7252#section-9.1.1)). This function should provide a generic way to access it.

### Testing procedure
Implementation in tinyDTLS can be tested with the test [pkg_tinydtls_sock_async](https://github.com/RIOT-OS/RIOT/tree/master
/tests/pkg_tinydtls_sock_async) together with this patch:
<details>

```
diff --git a/tests/pkg_tinydtls_sock_async/dtls-client.c b/tests/pkg_tinydtls_sock_async/dtls-client.c
index 78d2fefa19..ccbfa862e0 100644
--- a/tests/pkg_tinydtls_sock_async/dtls-client.c
+++ b/tests/pkg_tinydtls_sock_async/dtls-client.c
@@ -163,6 +163,7 @@ static void _dtls_handler(sock_dtls_t *sock, sock_async_flags_t type, void *arg)
             printf("Received %d bytes: \"%.*s\"\n", (int)res, (int)res,
                    (char *)_recv_buf);
         }
+        printf("Epoch of the session is %d\n", sock_dtls_session_get_epoch(sock, &session));
         puts("Terminating session");
         sock_dtls_session_destroy(sock, &session);
         _close_sock(sock);
diff --git a/tests/pkg_tinydtls_sock_async/dtls-server.c b/tests/pkg_tinydtls_sock_async/dtls-server.c
index 060a6f10b7..7a5b637578 100644
--- a/tests/pkg_tinydtls_sock_async/dtls-server.c
+++ b/tests/pkg_tinydtls_sock_async/dtls-server.c
@@ -160,6 +160,7 @@ static void _dtls_handler(sock_dtls_t *sock, sock_async_flags_t type, void *arg)
                 printf("Error resending DTLS message: %d\n", (int)res);
             }
         }
+        printf("Epoch of the session is %d\n", sock_dtls_session_get_epoch(sock, &session));
     }
 }
 
```
</details>

To run it: 
* Flash and run on two devices (e.g. native)
* Execute `dtlss` on of the devices
* Execute `dtlsc {ip} {some data}` on the other device

The epoch should be printed for the received message. The epoch can also be sniffed with wireshark and must be the same.
Printed epoch is the epoch of the packets with `Application data` in the info field. 

### Issues/PRs references

<!--
Examples: Fixes #1234. See also #5678. Depends on PR #9876.

Please use keywords (e.g., fixes, resolve) with the links to the issues you
resolved, this way they will be automatically closed when your pull request
is merged. See https://help.github.com/articles/closing-issues-using-keywords/.
-->

You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/15881

-- Commit Summary --

  * sock/dtls: introduce function to retrieve epoch of a session
  * pkg/tinydtls: implement sock_dtls_session_get_epoch()

-- File Changes --

    M pkg/tinydtls/contrib/sock_dtls.c (13)
    M sys/include/net/sock/dtls.h (13)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/15881.patch
https://github.com/RIOT-OS/RIOT/pull/15881.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15881
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210128/f3aea1ce/attachment-0001.htm>


More information about the notifications mailing list