<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/44921/nrf9160-tls-and-mqtt</link><description>Hello guys, 
 We are working on the project and using DK 9160. We want to use LTE Cat M1 connection, mqtt tls and we need full functionality embed tls. We started with demo based on the BSD_socket library and as we understood contains partly tls security</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 14 Apr 2020 09:29:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/44921/nrf9160-tls-and-mqtt" /><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/244371?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2020 09:29:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48287071-ffd8-4fcc-b52c-c949f9896064</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Please check out the tutorial:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/cellular-iot-guides/b/software-and-protocols/posts/enabling-and-testing-tls-in-mqtt_5f00_simple"&gt;https://devzone.nordicsemi.com/nordic/cellular-iot-guides/b/software-and-protocols/posts/enabling-and-testing-tls-in-mqtt_5f00_simple&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you have any issues please make a new case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/244275?ContentTypeID=1</link><pubDate>Mon, 13 Apr 2020 07:47:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00dae8d1-fcf6-4390-8ca7-18e34b82d142</guid><dc:creator>Shekhar Suthar</dc:creator><description>&lt;p&gt;hello &lt;a href="https://devzone.nordicsemi.com/members/stevenlin"&gt;stevenlin&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m working on same thing so I want to know that, Did you get success in that application because I&amp;#39;m not getting some issues in connection with Azure&amp;nbsp; by certificates.&lt;/p&gt;
&lt;p&gt;May be you can help me out &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/213664?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2019 13:00:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9faba3ee-2367-4c9f-9b15-989ba00c8415</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Steven,&lt;/p&gt;
&lt;p&gt;Please make a new thread&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/211069?ContentTypeID=1</link><pubDate>Sun, 22 Sep 2019 12:04:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa971fb2-fd84-48f9-99a4-b12c2ace65e3</guid><dc:creator>stevenlin</dc:creator><description>&lt;p&gt;hi all,&lt;/p&gt;
&lt;p&gt;i have same issue about it .&lt;/p&gt;
&lt;p&gt;now , i ref &lt;a href="https://github.com/joakimtoe/fw-nrfconnect-nrf/commit/36532a8ca60bf7139a988b5cbb4e6cb47948a9fa"&gt;https://github.com/joakimtoe/fw-nrfconnect-nrf/commit/36532a8ca60bf7139a988b5cbb4e6cb47948a9fa&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;add tls mqtt . it can&amp;#39;t connect broker. (that return -45)&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;SPM: NS image at 0xc000&lt;br /&gt;SPM: NS MSP at 0x20025bc0&lt;br /&gt;SPM: NS reset vector at 0xe56d&lt;br /&gt;SPM: prepare to jump to Non-Secure image.&lt;br /&gt;***** Booting Zephyr OS build v1.14.99-ncs3-snapshot2-1266-g8711cfd5d348 *****&lt;br /&gt;The MQTT simple sample started&lt;br /&gt;nrf_inbuilt_key_delete(16842753, 0) =&amp;gt; result=0&lt;br /&gt;nrf_inbuilt_key_delete(16842753, 1) =&amp;gt; result=0&lt;br /&gt;nrf_inbuilt_key_delete(16842753, 2) =&amp;gt; result=0&lt;br /&gt;nrf_inbuilt_key_write =&amp;gt; result=0&lt;br /&gt;nrf_inbuilt_key_write =&amp;gt; result=0&lt;br /&gt;nrf_inbuilt_key_write =&amp;gt; result=0&lt;br /&gt;LTE Link Connecting ...&lt;br /&gt;LTE Link Connected!&lt;br /&gt;IPv4 Address found 5.196.95.208&lt;br /&gt;ERROR: mqtt_connect -45&lt;/p&gt;
&lt;p&gt;main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
#include &amp;quot;nrf_inbuilt_key.h&amp;quot;


//#if !defined(CONFIG_USE_PROVISIONED_CERTIFICATES)
#include &amp;quot;certificates.h&amp;quot;
//#endif


