net: mqtt: Add support for TLS option TLS_CERT_NOCOPY

Add an option in MQTT client context to take advantage of the
"TLS_CERT_NOCOPY" option when using  TLS socket transport.

Signed-off-by: Lucas Dietrich <ld.adecy@gmail.com>
This commit is contained in:
Lucas Dietrich 2021-11-19 09:46:33 +01:00 committed by Anas Nashif
commit 0a0e9079c3
2 changed files with 12 additions and 0 deletions

View file

@ -354,6 +354,9 @@ struct mqtt_sec_config {
* May be NULL to skip hostname verification. * May be NULL to skip hostname verification.
*/ */
const char *hostname; const char *hostname;
/** Indicates the preference for copying certificates to the heap. */
int cert_nocopy;
}; };
/** @brief MQTT transport type. */ /** @brief MQTT transport type. */

View file

@ -78,6 +78,15 @@ int mqtt_client_tls_connect(struct mqtt_client *client)
} }
} }
if (tls_config->cert_nocopy != TLS_CERT_NOCOPY_NONE) {
ret = zsock_setsockopt(client->transport.tls.sock, SOL_TLS,
TLS_CERT_NOCOPY, &tls_config->cert_nocopy,
sizeof(tls_config->cert_nocopy));
if (ret < 0) {
goto error;
}
}
size_t peer_addr_size = sizeof(struct sockaddr_in6); size_t peer_addr_size = sizeof(struct sockaddr_in6);
if (broker->sa_family == AF_INET) { if (broker->sa_family == AF_INET) {