Skip to content

Commit 89f886b

Browse files
Musilahfelixgateru
andauthored
SMQ-227 - Docs for mTLS messaging (#228)
* add mtls docs Signed-off-by: Musilah <[email protected]> * add protocols with mtls Signed-off-by: Musilah <[email protected]> * fix lint Signed-off-by: Musilah <[email protected]> * refactor: remove CoAP DTLS docs Signed-off-by: Felix Gateru <[email protected]> --------- Signed-off-by: Musilah <[email protected]> Signed-off-by: Felix Gateru <[email protected]> Co-authored-by: Felix Gateru <[email protected]>
1 parent b2deae7 commit 89f886b

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

docs/messaging.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ to every command.
3939

4040
## CoAP
4141

42-
CoAP adapter implements CoAP protocol using underlying UDP and according to [RFC 7252][rfc7252]. To send and receive messages over CoAP, you can use [CoAP CLI][coap-cli]. To set the add-on, please follow the installation instructions provided [here][coap-cli].
42+
CoAP adapter implements CoAP protocol using underlying UDP and according to [RFC 7252][rfc7252]. To send and receive messages over CoAP, you can use [CoAP CLI][coap-cli]. To set the add-on, please follow the installation instructions provided [in this section][coap-cli].
4343

4444
Examples:
4545

@@ -250,6 +250,87 @@ client = new Paho.MQTT.Client(loc.hostname, Number(loc.port), "clientId");
250250
client.connect({ onSuccess: onConnect });
251251
```
252252

253+
## mTLS Messaging
254+
255+
SuperMQ supports mutual TLS (mTLS) to enhance security by requiring both clients and servers to authenticate each other using certificates.
256+
This ensures that only authorized clients can connect and communicate with the server.
257+
It is designed to handle high-throughput environments.
258+
Core components are modular, making it easy to plug in custom modules or replace existing ones. Extendable to add new IoT protocols, middleware, and features as needed.
259+
260+
### Certificate Setup
261+
262+
To enable mTLS, you'll need the following certificates:
263+
264+
- **CA Certificate (`ca.crt`)**: The Certificate Authority's certificate used to sign both server and client certificates.
265+
- **Server Certificate (`server.crt`) and Private Key (`server.key`)**: Used by the server to authenticate itself to clients. These will be used by SuperMQ.
266+
- **Client Certificate (`client.crt`) and Private Key (`client.key`)**: Used by the client to authenticate itself to the server.
267+
268+
Ensure that these certificates are properly generated and signed by a trusted CA.
269+
270+
### HTTP with mTLS
271+
272+
By default, HTTP messages can be sent without any encryption or certificate verification:
273+
274+
```bash
275+
curl -s -S -i -X POST -H "Content-Type: application/senml+json" -H "Authorization: Client <client_secret>" https://localhost/http/m/<domain_id>/c/<channel_id> -d '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
276+
```
277+
278+
But with mTLS, clients must present their certificate during the TLS handshake. This ensures both server and client are authenticated using trusted certificates.
279+
280+
```bash
281+
curl -s -S -i --cacert docker/ssl/certs/ca.crt --cert docker/ssl/certs/client.crt --key docker/ssl/certs/client.key -X POST -H "Content-Type: application/senml+json" -H "Authorization: Client <client_secret>" https://localhost/http/m/<domain_id>/c/<channel_id> -d '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
282+
```
283+
284+
### HTTP with TLS
285+
286+
A user can also send messages with just the TLS support (server authentication only) and just a CA certificate using the command:
287+
288+
```bash
289+
curl -s -S -i --cacert docker/ssl/certs/ca.crt -X POST -H "Content-Type: application/senml+json" -H "Authorization: Client <client_secret>" https://localhost/http/m/<domain_id>/c/<channel_id> -d '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
290+
```
291+
292+
### MQTT with TLS
293+
294+
You can connect over plain MQTT (port `1883`) without any encryption or certificate validation:
295+
296+
```bash
297+
mosquitto_pub -u <client_id> -P <client_secret> -t m/<domain_id>/c/<channel_id> -h localhost -p 1883 -m '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
298+
```
299+
300+
To connect securely over TLS using the same port `8883` and valisate the server certificate with a CA file:
301+
302+
```bash
303+
mosquitto_pub --cafile docker/ssl/certs/ca.crt -u <client_id> -P <client_secret> -t m/<domain_id>/c/<channel_id> -h localhost -p 1883 -m '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
304+
```
305+
306+
This ensures encrypted communication and server identity verification.
307+
308+
### MQTT with mTLS
309+
310+
Provide the client certificate and key along with the CA certificate to enable mutual authentication:
311+
312+
```bash
313+
mosquitto_pub --cafile docker/ssl/certs/ca.crt --cert docker/ssl/certs/client.crt --key docker/ssl/certs/client.key -u <client_id> -P <client_secret> -t m/<domain_id>/c/<channel_id> -h localhost -p 1883 -m '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
314+
```
315+
316+
This is the most secure mode — both client and server verify each other.
317+
318+
### MQTT Subscription with mTLS
319+
320+
To subscribe to the same channel using mTLS:
321+
322+
```bash
323+
mosquitto_sub \
324+
--cafile docker/ssl/certs/ca.crt \
325+
--cert docker/ssl/certs/client.crt \
326+
--key docker/ssl/certs/client.key \
327+
-h localhost -p 8883 \
328+
-u <client_id> -P <client_secret> \
329+
-t m/<domain_id>/c/<channel_id
330+
```
331+
332+
### WebSocket without TLS
333+
253334
## Subtopics
254335

255336
In order to use subtopics and give more meaning to your pub/sub channel, you can simply add any suffix to base `/m/<domain_id>/c/<channel_id>` topic.

0 commit comments

Comments
 (0)