#define CONFIG_CLOUD_CERT_SEC_TAG 16842753
static int provision_certificates(void)
{
	{
		int err;

		/* Delete certificates */
		nrf_sec_tag_t sec_tag = CONFIG_CLOUD_CERT_SEC_TAG;

		for (nrf_key_mgnt_cred_type_t type = 0; type &amp;lt; 3; type++) {
			err = nrf_inbuilt_key_delete(sec_tag, type);
			printk(&amp;quot;nrf_inbuilt_key_delete(%u, %d) =&amp;gt; result=%d\n&amp;quot;,
				sec_tag, type, err);
		}

		/* Provision CA Certificate. */
		err = nrf_inbuilt_key_write(CONFIG_CLOUD_CERT_SEC_TAG,
					NRF_KEY_MGMT_CRED_TYPE_CA_CHAIN,
					CLOUD_CA_CERTIFICATE,
					strlen(CLOUD_CA_CERTIFICATE));
		printk(&amp;quot;nrf_inbuilt_key_write =&amp;gt; result=%d\n&amp;quot;, err);
		if (err) {
			printk(&amp;quot;CLOUD_CA_CERTIFICATE err: %d&amp;quot;, err);
			return err;
		}

		/* Provision Private Certificate. */
		err = nrf_inbuilt_key_write(
			CONFIG_CLOUD_CERT_SEC_TAG,
			NRF_KEY_MGMT_CRED_TYPE_PRIVATE_CERT,
			CLOUD_CLIENT_PRIVATE_KEY,
			strlen(CLOUD_CLIENT_PRIVATE_KEY));
		printk(&amp;quot;nrf_inbuilt_key_write =&amp;gt; result=%d\n&amp;quot;, err);
		if (err) {
			printk(&amp;quot;NRF_CLOUD_CLIENT_PRIVATE_KEY err: %d&amp;quot;, err);
			return err;
		}

		/* Provision Public Certificate. */
		err = nrf_inbuilt_key_write(
			CONFIG_CLOUD_CERT_SEC_TAG,
			NRF_KEY_MGMT_CRED_TYPE_PUBLIC_CERT,
				 CLOUD_CLIENT_PUBLIC_CERTIFICATE,
				 strlen(CLOUD_CLIENT_PUBLIC_CERTIFICATE));
		printk(&amp;quot;nrf_inbuilt_key_write =&amp;gt; result=%d\n&amp;quot;, err);
		if (err) {
			printk(&amp;quot;CLOUD_CLIENT_PUBLIC_CERTIFICATE err: %d&amp;quot;,
				err);
			return err;
		}
	}
	return 0;
}

/**@brief Initialize the file descriptor structure used by poll.
 */
static int fds_init(struct mqtt_client *c)
{

    fds.fd = c-&amp;gt;transport.tls.sock;

	fds.events = POLLIN;

	return 0;
}


