Skip to content

Commit c74e382

Browse files
committed
add protocols with mtls
Signed-off-by: Musilah <[email protected]>
1 parent 399499d commit c74e382

File tree

1 file changed

+91
-6
lines changed

1 file changed

+91
-6
lines changed

docs/messaging.md

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,26 +269,111 @@ Ensure that these certificates are properly generated and signed by a trusted CA
269269

270270
### HTTP with mTLS
271271

272-
We currently use _HTTP_ without mTLS support.
272+
By default, HTTP messages can be sent without any encryption or certificate verification:
273273

274274
```bash
275-
curl -sSiX POST "${protocol}://${host}:${port}/${path}" -H "content-type:${content}" -H "Authorization:TOKEN" -d "${message}"
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}]'
276276
```
277277

278-
But with mTLS, clients must present their certificate during the TLS handshake.
278+
But with mTLS, clients must present their certificate during the TLS handshake. This ensures both server and client are authenticated using trusted certificates.
279279

280280
```bash
281-
curl -sSiX POST "${protocol}://${host}:${port}/${path}" -H "content-type:${content}" -H "Authorization:TOKEN" -d "${message}" --cacert $cafile --cert $certfile --key $keyfile
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}]'
282282
```
283283

284284
### HTTP with TLS
285285

286-
A user can also send messages with just the TLS support and just a CAA certificate using the command:
286+
A user can also send messages with just the TLS support (server authentication only) and just a CA certificate using the command:
287287

288288
```bash
289-
curl -sSiX POST "${protocol}://${host}:${port}/${path}" -H "content-type:${content}" -H "Authorization:TOKEN" -d "${message}" --cacert $cafile
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}]'
290290
```
291291

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+
### CoAP without TLS
333+
334+
To send a message using plain CoAP (UDP) without any certificate validation:
335+
336+
```bash
337+
coap-cli post m/<domain_id>/c/<channel_id>/subtopic -auth <client_secret> -d "hello world"
338+
```
339+
340+
To subscribe to messages via CoAP observe:
341+
342+
```bash
343+
coap-cli get m/<domain_id>/c/<channel_id>/subtopic -auth <client_secret> -o
344+
```
345+
346+
### CoAP with TLS
347+
348+
To enable DTLS with server authentication only which encrypts traffic and ensuers the CoAP server is trusted:
349+
350+
```bash
351+
coap-cli post m/<domain_id>/c/<channel_id>/subtopic -auth <client_secret> -d "hello world" --ca docker/ssl/certs/ca.crt
352+
```
353+
354+
### CoAP with mTLS
355+
356+
For full mTLS, add the client certificate and private key to the DTLS handshake:
357+
358+
```bash
359+
coap-cli post m/<domain_id>/c/<channel_id>/subtopic -auth <client_secret> -d "hello world" --ca docker/ssl/certs/ca.crt --cert docker/ssl/certs/client.crt --key docker/ssl/certs/client.key
360+
```
361+
362+
To observe with mTLS enabled:
363+
364+
```bash
365+
coap-cli get m/<domain_id>/c/<channel_id>/subtopic \
366+
-auth <client_secret> \
367+
-o \
368+
--ca docker/ssl/certs/ca.crt \
369+
--cert docker/ssl/certs/client.crt \
370+
--key docker/ssl/certs/client.key
371+
```
372+
373+
This ensures both server and client identities are verified via DTLS.
374+
375+
### WebSocket without TLS
376+
292377
## Subtopics
293378

294379
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)