Skip to content

Commit

Permalink
net: lwm2m: Support DTLS Connection Identifier
Browse files Browse the repository at this point in the history
DTLS Connection Identifier support requires DTLS stack
that supports it. MbedTLS support in Zephyr is already
ported in, also some offloaded sockets support it.

Signed-off-by: Seppo Takalo <[email protected]>
  • Loading branch information
SeppoTakalo authored and carlescufi committed Nov 17, 2023
1 parent 100836e commit 8cfede8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/connectivity/networking/api/lwm2m.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ NoSec
In all modes, Server URI resource (ID 0) must contain the full URI for the target server.
When DNS names are used, the DNS resolver must be enabled.

When DTLS is used, following options are recommended to reduce DTLS handshake traffic when connection is re-established:

* :kconfig:option:`CONFIG_LWM2M_DTLS_CID` enables DTLS Connection Identifier support. When server supports it, this completely removes the handshake when device resumes operation after long idle period. Greatly helps when NAT mappings have timed out.
* :kconfig:option:`CONFIG_LWM2M_TLS_SESSION_CACHING` uses session cache when before falling back to full DTLS handshake. Reduces few packets from handshake, when session is still cached on server side. Most significant effect is to avoid full registration.

LwM2M stack provides callbacks in the :c:struct:`lwm2m_ctx` structure.
They are used to feed keys from the LwM2M security object into the TLS credential subsystem.
By default, these callbacks can be left as NULL pointers, in which case default callbacks are used.
Expand Down
3 changes: 3 additions & 0 deletions samples/net/lwm2m_client/overlay-dtls.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Enable DTLS with Connection Identifier
CONFIG_LWM2M_DTLS_SUPPORT=y
CONFIG_LWM2M_DTLS_CID=y
CONFIG_LWM2M_PEER_PORT=5684

# Select Zephyr mbedtls
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_TLS_VERSION_1_2=y
CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID=y

# Special MbedTLS changes
CONFIG_MBEDTLS_ENABLE_HEAP=y
Expand Down
7 changes: 7 additions & 0 deletions subsys/net/lib/lwm2m/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ config LWM2M_TLS_SESSION_CACHING
help
Enabling this only when feature is supported in TLS library.

config LWM2M_DTLS_CID
bool "DTLS Connection Identifier support"
default y if MBEDTLS_SSL_DTLS_CONNECTION_ID
help
Request TLS stack to enable DTLS Connection identifier. This requires stack that support it
and actual effect depends on the target server as well.

config LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
bool "Bootstrap support"
help
Expand Down
12 changes: 12 additions & 0 deletions subsys/net/lib/lwm2m/lwm2m_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,18 @@ int lwm2m_set_default_sockopt(struct lwm2m_ctx *ctx)
return ret;
}
}
if (IS_ENABLED(CONFIG_LWM2M_DTLS_CID)) {
/* Enable CID */
int cid = TLS_DTLS_CID_ENABLED;

ret = zsock_setsockopt(ctx->sock_fd, SOL_TLS, TLS_DTLS_CID, &cid,
sizeof(cid));
if (ret) {
ret = -errno;
LOG_ERR("Failed to enable TLS_DTLS_CID: %d", ret);
/* Not fatal, continue. */
}
}

if (ctx->hostname_verify && (ctx->desthostname != NULL)) {
/** store character at len position */
Expand Down

0 comments on commit 8cfede8

Please sign in to comment.