# TLS/SSL encrypt for MQTT

**URL:** https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035
**Category:** General
**Created:** [26 June 2020 15:22 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035 "2020-06-26T15:22:00Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [26 June 2020 15:22 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/1 "2020-06-26T15:22:00Z")

</div>

Is this the right way to encrypt the mqqt node via TLS/SSL?  
[https://groups.google.com/forum/#!topic/node-red/vu0Hrc2VPLk](https://groups.google.com/forum/#!topic/node-red/vu0Hrc2VPLk)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [26 June 2020 21:19 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/2 "2020-06-26T21:19:56Z")

</div>

I think that there was an extensive thread on this not so long back.

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [27 June 2020 13:23 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/3 "2020-06-27T13:23:25Z")

</div>

As far as i understand i have to use open-ssl to generate self-signed certificate, and with it to gain a number of files, three of which I have to configure in the tls-config, it is correct ?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [27 June 2020 13:42 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/4 "2020-06-27T13:42:40Z")

</div>

> [@Martin10](#):
>
> i have to use

No, there are many ways to get certificates. Because many libraries and applications no longer trust self-signed certs without loading a suitable trusted root cert as well, I can be easier to use Let's Encrypt to generate certs instead. I use the `acme.sh` shell script to generate a couple of different wild-card, multi-domain certificates that I then use on various devices and services. The script is run on a Linux host via CRON so that it always updates in time. Someone else recently worked on a custom node to try and do something similar.

You will want to look for the other thread about setting up TLS on MQTT correctly, I seem to remember that there were some complexities.

One other thing. I assume that you might be wanting to do this because you want to allow external access to your MQTT broker? If so, you will also want to enforce authenticated connections. You might also consider whether you want \>1 broker so that you can have the more sensitive topics more protected and use an edge broker for talking to the outside world. You can bridge brokers and enforce limited topic exchanges so you can build something quite secure if needed.

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [27 June 2020 15:25 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/5 "2020-06-27T15:25:38Z")

</div>

I just looking for the easiest way to secure the sensor data i sent to thingspeak via mqtt protocol.

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [27 June 2020 17:04 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/6 "2020-06-27T17:04:43Z")

</div>

Any help?

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [28 June 2020 08:30 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/7 "2020-06-28T08:30:19Z")

</div>

Any help?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [28 June 2020 08:52 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/8 "2020-06-28T08:52:14Z")

</div>

@Martin10 the thread you linked to was for setting up an MQTT Broker with certificates. That is not what you want to do.

I don't know ThingSpeak, but a quick search suggests they only support SSL/TLS over MQTT/Websocket connections.

So in the server field, change it to begin `wss://mqtt.thingspeak.com` - this will tell the client to do WebSockets over ssl.

I don't _think_ you need to do anything else... but I haven't tried it myself.

Ultimately, its a case of reading the docs, trying it out and seeing where you get to.

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [28 June 2020 14:50 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/9 "2020-06-28T14:50:47Z")

</div>

I try your advice and also the examples from hire ([https://www.mathworks.com/help/thingspeak/mqtt-basics.html](https://www.mathworks.com/help/thingspeak/mqtt-basics.html))

### MQTT Client Configuration

ThingSpeak has an MQTT broker at the URL `mqtt.thingspeak.com` . Configure your MQTT client to communicate with the ThingSpeak MQTT broker based on one of the following options:

| Port | Connection Type | Encryption |
| --- | --- | --- |
| 1883 | TCP | None |
| 8883 | TCP | TLS/SSL |
| 80 | WebSocket | None |
| 443 | WebSocket | TLS/SSL |

But my mqtt client in node-red always is disconnected

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 June 2020 16:14 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/10 "2020-06-28T16:14:16Z")

</div>

Show us how you have configured the MQTT node

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [28 June 2020 17:17 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/11 "2020-06-28T17:17:08Z")

</div>

![2020-06-28-200450_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d28cefd2f0b93d9ee87aa85e3d67031d47f35eb5.png)  
 ![2020-06-28-201200_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/670c21798d385535d5b721baa22c02cc14bcddf4.png)  
 ![2020-06-28-201303_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/3137fa58e13a798b2d37ddeb89d82a28b1c8725c.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 June 2020 17:27 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/12 "2020-06-28T17:27:05Z")

</div>

I don't understand, your broker dialog is missing the security tab. It should look like this

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d551ff228720e864c3e741a63ea24b75b2800f9f.png)

I have no idea why the tabs might be missing  
What version of node-red are you using? In fact please post the startup log from starting node-red in a terminal. It should start with Welcome to node-red.

Also what hardware and operating system are you using?

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [28 June 2020 17:54 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/13 "2020-06-28T17:54:12Z")

</div>

The tab missing because i scroll down. Not sure about the version. I use it on RPI 4 and raspbian

![2020-06-28-204955_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8f4d1f7260d054a322122a869e4545a7d0127f6c.png)

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [28 June 2020 17:56 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/14 "2020-06-28T17:56:25Z")

</div>

Have you clicked the 'enable tls' option? It isn't enabled in any of the screen shots you have shared. Given you want to use TLS, I would have started with that.

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [28 June 2020 18:04 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/15 "2020-06-28T18:04:19Z")

</div>

Yes i try, but nothing

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [28 June 2020 18:09 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/16 "2020-06-28T18:09:29Z")

</div>

> [@Martin10](#):
>
> Yes i try

After clicking the Enable button, did you also add a new tls-config node?

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [28 June 2020 18:20 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/17 "2020-06-28T18:20:32Z")

</div>

tls-config node ?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [28 June 2020 18:24 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/18 "2020-06-28T18:24:49Z")

</div>

tick Enable ssl/tls  
then add a tls config  
 ![86KuI1GIxK](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7aeb5282cbdf08096001a475b97ab8282e5ecd96.gif)

---

<div class="post-metadata">

### Author: ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)
#### Post date: [28 June 2020 18:30 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/19 "2020-06-28T18:30:12Z")

</div>

Of course I am. I thought there was some other node, like mqttssl

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 June 2020 18:47 UTC](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035/20 "2020-06-28T18:47:03Z")

</div>

I don't think he does want to use TLS, just wss.  
But have you entered the API key and user name on the security tab?

[Next page](https://discourse.nodered.org/t/tls-ssl-encrypt-for-mqtt/29035.md?page=2)
