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 <benjamin.bigler@securiton.ch>
This commit is contained in:
Benjamin Bigler 2022-03-29 07:41:56 +02:00 committed by Maureen Helm
commit 6807d75e16
2 changed files with 2 additions and 1 deletions

View file

@ -137,6 +137,7 @@ struct lwm2m_ctx {
*/ */
char *desthostname; char *desthostname;
uint16_t desthostnamelen; uint16_t desthostnamelen;
bool hostname_verify;
/** Client can set load_credentials function as a way of overriding /** Client can set load_credentials function as a way of overriding
* the default behavior of load_tls_credential() in lwm2m_engine.c * the default behavior of load_tls_credential() in lwm2m_engine.c

View file

@ -5642,7 +5642,7 @@ int lwm2m_socket_start(struct lwm2m_ctx *client_ctx)
return -errno; return -errno;
} }
if (client_ctx->desthostname != NULL) { if (client_ctx->hostname_verify && (client_ctx->desthostname != NULL)) {
/** store character at len position */ /** store character at len position */
tmp = client_ctx->desthostname[client_ctx->desthostnamelen]; tmp = client_ctx->desthostname[client_ctx->desthostnamelen];