void main(void)
{
	int err;

	printk(&amp;quot;The MQTT simple sample started\n&amp;quot;);
	provision_certificates();
	modem_configure();

	client_init(&amp;amp;client);

	err = mqtt_connect(&amp;amp;client);
	if (err != 0) {
		printk(&amp;quot;ERROR: mqtt_connect %d\n&amp;quot;, err);
		return;
	}

	err = fds_init(&amp;amp;client);
	if (err != 0) {
		printk(&amp;quot;ERROR: fds_init %d\n&amp;quot;, err);
		return;
	}
...
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;certificates.h&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
#define CLOUD_CLIENT_PRIVATE_KEY \
&amp;quot;-----BEGIN RSA PRIVATE KEY-----\n&amp;quot; \
  &amp;quot;MIIEogIBAAKCAQEArjslJVMR6y7OQf+diPBE546zw9HO3pSxIbC1rN5R/w8mmoHi\n&amp;quot;\
  .....
2kYGR4ow8bWDL3xmThnmCyIRV7bJNqKvzU3U9hArV8=\n&amp;quot;\
&amp;quot;-----END RSA PRIVATE KEY-----\n&amp;quot;

#define CLOUD_CLIENT_PUBLIC_CERTIFICATE \
&amp;quot;-----BEGIN PUBLIC KEY-----\n&amp;quot; \
  &amp;quot;MIIC7zCCAligAwIBAgIBADANBgkqhkiG9w0BAQsFADCBkDELMAkGA1UEBhMCR0Ix\n&amp;quot;\
  &amp;quot;FzAVBgNVBAgMDlVuaXRlZCBLaW5nZG9tMQ4wDAYDVQQHDAVEZXJieTESMBAGA1UE\n&amp;quot;\
.....
  &amp;quot;mgb7Y/aMXqTsICCzkL8qzEDb2VQGZU0Gd/LScR6Za1oeA7s=\n&amp;quot;\
&amp;quot;-----END PUBLIC KEY-----\n&amp;quot;

#define CLOUD_CA_CERTIFICATE \
&amp;quot;-----BEGIN CERTIFICATE-----\n&amp;quot; \
  &amp;quot;MIIC8DCCAlmgAwIBAgIJAOD63PlXjJi8MA0GCSqGSIb3DQEBBQUAMIGQMQswCQYD\n&amp;quot;\
 ....
  &amp;quot;1ZgKJc2zbSQ9fCPxt2W3mdVav66c6fsb7els2W2Iz7gERJSX\n&amp;quot;\
&amp;quot;-----END CERTIFICATE-----\n&amp;quot;
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/177155?ContentTypeID=1</link><pubDate>Tue, 19 Mar 2019 17:07:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3c45242-708c-4fde-af1f-94c9c9286e52</guid><dc:creator>jbrzozoski</dc:creator><description>&lt;p&gt;Yes, i definitely had a TLS connection.&lt;/p&gt;
&lt;p&gt;It requires more code changes than just turning on that one config.&amp;nbsp; I also had to change the configured port to 8883, and had to modify the client_init function&amp;nbsp;like this:&amp;nbsp;&lt;span&gt;&lt;/span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if defined(CONFIG_MQTT_LIB_TLS)
   client-&amp;gt;transport.type = MQTT_TRANSPORT_SECURE;
   client-&amp;gt;transport.tls.config.peer_verify = 0;
   client-&amp;gt;transport.tls.config.cipher_count = 0;
   client-&amp;gt;transport.tls.config.cipher_list = NULL;
   client-&amp;gt;transport.tls.config.sec_tag_count = 0;
   client-&amp;gt;transport.tls.config.seg_tag_list = NULL;
   client-&amp;gt;transport.tls.config.hostname = NULL;
#else
   client-&amp;gt;transport.type = MQTT_TRANSPORT_NON_SECURE;
#endif&lt;/pre&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/177097?ContentTypeID=1</link><pubDate>Tue, 19 Mar 2019 14:44:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:062b4809-127f-4452-87af-74dcb0373d76</guid><dc:creator>DenisAks</dc:creator><description>&lt;p&gt;I see that using CONFIG_MQTT_LIB_TLS define enable support TLS sockets in MQTT, but the TLS does not realize in MQTT library and you need use zephyr TLS library or Nordic BSD sockets lib.&lt;br /&gt;I saw examples MQTT with tls from zephyr for other boards and they used mbedTLS library.&lt;br /&gt;&lt;br /&gt;Are you sure that you used MQTT TLS connection?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/176743?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 13:57:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b8d3d06-973e-4483-b990-3342e533a55f</guid><dc:creator>jbrzozoski</dc:creator><description>&lt;p&gt;I have been able to do MQTT over TLS using a config option directly related to the Zephyr MQTT library.&amp;nbsp; In my prj.conf I have:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=y
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I have no other TLS libraries (explicitly) enabled.&amp;nbsp; I think that MQTT_LIB_TLS may indirectly enable a TLS library, but I never reference or call it from any of my code directly.&amp;nbsp; My code was originally based on the mqtt_simple application which you can find here:&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/samples/nrf9160/mqtt_simple"&gt;https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/samples/nrf9160/mqtt_simple&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Be aware that there are multiple MQTT libraries between the zephyr and nrf code trees, and some of them are near clones of each other that should hopefully be converging upstream soon.&amp;nbsp; The one I have used successfully is the one you can enable with that specific config option, with the source code located in&amp;nbsp;zephyr/subsys/net/lib/mqtt_sock&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/176615?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 08:15:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba6ddc91-2aec-439c-adba-13201205fa7e</guid><dc:creator>DenisAks</dc:creator><description>&lt;p&gt;Now only for MQTT.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 TLS and MQTT</title><link>https://devzone.nordicsemi.com/thread/176522?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2019 20:36:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b64d63c-cc1a-4c29-9628-ef9d8b86df64</guid><dc:creator>jbrzozoski</dc:creator><description>&lt;p&gt;Do you want TLS for the MQTT connection or a different connection?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>