From 6807d75e16a0ca468e621c3c97f053db3682b841 Mon Sep 17 00:00:00 2001 From: Benjamin Bigler Date: Tue, 29 Mar 2022 07:41:56 +0200 Subject: [PATCH] net: lwm2m: Fix TLS_HOSTNAME is always set LWM2M Client Sample with DTLS enabled fails because TLS_HOSTNAME is set but MBEDTLS_X509_CRT_PARSE_C is disabled which leads to error 'net_lwm2m_engine: Failed to set TLS_HOSTNAME option: 109' Add new field hostname_verify to let the application decide if hostname should be checked. Signed-off-by: Benjamin Bigler --- include/net/lwm2m.h | 1 + subsys/net/lib/lwm2m/lwm2m_engine.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/net/lwm2m.h b/include/net/lwm2m.h index c2cf1fbfb5a..cf40b9f0115 100644 --- a/include/net/lwm2m.h +++ b/include/net/lwm2m.h @@ -137,6 +137,7 @@ struct lwm2m_ctx { */ char *desthostname; uint16_t desthostnamelen; + bool hostname_verify; /** Client can set load_credentials function as a way of overriding * the default behavior of load_tls_credential() in lwm2m_engine.c diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 64d448469f2..1221f258937 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -5642,7 +5642,7 @@ int lwm2m_socket_start(struct lwm2m_ctx *client_ctx) return -errno; } - if (client_ctx->desthostname != NULL) { + if (client_ctx->hostname_verify && (client_ctx->desthostname != NULL)) { /** store character at len position */ tmp = client_ctx->desthostname[client_ctx->desthostnamelen];