This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

mqtt_connect error 45 when using secure transport

I have gotten mqtt_simple working with iot.eclipse.org:1883. I am now trying to adapt it to use TLS. From other questions I have made the following changes:

diff --git a/samples/nrf9160/mqtt_simple/src/main.c b/samples/nrf9160/mqtt_simple/src/main.c
index 779ee15..32afae5 100644
--- a/samples/nrf9160/mqtt_simple/src/main.c
+++ b/samples/nrf9160/mqtt_simple/src/main.c
@@ -288,7 +288,14 @@ static void client_init(struct mqtt_client *client)
     client->tx_buf_size = sizeof(tx_buffer);
 
     /* MQTT transport configuration */
-    client->transport.type = MQTT_TRANSPORT_NON_SECURE;
+    client->transport.type = MQTT_TRANSPORT_SECURE;
+    struct mqtt_sec_config *tls_config = &client->transport.tls.config;
+    tls_config->peer_verify = 0;
+    tls_config->cipher_list = 0;
+    tls_config->cipher_count = 0;
+    tls_config->sec_tag_list = 0;
+    tls_config->sec_tag_count = 0;
+    tls_config->hostname = CONFIG_MQTT_BROKER_HOSTNAME;
 }
 
 /**@brief Initialize the file descriptor structure used by poll.

and set CONFIG_MQTT_LIB_TLS. When I try I get error -45 from mqtt_connect. I get the same if I set peer_verify = 2.

Software versions:

nrf c1939d963fe2c18013ffb8de0bd8f6fc1d91724d
modem 0.6.8-30
  • Minor bump to the conversation: after updating my NRF checkout to the v0.4.0-rc1 tag, using 'west update' to bring everything else up to date, and a bit more development on my application, I am able to use peer_verify=2 with a hostname set in the TLS config.

    I'm uncertain if it works now because of the new NRF code base, or the fact that I have also setup a security tag with SSL certificates (both server cert and client key/cert pair).  For an example of how to setup a security tag, dig through the NRF libraries for CONFIG_NRF_CLOUD_PROVISION_CERTIFICATES.  In particular, I (only once) used code based on the block that uses nrf_inbuilt_key_write to store the certificates permanently in the modem and can now use that security tag in my TLS config without having to reload or provision them again.

Related