Add labs
This commit is contained in:
127
01-basics/lab01/lab.txt
Normal file
127
01-basics/lab01/lab.txt
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
= Installation und Starten eines Mosquitto Brokers
|
||||||
|
|
||||||
|
Nutzen Sie eine der folgenden Methoden, um
|
||||||
|
den Mosquitto Broker lokal zu installieren und zu starten.
|
||||||
|
|
||||||
|
Lokales Arbeiten ist Teil der Schulung und weitere Labs bauen darauf auf.
|
||||||
|
|
||||||
|
Container Technologie ist ein guter Weg, um reproduzierbare Ergebnisse
|
||||||
|
zu erhalten und komfortabel zu arbeiten.
|
||||||
|
|
||||||
|
Methoden:
|
||||||
|
|
||||||
|
- Lokale Installation
|
||||||
|
- Docker Container
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Lokale Installation
|
||||||
|
|
||||||
|
== Windows
|
||||||
|
|
||||||
|
Gehen Sie auf die offizielle Seite von Eclipse Mosquitto und
|
||||||
|
laden Sie den neusten 64 Bit Installer herunter.
|
||||||
|
|
||||||
|
https://mosquitto.org/files/binary/win64/
|
||||||
|
|
||||||
|
Führen Sie die Installationsdatei aus und befolgen Sie den Anweisungen.
|
||||||
|
|
||||||
|
Merken Sie sich das Installationsverzeichnis.
|
||||||
|
|
||||||
|
Standardmäßig wird Mosquitto unter 'C:\Program Files\Mosquitto'
|
||||||
|
installiert.
|
||||||
|
|
||||||
|
Starten Sie eine Kommandozeile und navigieren Sie in das
|
||||||
|
Installationsverzeichnis von Mosquitto.
|
||||||
|
|
||||||
|
Installation abgeschlossen, weiter bei "Starten"
|
||||||
|
|
||||||
|
|
||||||
|
== Linux
|
||||||
|
|
||||||
|
Mosquitto wird nicht mehr als Binärpaket für Linux auf mosquitto.org angeboten.
|
||||||
|
Die Installationsmethode ist daher abhängig von der verwendeten Linux Distribution.
|
||||||
|
Das Beispiel nutzt Debian/Ubuntu/Armbian.
|
||||||
|
|
||||||
|
Zum Testen kann auch das in Docker ausprobiert werden
|
||||||
|
(wobei dann auch direkt ein Mosquiotto Container genutzt werden kann):
|
||||||
|
Dazu:
|
||||||
|
1) Ubuntu Container als "virtuelle Maschine" starten 2) darin die Kommandos ausführen
|
||||||
|
$ docker run --privileged --cgroupns=host --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:rw geerlingguy/docker-ubuntu2404-ansible
|
||||||
|
$ docker exec -it $(docker ps -q --latest) /bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
Fügen Sie das Mosquitto PPA APT Repository hinzu:
|
||||||
|
|
||||||
|
$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
|
||||||
|
$ sudo apt-get update
|
||||||
|
|
||||||
|
Installieren Sie nun Mosquitto:
|
||||||
|
|
||||||
|
$ sudo apt-get install mosquitto
|
||||||
|
|
||||||
|
Der Broker sollte automatisch als Service gestartet werden.
|
||||||
|
|
||||||
|
Um ihn manuell zu starten, und die Kommandozeile zu sehen, stoppen
|
||||||
|
Sie den Mosquitto Broker und starten Sie ihn erneut.
|
||||||
|
|
||||||
|
$ sudo systemctl stop mosquitto
|
||||||
|
# ggf. pruefen ("Active: inactive") mittels "sudo systemctl status mosquitto"
|
||||||
|
|
||||||
|
Installation abgeschlossen, weiter bei "Starten"
|
||||||
|
|
||||||
|
|
||||||
|
== MacOS
|
||||||
|
|
||||||
|
Installieren Sie den Mosquitto Broker über Brew.
|
||||||
|
|
||||||
|
$ brew install mosquitto
|
||||||
|
|
||||||
|
Installation abgeschlossen, weiter bei "Starten"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Starten des Mosquitto Brokers
|
||||||
|
|
||||||
|
Führen Sie den Befehl 'mosquitto -h' aus, um unterstützte Befehle von
|
||||||
|
Mosquitto zu sehen.
|
||||||
|
|
||||||
|
Führen Sie den Befehl 'mosquitto -v' aus um den Broker zu starten und
|
||||||
|
um die Aktivität des Brokers in der Kommandozeile mitzuverfolgen können.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Verwendung Docker
|
||||||
|
|
||||||
|
Da das offizielle Container Image von Mosquitto keine anonymen Verbindungen erlaubt,
|
||||||
|
wird eine Konfigurationdatei benötigt, die dann in den Docker Container eingebunden wird.
|
||||||
|
|
||||||
|
Erstellen Sie dazu eine Datei mit dem Namen 'mosquitto.conf' und folgendem Inhalt:
|
||||||
|
|
||||||
|
allow_anonymous true
|
||||||
|
listener 1883
|
||||||
|
|
||||||
|
|
||||||
|
Um den Mosquitto Broker als Docker Container zu starten führen Sie
|
||||||
|
folgenden Befehl im selben Verzeichnis, wie die Konfigurationsdatei aus:
|
||||||
|
|
||||||
|
$ docker run --rm -p 1883:1883 -v $PWD/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto
|
||||||
|
|
||||||
|
Diesel Befehl startet einen Container mit den Mosquitto Broker, verbindet
|
||||||
|
den Host Port 1883 mit den Port 1883 des Containers und bindet die
|
||||||
|
Konfigurationdatei an passender Stelle ein.
|
||||||
|
|
||||||
|
|
||||||
|
= Referenzen
|
||||||
|
|
||||||
|
Download Page von Mosquitto https://mosquitto.org/download/
|
||||||
|
|
||||||
|
Docker Desktop Installation https://docs.docker.com/desktop/
|
||||||
|
|
||||||
|
Docker Standalone Installation https://docs.docker.com/engine/install/
|
||||||
|
|
||||||
|
Docker Container Runtime für MacOS https://github.com/abiosoft/colima
|
||||||
|
|
||||||
|
Mosquitto Docker Container https://hub.docker.com/_/eclipse-mosquitto
|
||||||
2
01-basics/lab01/mosquitto.conf
Normal file
2
01-basics/lab01/mosquitto.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
7
01-basics/lab02/docker-compose.yml
Normal file
7
01-basics/lab02/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
30
01-basics/lab02/lab.txt
Normal file
30
01-basics/lab02/lab.txt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
= Docker Compose
|
||||||
|
|
||||||
|
Mittels docker-compose lassen sich auch komplexere Setups auf einfache Weise
|
||||||
|
reproduzierbar konfigurieren.
|
||||||
|
|
||||||
|
Erstellen Sie dazu eine 'docker-compose.yml' Datei mit folgendem Inhalt.
|
||||||
|
|
||||||
|
`
|
||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
|
`
|
||||||
|
|
||||||
|
Um den Container zu starten, verwenden Sie nun im selben Verzeichnis, wie
|
||||||
|
die Konfigurationsdatei 'docker-compose.yml', folgenden Befehl:
|
||||||
|
|
||||||
|
$ docker compose up
|
||||||
|
|
||||||
|
Stoppen erfolgt durch CTRL-C oder docker-compose down
|
||||||
|
|
||||||
|
$ docker compose down
|
||||||
|
|
||||||
|
|
||||||
|
= Referenzen
|
||||||
|
|
||||||
|
https://docs.docker.com/compose/
|
||||||
2
01-basics/lab02/mosquitto.conf
Normal file
2
01-basics/lab02/mosquitto.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
7
01-basics/lab03/docker-compose.yml
Normal file
7
01-basics/lab03/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
24
01-basics/lab03/lab.txt
Normal file
24
01-basics/lab03/lab.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
= Broker Zugriff mit cURL
|
||||||
|
|
||||||
|
Nutzen Sie cURL als einfachen Client, um sich mit Ihrem Broker
|
||||||
|
zu verbinden.
|
||||||
|
|
||||||
|
Verwenden Sie folgende Parameter:
|
||||||
|
|
||||||
|
* URL mqtt://localhost/\$SYS/broker/uptime (Zu beachten: Das Dollarzeichen
|
||||||
|
wird ggf. durch die Shell interpretiert. Enteder mit Backslash escapen
|
||||||
|
oder die gesamte URL in einfache Anführungszeichen setzen.)
|
||||||
|
* `--trace -` Detailausgabe der Verbindungsdaten auf stdout
|
||||||
|
* `--output -` Ausgabe auch von Binärdaten auf stdout erlauben
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Umsetzung:
|
||||||
|
|
||||||
|
$ curl --output - --trace - mqtt://localhost/\$SYS/broker/uptime
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Referenzen
|
||||||
|
|
||||||
|
https://curl.se/docs/mqtt.html
|
||||||
2
01-basics/lab03/mosquitto.conf
Normal file
2
01-basics/lab03/mosquitto.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
7
01-basics/lab04/docker-compose.yml
Normal file
7
01-basics/lab04/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
32
01-basics/lab04/lab.txt
Normal file
32
01-basics/lab04/lab.txt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
= Abbonnieren von Topics
|
||||||
|
|
||||||
|
Nutzen Sie mosquitto_sub als Client, lokal installiert (siehe lab01) oder als Container.
|
||||||
|
|
||||||
|
Bei Verwendung von Docker kann der Aufruf so aussehen:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub
|
||||||
|
|
||||||
|
bei lokaler Installation ist der Befehl lediglich
|
||||||
|
|
||||||
|
$ mosquitto_sub
|
||||||
|
|
||||||
|
Lassen Sie sich zunächst die Hilfe ausgeben:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub --help
|
||||||
|
|
||||||
|
|
||||||
|
Subscriben Sie auf das Topic `$SYS/broker/uptime` (Shell Escape beachten)
|
||||||
|
Beenden mit CTRL-C
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub --topic '$SYS/broker/uptime'
|
||||||
|
|
||||||
|
Testen Sie auch die Debug-Ausgabe
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub --topic '$SYS/broker/uptime' --debug
|
||||||
|
|
||||||
|
|
||||||
|
Können Sie mehrere Topics gleichzeitig abbonieren? Verwenden Sie '$SYS/broker/bytes/sent' .
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub --topic '$SYS/broker/uptime' --topic '$SYS/broker/bytes/sent'
|
||||||
|
|
||||||
2
01-basics/lab04/mosquitto.conf
Normal file
2
01-basics/lab04/mosquitto.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
7
01-basics/lab05/docker-compose.yml
Normal file
7
01-basics/lab05/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
36
01-basics/lab05/lab.txt
Normal file
36
01-basics/lab05/lab.txt
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
= Anpassung Konfiguration Mosquitto Broker
|
||||||
|
|
||||||
|
Lassen Sie ein mosquitto_sub mit Debug-Ausgabe laufen, z.B.
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub \
|
||||||
|
--debug --topic '$SYS/broker/uptime' --topic '$SYS/broker/bytes/sent'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Passen Sie die mosquitto.conf mit einem neuen Konfigrationswert an:
|
||||||
|
|
||||||
|
sys_interval 3
|
||||||
|
|
||||||
|
Stoppen (z.B. CTRL-C oder `docker compose stop`) und starten Sie Mosquitto mit
|
||||||
|
der neuen Konfiguration.
|
||||||
|
Beachten Sie die neuen CONNECT und SUBSCRIBE Pakete des Clients!
|
||||||
|
|
||||||
|
Passen Sie den Wert in der Konfigurationsdatei nochmals an.
|
||||||
|
Senden Sie ein HUP Signal an den Mosquitto Prozess.
|
||||||
|
(Sendet das Standard Unix Signal SIGHUP. Wird von vielen Diensten
|
||||||
|
(mosquitto, nginx, sshd ...) als Aufforderung gesehen, Konfiguration
|
||||||
|
neu zu laden ohne den Prozess zu beenden.)
|
||||||
|
|
||||||
|
$ docker compose exec mosquitto kill -HUP 1
|
||||||
|
|
||||||
|
Beachten Sie, dass es zu keiner Unterbrechung des Clients kommt.
|
||||||
|
|
||||||
|
|
||||||
|
= Referenzen
|
||||||
|
|
||||||
|
Mosquitto Konfigurationdatei https://mosquitto.org/man/mosquitto-conf-5.html
|
||||||
|
|
||||||
|
Docker Compose Installation https://docs.docker.com/compose/install/
|
||||||
|
|
||||||
|
Docker Volumes https://docs.docker.com/engine/storage/volumes/
|
||||||
4
01-basics/lab05/mosquitto.conf
Normal file
4
01-basics/lab05/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab06/docker-compose.yml
Normal file
7
01-basics/lab06/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
34
01-basics/lab06/lab.txt
Normal file
34
01-basics/lab06/lab.txt
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
= Publish
|
||||||
|
|
||||||
|
Nutzen Sie mosquitto_pub als Client und lassen sich zunächst die Hilfe ausgeben.
|
||||||
|
|
||||||
|
Sie können mosquitto_pub mit Docker ausführen:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub --help
|
||||||
|
|
||||||
|
Publizieren Sie auf das Topic `training`.
|
||||||
|
Verwenden Sie anschließend `mosquitto_sub` mit dem Topic, erhalten Sie die Nachricht?
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub --topic training --message "hello trion"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub --topic 'training' --debug
|
||||||
|
|
||||||
|
|
||||||
|
Starten Sie zuerst die Subscription und publizieren Sie danach in einem separaten Terminalfenster.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub --topic 'training' --debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub --topic training --message "hello trion"
|
||||||
|
|
||||||
|
|
||||||
|
Nutzen Sie mehrere Subscriber parallel, z.B. auch cURL
|
||||||
|
|
||||||
|
$ curl --output - --trace - mqtt://localhost/training
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Referenzen
|
||||||
|
|
||||||
|
mosquitto_sub https://mosquitto.org/man/mosquitto_sub-1.html
|
||||||
|
|
||||||
|
mosquitto_pub https://mosquitto.org/man/mosquitto_pub-1.html
|
||||||
4
01-basics/lab06/mosquitto.conf
Normal file
4
01-basics/lab06/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab07/docker-compose.yml
Normal file
7
01-basics/lab07/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
31
01-basics/lab07/lab.txt
Normal file
31
01-basics/lab07/lab.txt
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
= Single Level Wildcard
|
||||||
|
|
||||||
|
|
||||||
|
Abbonieren Sie die Topics `training/+/student` und `schulung/+/+`
|
||||||
|
|
||||||
|
|
||||||
|
Publizieren Sie Nachrichten nach
|
||||||
|
- training/mqtt/student
|
||||||
|
- schulung/mqtt/teilnehmer
|
||||||
|
- training/all
|
||||||
|
|
||||||
|
Funktioniert alles, wie erwartet?
|
||||||
|
|
||||||
|
|
||||||
|
Subscribe mit Wildcard
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub \
|
||||||
|
--topic training/+/student --topic schulung/+/+ \
|
||||||
|
--debug
|
||||||
|
|
||||||
|
|
||||||
|
Publish
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub \
|
||||||
|
--topic training/mqtt/student --message "hello: training/mqtt/student"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub \
|
||||||
|
--topic schulung/mqtt/teilnehmer --message "hello: schulung/mqtt/teilnehmer"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub \
|
||||||
|
--topic training/all --message "hello: training/all"
|
||||||
4
01-basics/lab07/mosquitto.conf
Normal file
4
01-basics/lab07/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab08/docker-compose.yml
Normal file
7
01-basics/lab08/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
47
01-basics/lab08/lab.txt
Normal file
47
01-basics/lab08/lab.txt
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
= Multi Level Wildcard
|
||||||
|
|
||||||
|
Abbonieren Sie einmal alles.
|
||||||
|
|
||||||
|
|
||||||
|
Abbonieren Sie alles, was zu `training` oder `schulung` gehört.
|
||||||
|
|
||||||
|
Senden Sie Nachrichten an
|
||||||
|
- training/mqtt/student
|
||||||
|
- schulung/mqtt/teilnehmer
|
||||||
|
- all
|
||||||
|
|
||||||
|
Funktioniert alles, wie erwartet?
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub \
|
||||||
|
--topic '#' \
|
||||||
|
--debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub \
|
||||||
|
--topic 'training/#' --topic 'schulung/#' \
|
||||||
|
--debug
|
||||||
|
|
||||||
|
|
||||||
|
Versand der Testnachrichten:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub \
|
||||||
|
--topic training/mqtt/student --message "hello: training/mqtt/student"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub \
|
||||||
|
--topic schulung/mqtt/teilnehmer --message "hello: schulung/mqtt/teilnehmer"
|
||||||
|
|
||||||
|
// FIX: nur topic 'all' um zu zeigen das dieses nur bei dem ersten sub erhalten wird
|
||||||
|
aber nicht bei 'training/#' und 'schulung/#'
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub \
|
||||||
|
--topic all --message "hello: all"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Erhalten Sie auch System-Nachrichten?
|
||||||
|
|
||||||
|
Abbonieren Sie explizit alle `$SYS` Topics.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_sub \
|
||||||
|
--topic '$SYS/#' \
|
||||||
|
--debug
|
||||||
|
|
||||||
4
01-basics/lab08/mosquitto.conf
Normal file
4
01-basics/lab08/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab09/docker-compose.yml
Normal file
7
01-basics/lab09/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
46
01-basics/lab09/lab.txt
Normal file
46
01-basics/lab09/lab.txt
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
= MQTT Topic Visualisierung mit dem MQTT Explorer
|
||||||
|
|
||||||
|
Installieren Sie den MQTTExplorer und interagieren Sie mit Ihrem Mosquitto Broker.
|
||||||
|
|
||||||
|
|
||||||
|
MQTTExplorer installieren:
|
||||||
|
|
||||||
|
Gehen Sie auf die offizielle Webseite des MQTTExplorers ( https://mqtt-explorer.com/ )
|
||||||
|
|
||||||
|
Laden Sie die passende Version für Ihr Betriebssystem herunter und installiere Sie diese.
|
||||||
|
|
||||||
|
Für Debian/Ubuntu kann das .deb-Paket verwendet werden.
|
||||||
|
Installation:
|
||||||
|
|
||||||
|
$ wget https://github.com/thomasnordquist/MQTT-Explorer/releases/download/v0.4.0-beta.6/MQTT-Explorer_0.4.0-beta.6_amd64.deb
|
||||||
|
$ sudo dpkg -i MQTT-Explorer_0.4.0-beta.6_amd64.deb
|
||||||
|
|
||||||
|
Hinweis zu macOS: Bei macOS sollte die AppStore Version des MQTT Explorers genutzt werden.
|
||||||
|
Dies ist eine etwas veraltete Version. Die neuste Version wird von macOS blockiert.
|
||||||
|
|
||||||
|
|
||||||
|
Starten Sie den MQTTExplorer.
|
||||||
|
|
||||||
|
$ mqtt-explorer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Broker Verbindung mit dem MQTTExplorer:
|
||||||
|
|
||||||
|
Klicken Sie auf das '+' Symbol um eine neue Verbindung hinzuzufügen.
|
||||||
|
|
||||||
|
Geben Sie der Verbindung einen Namen (bspw. Mosquitto) und tragen Sie als Host 'localhost' ein.
|
||||||
|
|
||||||
|
Klicken Sie auf Speichern und dann auf Verbinden.
|
||||||
|
|
||||||
|
Nun können Sie das Interface des MQTTExplorers nutzen um Nachrichten zu senden und alle Nachrichten zu sehen,
|
||||||
|
die der Broker empfängt.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Quellen
|
||||||
|
|
||||||
|
MQTTExplorer https://mqtt-explorer.com
|
||||||
4
01-basics/lab09/mosquitto.conf
Normal file
4
01-basics/lab09/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab10/docker-compose.yml
Normal file
7
01-basics/lab10/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
78
01-basics/lab10/lab.txt
Normal file
78
01-basics/lab10/lab.txt
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
= Session
|
||||||
|
|
||||||
|
Verwenden Sie `mosquitto_sub`, eine feste Client-ID (`--id`), QoS 1, deaktiviertes Clean-Session (`-c`) und Topic `demo` +
|
||||||
|
`mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug`
|
||||||
|
|
||||||
|
Beenden Sie mittels `CTRL-C`, senden dann mehrere Nachrichten mit QoS 1 an das Topic `demo` und starten `mosquitto_sub` erneut
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
CTRL-C
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 1"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 2"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 3"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
|
||||||
|
Wiederholen Sie den Vorgang, verwenden Sie statt `CTRL-C` zum Beenden `sudo killall -KILL mosquitto_sub`.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
$ sudo killall -KILL mosquitto_sub
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 1"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 2"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 3"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Testen Sie, ob der Versand mit QoS 0 sich genauso verhält
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
CTRL-C
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 0 --message "Demo message 1"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 0 --message "Demo message 2"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Was ist, falls der Subscriber QoS 0 verwendet und der Publisher QoS 1?
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 0 --disable-clean-session --debug
|
||||||
|
|
||||||
|
CTRL-C
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 1"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 --message "Demo message 2"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
|
||||||
2
01-basics/lab10/mosquitto.conf
Normal file
2
01-basics/lab10/mosquitto.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
7
01-basics/lab11/docker-compose.yml
Normal file
7
01-basics/lab11/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
32
01-basics/lab11/lab.txt
Normal file
32
01-basics/lab11/lab.txt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
= Wireshark
|
||||||
|
|
||||||
|
|
||||||
|
Installieren Sie Wireshark und/oder tshark.
|
||||||
|
|
||||||
|
$ sudo apt update; sudo apt -y install tshark wireshark
|
||||||
|
|
||||||
|
|
||||||
|
Verwenden Sie Wireshark (oder tshark) mit Port 1883 und MQTT Protokollanalyse
|
||||||
|
|
||||||
|
Wireshark: Interface "loopback / lo ", Apply a display filter: "tcp.port == 1883"
|
||||||
|
|
||||||
|
tshark:
|
||||||
|
|
||||||
|
$ tshark -s 1500 -i lo -n -x -O mqtt port 1883
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Senden Sie die Nachricht 'hello trion' an das Topic `training`
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto mosquitto_pub \
|
||||||
|
--topic training --message "hello trion"
|
||||||
|
|
||||||
|
|
||||||
|
Analysieren Sie die gesendeten und empfangenen Daten
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Quellen
|
||||||
|
|
||||||
|
Wireshark: https://www.wireshark.org/
|
||||||
4
01-basics/lab11/mosquitto.conf
Normal file
4
01-basics/lab11/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab12/docker-compose.yml
Normal file
7
01-basics/lab12/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
55
01-basics/lab12/lab.txt
Normal file
55
01-basics/lab12/lab.txt
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
= QoS 0 TCP Absicherung
|
||||||
|
|
||||||
|
Ziel ist zu sehen, wie TCP bei Verbindungsproblemen die Applikationsschicht absichert.
|
||||||
|
|
||||||
|
Dazu wird für den TCP Port 1883 ein Paketverlust von 50% konfiguriert und Anschließend
|
||||||
|
Nachrichten versendet und konsumiert.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug --topic demo/qos0 -q 0
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic demo/qos0 -q 0 --message "before tcp loss"
|
||||||
|
|
||||||
|
|
||||||
|
In separatem Terminal wird nun das Netzwerk so konfiguriert, dass es
|
||||||
|
hohen IP Paketverlust (50%) gibt:
|
||||||
|
|
||||||
|
(falls Docker genutzt wird)
|
||||||
|
$ docker run --rm -it --net host --cap-add NET_ADMIN alpine:3
|
||||||
|
# apk -U add iptables iproute2 iproute2-ss
|
||||||
|
|
||||||
|
(ohne Docker, Debian/Ubuntu)
|
||||||
|
$ sudo apt install -y iptables iproute2
|
||||||
|
$ sudo bash
|
||||||
|
|
||||||
|
|
||||||
|
# iptables -t mangle -A POSTROUTING -o lo -p tcp --sport 1883 -j MARK --set-mark 1
|
||||||
|
# iptables -t mangle -A PREROUTING -i lo -p tcp --dport 1883 -j MARK --set-mark 1
|
||||||
|
|
||||||
|
# tc qdisc add dev lo root handle 1: prio
|
||||||
|
# tc filter add dev lo parent 1:0 protocol ip handle 1 fw flowid 1:1
|
||||||
|
# tc qdisc add dev lo parent 1:1 handle 10: netem loss 50%
|
||||||
|
|
||||||
|
|
||||||
|
Im ersten Terminal werden nun mehrere Nachrichten versandt:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos0 -q 0 -m "this will be save #1"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos0 -q 0 -m "this will be save #2"
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos0 -q 0 -m "this will be save #3"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Anschließendes Aufräumen:
|
||||||
|
|
||||||
|
# iptables -t mangle -F
|
||||||
|
# tc qdisc del dev lo root
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Quellen
|
||||||
|
|
||||||
|
Wireshark: https://www.wireshark.org/
|
||||||
4
01-basics/lab12/mosquitto.conf
Normal file
4
01-basics/lab12/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab13/docker-compose.yml
Normal file
7
01-basics/lab13/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
55
01-basics/lab13/lab.txt
Normal file
55
01-basics/lab13/lab.txt
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
= QoS 0 Verlust von Nachrichten
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug --topic demo/qos0 -q 0
|
||||||
|
|
||||||
|
|
||||||
|
In separatem Terminal wird nun das Netzwerk so konfiguriert, dass es
|
||||||
|
hohe Latenzen (3 Sekunden) gibt, dies macht es leichter, zum richtigen Zeitpunkt
|
||||||
|
die Verbindung zu unterbrechen:
|
||||||
|
|
||||||
|
(falls Docker genutzt wird)
|
||||||
|
$ docker run --rm -it --net host --cap-add NET_ADMIN alpine:3
|
||||||
|
# apk -U add iptables iproute2 iproute2-ss
|
||||||
|
|
||||||
|
(ohne Docker, Debian/Ubuntu)
|
||||||
|
$ sudo apt install -y iptables iproute2
|
||||||
|
$ sudo bash
|
||||||
|
|
||||||
|
|
||||||
|
# iptables -t mangle -A POSTROUTING -o lo -p tcp --sport 1883 -j MARK --set-mark 1
|
||||||
|
# iptables -t mangle -A PREROUTING -i lo -p tcp --dport 1883 -j MARK --set-mark 1
|
||||||
|
|
||||||
|
# tc qdisc add dev lo root handle 1: prio
|
||||||
|
# tc filter add dev lo parent 1:0 protocol ip handle 1 fw flowid 1:1
|
||||||
|
# tc qdisc add dev lo parent 1:1 handle 10: netem delay 3s
|
||||||
|
|
||||||
|
|
||||||
|
Im ersten Terminal werden nun mehrere Nachrichten versandt:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos0 -q 0 -m "this will be save #1"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos0 -q 0 -m "this will be lost #2"
|
||||||
|
|
||||||
|
(Nach ca. 6 Sekunden werden die TCP Verbindungen im zweiten Terminal unterbrochen)
|
||||||
|
# ss -t -K sport = :1883
|
||||||
|
|
||||||
|
(Neuer Versand funktioniert)
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos0 -q 0 -m "this will be save #3"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Anschließendes Aufräumen:
|
||||||
|
|
||||||
|
# iptables -t mangle -F
|
||||||
|
# tc qdisc del dev lo root
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Quellen
|
||||||
|
|
||||||
|
Wireshark: https://www.wireshark.org/
|
||||||
4
01-basics/lab13/mosquitto.conf
Normal file
4
01-basics/lab13/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab14/docker-compose.yml
Normal file
7
01-basics/lab14/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
73
01-basics/lab14/lab.txt
Normal file
73
01-basics/lab14/lab.txt
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
= QoS 1 Nachlieferung
|
||||||
|
|
||||||
|
Subscribe mit expliziter Client ID und "clean session" auf "false".
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug --topic demo/qos1 --qos 1 --disable-clean-session --id demo
|
||||||
|
|
||||||
|
|
||||||
|
In separatem Terminal wird nun das Netzwerk so konfiguriert, dass es
|
||||||
|
hohe Latenzen (3 Sekunden) gibt, dies macht es leichter, zum richtigen Zeitpunkt
|
||||||
|
die Verbindung zu unterbrechen:
|
||||||
|
|
||||||
|
|
||||||
|
(falls Docker genutzt wird)
|
||||||
|
$ docker run --rm -it --net host --cap-add NET_ADMIN alpine:3
|
||||||
|
# apk -U add iptables iproute2 iproute2-ss
|
||||||
|
|
||||||
|
(ohne Docker, Debian/Ubuntu)
|
||||||
|
$ sudo apt install -y iptables iproute2
|
||||||
|
$ sudo bash
|
||||||
|
|
||||||
|
|
||||||
|
# iptables -t mangle -A POSTROUTING -o lo -p tcp --sport 1883 -j MARK --set-mark 1
|
||||||
|
# iptables -t mangle -A PREROUTING -i lo -p tcp --dport 1883 -j MARK --set-mark 1
|
||||||
|
|
||||||
|
# tc qdisc add dev lo root handle 1: prio
|
||||||
|
# tc filter add dev lo parent 1:0 protocol ip handle 1 fw flowid 1:1
|
||||||
|
# tc qdisc add dev lo parent 1:1 handle 10: netem delay 3s
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Ermittlung des Ports des Subscribers:
|
||||||
|
|
||||||
|
# ss -t sport = :1883
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Im ersten Terminal werden nun mehrere Nachrichten versandt:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos1 -q 1 -m "This is delivered. #1"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t demo/qos1 -q 1 -m " #### This could be delivered later. #2"
|
||||||
|
|
||||||
|
Nach ca. 3 Sekunden werden die TCP Verbindungen des Subscribers im zweiten Terminal unterbrochen)
|
||||||
|
# ss -t -K sport = :60804
|
||||||
|
|
||||||
|
Optional: Im ersten Terminal wird mittels mehrfachem CTRL-C der Subscriber beendet.
|
||||||
|
Anschließend erfolgt neuer Start.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug -t demo/qos1 --qos 1 --disable-clean-session --id demo
|
||||||
|
|
||||||
|
|
||||||
|
Testen Sie auch, was passiert, wenn beim Neustart ein völlig anderes Topic angegeben wird -
|
||||||
|
wird die nicht erhaltene Nachricht trotzdem ausgeliefert?
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug -t demo/othertopic --qos 1 --disable-clean-session --id demo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Anschließendes Aufräumen:
|
||||||
|
|
||||||
|
# iptables -t mangle -F
|
||||||
|
# tc qdisc del dev lo root
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
= Quellen
|
||||||
|
|
||||||
|
Wireshark: https://www.wireshark.org/
|
||||||
4
01-basics/lab14/mosquitto.conf
Normal file
4
01-basics/lab14/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab15/docker-compose.yml
Normal file
7
01-basics/lab15/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
37
01-basics/lab15/lab.txt
Normal file
37
01-basics/lab15/lab.txt
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
= Retained Message
|
||||||
|
|
||||||
|
|
||||||
|
Publizieren Sie alle 20 Sekunden eine Nachricht mit aktueller Zeit, einmal mit
|
||||||
|
retained Flag, einmal ohne in jeweils separate Topics:
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
/bin/sh -c 'while true; do mosquitto_pub
|
||||||
|
-t demo/retained --qos 1 --retain -m "$(date)"; sleep 20; done'
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
/bin/sh -c 'while true; do mosquitto_pub
|
||||||
|
-t demo/not-retained --qos 1 -m "$(date)"; sleep 20; done'
|
||||||
|
|
||||||
|
|
||||||
|
Lesen Sie die Topics und beobachten das Verhalten.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug --topic demo/retained --qos 1 --disable-clean-session --id demo
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug --topic demo/not-retained --qos 1 --disable-clean-session --id demo
|
||||||
|
|
||||||
|
|
||||||
|
Beenden Sie die Publisher und starten erneut Subscriber und vergleichen das
|
||||||
|
Verhalten der beiden Topics.
|
||||||
|
|
||||||
|
|
||||||
|
Testen Sie bei dem Subscriber verschiedene QoS Level, Client-ID und Clean-Session Kombinationen.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug --topic demo/retained --qos 0 --disable-clean-session --id demo
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug --topic demo/retained --qos 1
|
||||||
|
|
||||||
4
01-basics/lab15/mosquitto.conf
Normal file
4
01-basics/lab15/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
01-basics/lab16/docker-compose.yml
Normal file
7
01-basics/lab16/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
37
01-basics/lab16/lab.txt
Normal file
37
01-basics/lab16/lab.txt
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
= Last Will and Testament
|
||||||
|
|
||||||
|
Nutzen Sie eine Last Will Nachricht mit dem 'mosquitto_pub' Befehl,
|
||||||
|
um auf dem Topic "clients/demo/status" eine Status Nachricht zu bekommen, sobald der
|
||||||
|
Publisher Client die Verbindung abbricht.
|
||||||
|
(Im Lab Ordner ist eine beispielhafte Umsetzung mit will-docker-compose.yaml als Referenz)
|
||||||
|
|
||||||
|
Subscriben Sie das Will Topic "clients/+/status"
|
||||||
|
|
||||||
|
Beenden Sie den Publisher einmal mit CTRL-C und killen Sie ihn (`kill -SIGKILL`) oder den
|
||||||
|
zugehörigen TCP Socket (`ss sport =: 1883` und `ss -K sport =:9999`)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Subscriben Sie das Topic "clients/+/status".
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --debug -t clients/+/status
|
||||||
|
|
||||||
|
|
||||||
|
Verwenden Sie einen Client mit Last Will Nachricht.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --will-topic clients/room1/status --will-payload offline --will-qos 1 --topic demo
|
||||||
|
|
||||||
|
Nutzen Sie folgenden Befehl, um die Sockets der Clients zu finden:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host --cap-add NET_ADMIN alpine:3
|
||||||
|
# apk -U add iptables iproute2 iproute2-ss
|
||||||
|
# ss -t sport = :1883
|
||||||
|
|
||||||
|
Beenden Sie die TCP Verbindungen mit dem Befehl (Port anpassen):
|
||||||
|
|
||||||
|
# ss -t -K sport = :9999
|
||||||
|
|
||||||
|
|
||||||
4
01-basics/lab16/mosquitto.conf
Normal file
4
01-basics/lab16/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
28
01-basics/lab16/will-docker-compose.yml
Normal file
28
01-basics/lab16/will-docker-compose.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
|
|
||||||
|
subscriber:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
network_mode: host
|
||||||
|
depends_on:
|
||||||
|
- mosquitto
|
||||||
|
command: >
|
||||||
|
sh -c "
|
||||||
|
mosquitto_sub -t clients/+/status
|
||||||
|
"
|
||||||
|
|
||||||
|
lwt-publisher:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
network_mode: host
|
||||||
|
depends_on:
|
||||||
|
- mosquitto
|
||||||
|
- subscriber
|
||||||
|
command: >
|
||||||
|
sh -c "
|
||||||
|
mosquitto_sub -t sensors/room1/temperature --will-topic clients/room1/status --will-payload offline --will-qos 1
|
||||||
|
"
|
||||||
7
02-mqtt5/lab01/docker-compose.yml
Normal file
7
02-mqtt5/lab01/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
46
02-mqtt5/lab01/lab.txt
Normal file
46
02-mqtt5/lab01/lab.txt
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
= Session Expiration
|
||||||
|
|
||||||
|
Subscriben Sie mit `mosquitto_sub` als MQTT 5 Client (`-V 5`) mit fester ID, QoS 1, ohne Clean-Session und 10 Sekunden Expiration (`-x 10`) das Topic `demo/session`
|
||||||
|
|
||||||
|
Beenden Sie den Subscriber, beobachten Sie die mosquitto Logausgabe.
|
||||||
|
("p"rotokoll version, "c"lean session, "k"eepalive)
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/session -V 5 --id demo --qos 1 --disable-clean-session -x 10
|
||||||
|
|
||||||
|
CTRL-C
|
||||||
|
|
||||||
|
Publishen Sie eine QoS 1 Nachricht auf das Topic.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo/session" --qos 1 --message "Demo message"
|
||||||
|
|
||||||
|
Starten Sie den Subscriber neu
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/session -V 5 --id demo --qos 1 --disable-clean-session -x 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Wiederholen Sie den Vorgang, warten jedoch weniger als 10 Sekunden.
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/session -V 5 --id demo --qos 1 --disable-clean-session -x 10
|
||||||
|
|
||||||
|
CTRL-C
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo/session" --qos 1 --message "Demo message"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/session -V 5 --id demo --qos 1 --disable-clean-session -x 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Bonus: Untersuchen Sie mittels Netzwerkanalyse, wie `mosquitto_sub` sich verhält,
|
||||||
|
wenn keine Expiration Time, aber `--disable-clean-session` gesetzt ist.
|
||||||
|
|
||||||
|
$ sudo tshark -s 1500 -i lo -n -x -O mqtt port 1883
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 -V 5 --disable-clean-session
|
||||||
4
02-mqtt5/lab01/mosquitto.conf
Normal file
4
02-mqtt5/lab01/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
02-mqtt5/lab02/docker-compose.yml
Normal file
7
02-mqtt5/lab02/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
31
02-mqtt5/lab02/lab.txt
Normal file
31
02-mqtt5/lab02/lab.txt
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
= Message Expiration
|
||||||
|
|
||||||
|
Aufbau einer QoS 1 Session durch Subscriber und Verbindungsabbau.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 -V 5 --disable-clean-session --debug
|
||||||
|
|
||||||
|
CTRL-C
|
||||||
|
|
||||||
|
Versand einer Nachricht mit Expiration durch MQTT 5 Publisher und
|
||||||
|
Fortsetzung der Session durch Client innerhalb und nach der Zeitspanne.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 -V 5 \
|
||||||
|
--property publish message-expiry-interval 10 --message "Demo message"
|
||||||
|
|
||||||
|
$ sleep 6; docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 -V 5 --disable-clean-session --debug
|
||||||
|
|
||||||
|
|
||||||
|
Was passiert, wenn der Subscriber MQTT 3.x verwendet?
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --topic "demo" --qos 1 -V 5 \
|
||||||
|
--property publish message-expiry-interval 10 --message "Demo message"
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo --id demo --qos 1 --disable-clean-session --debug
|
||||||
4
02-mqtt5/lab02/mosquitto.conf
Normal file
4
02-mqtt5/lab02/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
02-mqtt5/lab03/docker-compose.yml
Normal file
7
02-mqtt5/lab03/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
13
02-mqtt5/lab03/lab.txt
Normal file
13
02-mqtt5/lab03/lab.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
= Reason Codes
|
||||||
|
|
||||||
|
Provozieren Sie einen Fehler durch Senden einer QoS 1 Nachricht auf ein
|
||||||
|
Broker Topic, z.B. `$SYS/demo`.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -V 5 --id demo --qos 1 --topic '$SYS/demo' --message hi --debug
|
||||||
|
|
||||||
|
|
||||||
|
Vergleichen Sie das Verhalten bei MQTT 5 vs. 3.x
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --id demo --qos 1 --topic '$SYS/demo' --message hi --debug
|
||||||
4
02-mqtt5/lab03/mosquitto.conf
Normal file
4
02-mqtt5/lab03/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
02-mqtt5/lab04/docker-compose.yml
Normal file
7
02-mqtt5/lab04/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
23
02-mqtt5/lab04/lab.txt
Normal file
23
02-mqtt5/lab04/lab.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
= Response-Topic
|
||||||
|
|
||||||
|
Lassen Sie sich von `mosquitto_rr` die Hilfe ausgeben.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_rr --help
|
||||||
|
|
||||||
|
|
||||||
|
Topic `services/temp_query` soll für Anfragen dienen.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -V 5 --topic services/temp_query --debug
|
||||||
|
|
||||||
|
|
||||||
|
Antwort soll auf das jeweils mitgeteilte Topic gesendet werden, 20 Sekunden Timeout
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_rr --id demo --topic services/temp_query \
|
||||||
|
--message celsius -e reply/demo -W 20 --debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -V 5 --topic reply/demo --message "19.3"
|
||||||
4
02-mqtt5/lab04/mosquitto.conf
Normal file
4
02-mqtt5/lab04/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
02-mqtt5/lab05/docker-compose.yml
Normal file
7
02-mqtt5/lab05/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
21
02-mqtt5/lab05/lab.txt
Normal file
21
02-mqtt5/lab05/lab.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
= Shared Subscription
|
||||||
|
|
||||||
|
Erstellen Sie einen Publisher, der alle 2 Sekunden nach `output/demo` Werte sendet.
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -V 5 --topic output/demo --repeat 100 --repeat-delay 2 --message 'input'
|
||||||
|
|
||||||
|
Verwenden Sie zunächst eine Gruppe aus zwei Konsumenten.
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --id consumer-1 --topic '$share/group1/output/demo'
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --id consumer-2 --topic '$share/group1/output/demo'
|
||||||
|
|
||||||
|
|
||||||
|
Ergänzen Sie eine zweite Gruppe mit einem Konsumenten
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --id consumer-3 --topic '$share/group2/output/demo'
|
||||||
4
02-mqtt5/lab05/mosquitto.conf
Normal file
4
02-mqtt5/lab05/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
7
03-security/lab01/docker-compose.yml
Normal file
7
03-security/lab01/docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
23
03-security/lab01/lab.txt
Normal file
23
03-security/lab01/lab.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
= Öffentliche Broker
|
||||||
|
|
||||||
|
Verbinden Sie sich zu einem öffentlichen Broker, z.B. `test.mosquitto.org`, `broker.emqx.io` oder `broker.hivemq.com`
|
||||||
|
Können Sie Nachrichten aller Topics abrufen?
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -h test.mosquitto.org -V 5 -v -t "#" -W 5
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -h broker.hivemq.com -V 5 -v -t "#" -W 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Geben Sie von einer 10 Sekunden Messung (`timeout 10s <command>` oder `mosquitto_sub -W 10`)
|
||||||
|
die Top-10 Topics nach Nachrichten und Bytes aus (mosquitto_sub Ausgabeformat `%t` Topicname, `%l` Nachrichtenlänge)
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
timeout 10s mosquitto_sub -h test.mosquitto.org -t "#" -F "%t %l" | \
|
||||||
|
awk '{count[$1]++; size[$1]+=$2} END {print "Topic | Nachrichten | Bytes"; \
|
||||||
|
for (i in count) print i, count[i], size[i]}' | \
|
||||||
|
column -t | sort -k2 -nr | head -n 10
|
||||||
4
03-security/lab01/mosquitto.conf
Normal file
4
03-security/lab01/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
21
03-security/lab02/lab.txt
Normal file
21
03-security/lab02/lab.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
= Zertifikate
|
||||||
|
|
||||||
|
Rufen Sie von www.tagesschau.de das Zertifikate ab, verwenden Sie Ihren Webbrowser.
|
||||||
|
|
||||||
|
Je nach Browser:
|
||||||
|
Firefox: CTRL-I, Security, "View Certificate"
|
||||||
|
Chrome: kein Shortcut, klick auf "Regler" links von URL, Klick auf "Connection is secure", Klick auf "Certificate is valid"
|
||||||
|
|
||||||
|
Nutzen Sie OpenSSL als Client und rufen diese Zertfikate ab:
|
||||||
|
* www.tagesschau.de:443
|
||||||
|
* test.mosquitto.org:8883
|
||||||
|
|
||||||
|
$ openssl s_client -showcerts -connect www.tagesschau.de:443 </dev/null
|
||||||
|
$ openssl s_client -showcerts -connect test.mosquitto.org:8883 </dev/null
|
||||||
|
|
||||||
|
|
||||||
|
Lassen Sie sich von CyberChef das X.509 Zertifikat dekodieren:
|
||||||
|
"https://gchq.github.io/CyberChef/#recipe=Parse_X.509_certificate('PEM')"
|
||||||
|
|
||||||
|
Verdeutlichen Sie sich die wesentlichen Elemente
|
||||||
|
|
||||||
2
03-security/lab03/.gitignore
vendored
Normal file
2
03-security/lab03/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ca.crt
|
||||||
|
ca.key
|
||||||
13
03-security/lab03/lab.txt
Normal file
13
03-security/lab03/lab.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
= Self signed Zertifikat
|
||||||
|
|
||||||
|
Verwendung von OpenSSL um ein neues Zertifikat zu erstellen
|
||||||
|
|
||||||
|
$ openssl req -new -x509 -newkey rsa:2048 -days 365 \
|
||||||
|
-addext 'subjectAltName=DNS:mqtt.example.com,IP:127.0.0.1' \
|
||||||
|
-subj "/CN=example.com" \
|
||||||
|
-nodes -keyout ca.key -out ca.crt
|
||||||
|
|
||||||
|
|
||||||
|
Validieren Sie das Zertifikat mit OpenSSL
|
||||||
|
|
||||||
|
$ openssl verify -CAfile ca.crt ca.crt
|
||||||
1
03-security/lab04/.gitignore
vendored
Normal file
1
03-security/lab04/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
mosquitto.org.crt
|
||||||
33
03-security/lab04/lab.txt
Normal file
33
03-security/lab04/lab.txt
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
= Verwendung MQTT mit TLS
|
||||||
|
|
||||||
|
Verwenden Sie `mosquitto_sub` mit dem Host `test.mosquitto.org` und `--tls-use-os-certs`,
|
||||||
|
verwenden Sie einmal Port `8886` und einmal Port `8883`.
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 8886 -V 5 -W 10 --topic "#" --tls-use-os-certs --debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 8883 -V 5 -W 10 --topic "#" --tls-use-os-certs --debug
|
||||||
|
|
||||||
|
|
||||||
|
Laden Sie das CA Zertifikat von https://test.mosquitto.org/ssl/mosquitto.org.crt
|
||||||
|
und verwenden Sie es mit `--cafile` statt `--tls-use-os-certs` auf Port 8883
|
||||||
|
|
||||||
|
$ wget https://test.mosquitto.org/ssl/mosquitto.org.crt
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host -v $PWD:/data eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 8883 -V 5 -W 10 --topic "#" \
|
||||||
|
--cafile /data/mosquitto.org.crt --debug
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Was passiert, wenn Sie statt des Hostnamens die aufgelöste IP verwenden?
|
||||||
|
|
||||||
|
$ host test.mosquitto.org
|
||||||
|
$ dig in a test.mosquitto.org
|
||||||
|
$ nslookup test.mosquitto.org
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host -v $PWD:/data eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host 54.36.178.49 --port 8883 -V 5 -W 10 --topic "#" \
|
||||||
|
--cafile /data/mosquitto.org.crt --debug
|
||||||
20
03-security/lab05/lab.txt
Normal file
20
03-security/lab05/lab.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
= Username/Password Credentials
|
||||||
|
|
||||||
|
|
||||||
|
Verwenden Sie `mosquitto_sub` mit dem Host `test.mosquitto.org` und MQTT 5, Port `1884`,
|
||||||
|
Usernamen "ro" und Passwort "readonly".
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 1884 -V 5 --topic "demotopic" \
|
||||||
|
--username ro -P readonly --debug
|
||||||
|
|
||||||
|
Testen Sie, was bei einem anderen Passwort passiert.
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 1884 -V 5 --topic "demotopic" \
|
||||||
|
--username ro -P wrong --debug
|
||||||
|
|
||||||
|
|
||||||
|
Analysiern Sie die Netzwerkpakete, finden Sie Usernamen und Passwort?
|
||||||
|
|
||||||
|
$ sudo tshark -s 1500 -i any -n -x -O mqtt port 1884
|
||||||
28
03-security/lab06/lab.txt
Normal file
28
03-security/lab06/lab.txt
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
= TLS PSK mit OpenSSL
|
||||||
|
|
||||||
|
Erzeugen Sie mit OpenSSL einen hexadecimalen PSK Key
|
||||||
|
|
||||||
|
$ openssl rand -hex 16
|
||||||
|
|
||||||
|
|
||||||
|
Starten Sie mit OpenSSL einen TLS PSK Server.
|
||||||
|
|
||||||
|
$ openssl s_server -nocert -psk 7301036d7236029badbd -psk_hint Server-ID -accept 4433 -tls1_2
|
||||||
|
|
||||||
|
|
||||||
|
Verbinden Sie sich mit OpenSSL als Client.
|
||||||
|
|
||||||
|
$ openssl s_client -psk 7301036d7236029badbd -psk_identity Client_123 -connect localhost:4433 -tls1_2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Analog mit TLS 1.3.
|
||||||
|
|
||||||
|
Server:
|
||||||
|
|
||||||
|
$ openssl s_server -nocert -psk 7301036d7236029badbd -psk_identity Client_123 -accept 4433 -tls1_3
|
||||||
|
|
||||||
|
|
||||||
|
Client:
|
||||||
|
|
||||||
|
$ openssl s_client -psk 7301036d7236029badbd -psk_identity Client_123 -connect localhost:4433 -tls1_3
|
||||||
2
03-security/lab07/.gitignore
vendored
Normal file
2
03-security/lab07/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.pem
|
||||||
|
*.crt
|
||||||
24
03-security/lab07/lab.txt
Normal file
24
03-security/lab07/lab.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
= mTLS Authentifzierung
|
||||||
|
|
||||||
|
|
||||||
|
Laden Sie sich das CA Zertifikat von https://test.mosquitto.org/ssl/mosquitto.org.crt
|
||||||
|
|
||||||
|
$ wget https://test.mosquitto.org/ssl/mosquitto.org.crt
|
||||||
|
|
||||||
|
|
||||||
|
Verwenden Sie OpenSSL um sich ein Certificate-Signing-Request zu erstellen
|
||||||
|
|
||||||
|
$ openssl genrsa -out key.pem 2048
|
||||||
|
$ openssl req -new -key key.pem -out csr.pem -subj "/C=DE/O=trion/CN=mqttdemo"
|
||||||
|
|
||||||
|
|
||||||
|
Erstellen Sie sich damit auf https://test.mosquitto.org/ssl ein Client Zertifikat
|
||||||
|
Speichern Sie es als `cert.pem` im selben Verzeichnis.
|
||||||
|
|
||||||
|
|
||||||
|
Verwenden Sie `mosquitto_sub` mit dem Host `test.mosquitto.org` Port 8884,
|
||||||
|
nutzen Sie CA und Client Zertifikat (`--cert`, `--key`)
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host -v $PWD:/data eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 8884 -V 5 --topic "demotopic" \
|
||||||
|
--cert /data/cert.pem --key /data/key.pem --cafile /data/mosquitto.org.crt --debug
|
||||||
8
03-security/lab08/acl.txt
Normal file
8
03-security/lab08/acl.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
user rw
|
||||||
|
topic readwrite #
|
||||||
|
|
||||||
|
user wo
|
||||||
|
topic write /test
|
||||||
|
|
||||||
|
user ro
|
||||||
|
topic read #
|
||||||
10
03-security/lab08/docker-compose.yml
Normal file
10
03-security/lab08/docker-compose.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
|
- ./users.txt:/mosquitto/config/users.txt:ro
|
||||||
|
- ./acl.txt:/mosquitto/config/acl.txt:ro
|
||||||
|
- ./dynamic-config.json:/mosquitto/config/dynamic-config.json:rw
|
||||||
87
03-security/lab08/dynamic-config.json
Normal file
87
03-security/lab08/dynamic-config.json
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
{
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"rolename": "admin",
|
||||||
|
"acls": [{
|
||||||
|
"acltype": "publishClientSend",
|
||||||
|
"topic": "$CONTROL/dynamic-security/#",
|
||||||
|
"allow": true
|
||||||
|
}, {
|
||||||
|
"acltype": "publishClientReceive",
|
||||||
|
"topic": "$CONTROL/dynamic-security/#",
|
||||||
|
"allow": true
|
||||||
|
}, {
|
||||||
|
"acltype": "subscribePattern",
|
||||||
|
"topic": "$CONTROL/dynamic-security/#",
|
||||||
|
"allow": true
|
||||||
|
}, {
|
||||||
|
"acltype": "publishClientReceive",
|
||||||
|
"topic": "$SYS/#",
|
||||||
|
"allow": true
|
||||||
|
}, {
|
||||||
|
"acltype": "subscribePattern",
|
||||||
|
"topic": "$SYS/#",
|
||||||
|
"allow": true
|
||||||
|
}, {
|
||||||
|
"acltype": "publishClientReceive",
|
||||||
|
"topic": "#",
|
||||||
|
"allow": true
|
||||||
|
}, {
|
||||||
|
"acltype": "subscribePattern",
|
||||||
|
"topic": "#",
|
||||||
|
"allow": true
|
||||||
|
}, {
|
||||||
|
"acltype": "unsubscribePattern",
|
||||||
|
"topic": "#",
|
||||||
|
"allow": true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rolename": "read-write-role",
|
||||||
|
"acls": [
|
||||||
|
{ "acltype": "publishClientSend", "topic": "#", "priority": 0, "allow": true },
|
||||||
|
{ "acltype": "subscribeLiteral", "topic": "#", "priority": 0, "allow": true },
|
||||||
|
{ "acltype": "unsubscribeLiteral", "topic": "#", "priority": 0, "allow": true }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rolename": "write-only-role",
|
||||||
|
"acls": [
|
||||||
|
{ "acltype": "publishClientSend", "topic": "#", "priority": 0, "allow": true },
|
||||||
|
{ "acltype": "subscribeLiteral", "topic": "#", "priority": 0, "allow": false },
|
||||||
|
{ "acltype": "subscribePattern", "topic": "#", "priority": 0, "allow": false }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rolename": "read-only-role",
|
||||||
|
"acls": [
|
||||||
|
{ "acltype": "subscribeLiteral", "topic": "#", "priority": 0, "allow": true },
|
||||||
|
{ "acltype": "publishClientSend", "topic": "#", "priority": 0, "allow": false }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"clients": [
|
||||||
|
{
|
||||||
|
"username": "admin-user",
|
||||||
|
"textName": "Dynsec admin user, password geheim",
|
||||||
|
"password": "qFa1Zzq4SXwI1aGJq9rJm14m6LWiv+7p4mbDfsQK1x15NOBdZke4GO6zxSBfOXinRgVKES/tlyfmVJhq0N6rKw==",
|
||||||
|
"salt": "Qv02Q1Ngia2GacTB",
|
||||||
|
"iterations": 101,
|
||||||
|
"roles": [{
|
||||||
|
"rolename": "admin"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{ "username": "rw", "roles": [ { "rolename": "read-write-role" } ] },
|
||||||
|
{ "username": "wo", "roles": [ { "rolename": "write-only-role" } ] },
|
||||||
|
{ "username": "ro", "roles": [ { "rolename": "read-only-role" } ] }
|
||||||
|
],
|
||||||
|
"default_access": {
|
||||||
|
"publishClientSend": false,
|
||||||
|
"publishClientReceive": true,
|
||||||
|
"subscribeLiteral": false,
|
||||||
|
"subscribePattern": false,
|
||||||
|
"unsubscribeLiteral": false,
|
||||||
|
"subscribe": false,
|
||||||
|
"unsubscribe": true
|
||||||
|
}
|
||||||
|
}
|
||||||
42
03-security/lab08/lab.txt
Normal file
42
03-security/lab08/lab.txt
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
= Berechtigungen
|
||||||
|
|
||||||
|
Verwenden Sie `mosquitto_sub` mit dem Host `test.mosquitto.org`, MQTT 5,
|
||||||
|
Port `1884`, Usernamen "ro" und Passwort (`-P`) "readonly"
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 1884 -V 5 --qos 1 --topic "demotopic" \
|
||||||
|
--username ro -P readonly -W 2 --debug
|
||||||
|
|
||||||
|
|
||||||
|
Was passiert, wenn Sie "wo" und Passwort "writeonly" nutzen?
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --host test.mosquitto.org --port 1884 -V 5 --qos 1 --topic "demotopic" \
|
||||||
|
--username wo -P writeonly -W 2 --debug
|
||||||
|
|
||||||
|
|
||||||
|
Was passiert, wenn Sie mit den 'ro' User etwas publishen wollen?
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub --host test.mosquitto.org --port 1884 -V 5 --qos 1 --topic "demotopic" \
|
||||||
|
--username ro -P readonly --message "demo message" --debug
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Alternativ kann mittels `docker compose up` gleichartiges lokales Setup verwendet werden:
|
||||||
|
|
||||||
|
$ docker compose up
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -V 5 --qos 1 --topic "demotopic" \
|
||||||
|
--username ro -P readonly -W 2 --debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -V 5 --qos 1 --topic "demotopic" \
|
||||||
|
--username wo -P writeonly -W 2 --debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -V 5 --qos 1 --topic "demotopic" \
|
||||||
|
--username ro -P readonly --message "demo message" --debug
|
||||||
13
03-security/lab08/mosquitto.conf
Normal file
13
03-security/lab08/mosquitto.conf
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
listener 1883
|
||||||
|
|
||||||
|
allow_anonymous false
|
||||||
|
|
||||||
|
# this works but does not support expected feedback,
|
||||||
|
# see this issue comment:
|
||||||
|
# https://github.com/eclipse-mosquitto/mosquitto/issues/2296#issuecomment-924423566
|
||||||
|
# The ACLs in an ACL file are currently exclusively related to publishing - write indicates whether the client is allowed to send a publish to a topic, and read indicates whether a client is allowed to receive a publish on a topic.
|
||||||
|
password_file /mosquitto/config/users.txt
|
||||||
|
acl_file mosquitto/config/acl.txt
|
||||||
|
|
||||||
|
plugin /usr/lib/mosquitto_dynamic_security.so
|
||||||
|
plugin_opt_config_file /mosquitto/config/dynamic-config.json
|
||||||
3
03-security/lab08/users.txt
Normal file
3
03-security/lab08/users.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ro:$7$101$FPVn7s0SIqjbFLYS$wMHGMiFqSlGwHAP23kFoUgdkd8NH1J70mDdXlQPVxGxoC8wQz0lY8Wsoqf8O8JNjzZxyVmrNlG1n/mLxlf2i7g==
|
||||||
|
rw:$7$101$nayIsCxTb05m2LY6$jIJbztZr2r/ZWUyM1Qfo2QC390OPgcd6AbtuG9wadDXex/+tWjNhVEoTRs746KIeBmNiJbnwZ9kts2L6gn3MBA==
|
||||||
|
wo:$7$101$dIqbFuwPghjophX4$8U6EeHb7mBI4NWb9/J+wTW+WzvhN8ipWdA1UBK/ePs/Me/HfmvhiAcIpxcUsMvDjwWFc0UXlAkjFkoeEkPQ+cw==
|
||||||
72
04-mosquitto/lab01/lab.txt
Normal file
72
04-mosquitto/lab01/lab.txt
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
= Mosquitto Listener
|
||||||
|
|
||||||
|
|
||||||
|
Konfigurieren Sie Mosquitto für zwei Listener:
|
||||||
|
- Port 1883 mit Client-ID Prefix "def" und anonymen Zugriff
|
||||||
|
- Port 1884 mit Client-ID Prefix "local", anonymen Zugriff nur mit MQTT 5, maximal 5 Verbindungen nur auf dem loopback Interface (127.0.0.1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
listener 1883 # defaults, max_conn: -1
|
||||||
|
listener_auto_id_prefix def
|
||||||
|
listener_allow_anonymous true
|
||||||
|
|
||||||
|
listener 1884 127.0.0.1
|
||||||
|
listener_auto_id_prefix local
|
||||||
|
listener_allow_anonymous true
|
||||||
|
protocol mqtt
|
||||||
|
accept_protocol_versions 5 # ab mosquitto v2.1
|
||||||
|
max_connections 5
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host \
|
||||||
|
-v $PWD/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro eclipse-mosquitto
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Testen Sie den Zugriff über das Loopback Interface und eine andere IP der Maschine.
|
||||||
|
|
||||||
|
$ nc 10.23.15.2 1883
|
||||||
|
$ nc 10.23.15.2 1884
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Verwenden Sie MQTT 3.1.1 und MQTT 5
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1883 -V 5 --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --debug
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1883 --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 --debug
|
||||||
|
|
||||||
|
|
||||||
|
Beobachten Sie, welche Client ID Sie erhalten, wenn Sie im Client
|
||||||
|
keine vs. eine selbst gewählte angeben
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1883 -V 5 --id myid --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --id myid --debug
|
||||||
|
|
||||||
|
|
||||||
|
Versuchen Sie mehr als 5 Verbindungen auf den limitierten Listener zu öffnen
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --id conn1 --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --id conn2 --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --id conn3 --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --id conn4 --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --id conn5 --debug
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub --topic demo/retained --qos 1 --port 1884 -V 5 --id conn6 --debug
|
||||||
10
04-mosquitto/lab01/mosquitto.conf
Normal file
10
04-mosquitto/lab01/mosquitto.conf
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
listener 1883 # defaults, max_conn: -1
|
||||||
|
listener_auto_id_prefix def
|
||||||
|
listener_allow_anonymous true
|
||||||
|
|
||||||
|
listener 1884 127.0.0.1
|
||||||
|
listener_auto_id_prefix local
|
||||||
|
listener_allow_anonymous true
|
||||||
|
protocol mqtt
|
||||||
|
accept_protocol_versions 5 # ab mosquitto v2.1
|
||||||
|
max_connections 5
|
||||||
1
04-mosquitto/lab02/.gitignore
vendored
Normal file
1
04-mosquitto/lab02/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/data/mosquitto.db
|
||||||
0
04-mosquitto/lab02/data/.gitkeep
Normal file
0
04-mosquitto/lab02/data/.gitkeep
Normal file
9
04-mosquitto/lab02/docker-compose.yml
Normal file
9
04-mosquitto/lab02/docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
|
# - ./mosquitto-persistenz.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
|
- ./data:/data
|
||||||
40
04-mosquitto/lab02/lab.txt
Normal file
40
04-mosquitto/lab02/lab.txt
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
= Mosquitto Persistenz
|
||||||
|
|
||||||
|
Senden Sie zunächst eine retained message
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t "test/status" -r -m "Online"
|
||||||
|
|
||||||
|
Rufen Sie die Nachricht ab +
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -t "test/status" --debug
|
||||||
|
|
||||||
|
|
||||||
|
Starten Sie den Broker neu und wiederholen den Vorgang.
|
||||||
|
Bei Verwendung von docker-compose kann CTRL-C verwendet werden,
|
||||||
|
alternativ kann der Prozess beendet werden.
|
||||||
|
|
||||||
|
$ sudo killall mosquitto
|
||||||
|
(Neustart des Brokers, z.B. mittels `docker compose up`)
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -t "test/status" --debug
|
||||||
|
|
||||||
|
Konfigurieren Sie Persistenz und wiederholen den Vorgang.
|
||||||
|
Beispiel:
|
||||||
|
|
||||||
|
persistence true
|
||||||
|
persistence_location /data
|
||||||
|
autosave_interval 1 # sekunden oder events
|
||||||
|
autosave_on_changes 1 # bei jeder einzelnen aenderung
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_pub -t "test/status" -r -m "Online"
|
||||||
|
|
||||||
|
(Neustart des Brokers)
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -t "test/status" --debug
|
||||||
10
04-mosquitto/lab02/mosquitto-persistenz.conf
Normal file
10
04-mosquitto/lab02/mosquitto-persistenz.conf
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
|
|
||||||
|
persistence true
|
||||||
|
persistence_location /data
|
||||||
|
autosave_interval 1 # sekunden oder events
|
||||||
|
autosave_on_changes 1 # bei jeder einzelnen aenderung
|
||||||
|
|
||||||
4
04-mosquitto/lab02/mosquitto.conf
Normal file
4
04-mosquitto/lab02/mosquitto.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
# sys_interval 3
|
||||||
5
04-mosquitto/lab03/config/mosquitto.conf
Normal file
5
04-mosquitto/lab03/config/mosquitto.conf
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
listener 1883
|
||||||
|
|
||||||
|
allow_anonymous false
|
||||||
|
password_file /mosquitto/config/users.txt
|
||||||
|
sys_interval 10
|
||||||
2
04-mosquitto/lab03/config/users.txt
Normal file
2
04-mosquitto/lab03/config/users.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
thomas:$7$101$+0sf4wma3qzDFw6R$H+lLmGLzo1Ex5rXxZqWxuEFCV7bSsAehEwTJ6XULFberEhwug/EC8aSWtiI4xScYQ2u/0sZ3xCg0rTRaMb5ITg==
|
||||||
|
admin:$7$101$S9wXlrBPl3PFz+9y$l3/GP/FjklfQ2inTxBf4FfLvFR3r5yF6G6ZSRDFRwAklzltZ+xhUWM83PKQjxy2ZFYYmHxMoKs4q1+IMrXL6NA==
|
||||||
14
04-mosquitto/lab03/cyberchef/chef.txt
Normal file
14
04-mosquitto/lab03/cyberchef/chef.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Fork('\\n','\\n',false)
|
||||||
|
Register('^([^:]+)',true,false,false)
|
||||||
|
Find_/_Replace({'option':'Regex','string':'^[^:]+:'},'',false,false,false,false)
|
||||||
|
Register('(.*)',true,false,false)
|
||||||
|
Pseudo-Random_Number_Generator(12,'Hex')
|
||||||
|
Register('(.*)',true,false,false)
|
||||||
|
From_Hex('Auto')
|
||||||
|
To_Base64('A-Za-z0-9+/=')
|
||||||
|
Register('([\\s\\S]*)',true,false,false)
|
||||||
|
Find_/_Replace({'option':'Regex','string':'.*'},'$R1',false,false,false,false)
|
||||||
|
Derive_PBKDF2_key({'option':'Latin1','string':'$R1'},512,101,'SHA512',{'option':'Hex','string':'$R2'})
|
||||||
|
From_Hex('Auto')
|
||||||
|
To_Base64('A-Za-z0-9+/=')
|
||||||
|
Find_/_Replace({'option':'Regex','string':'.*'},'$R0:$$7$$101$$$R3$$$&',false,false,false,false)
|
||||||
30
04-mosquitto/lab03/cyberchef/receipt.json
Normal file
30
04-mosquitto/lab03/cyberchef/receipt.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[
|
||||||
|
{ "op": "Fork",
|
||||||
|
"args": ["\\n", "\\n", false] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["^([^:]+)", true, false, false] },
|
||||||
|
{ "op": "Find / Replace",
|
||||||
|
"args": [{ "option": "Regex", "string": "^[^:]+:" }, "", false, false, false, false] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["(.*)", true, false, false] },
|
||||||
|
{ "op": "Pseudo-Random Number Generator",
|
||||||
|
"args": [12, "Hex"] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["(.*)", true, false, false] },
|
||||||
|
{ "op": "From Hex",
|
||||||
|
"args": ["Auto"] },
|
||||||
|
{ "op": "To Base64",
|
||||||
|
"args": ["A-Za-z0-9+/="] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["([\\s\\S]*)", true, false, false] },
|
||||||
|
{ "op": "Find / Replace",
|
||||||
|
"args": [{ "option": "Regex", "string": ".*" }, "$R1", false, false, false, false] },
|
||||||
|
{ "op": "Derive PBKDF2 key",
|
||||||
|
"args": [{ "option": "Latin1", "string": "$R1" }, 512, 101, "SHA512", { "option": "Hex", "string": "$R2" }] },
|
||||||
|
{ "op": "From Hex",
|
||||||
|
"args": ["Auto"] },
|
||||||
|
{ "op": "To Base64",
|
||||||
|
"args": ["A-Za-z0-9+/="] },
|
||||||
|
{ "op": "Find / Replace",
|
||||||
|
"args": [{ "option": "Regex", "string": ".*" }, "$R0:$$7$$101$$$R3$$$&", false, false, false, false] }
|
||||||
|
]
|
||||||
39
04-mosquitto/lab03/lab.txt
Normal file
39
04-mosquitto/lab03/lab.txt
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
= Mosquitto Authentifizierung
|
||||||
|
|
||||||
|
Konfigurieren Sie Mosquitto, so dass nur authentifizierte Clients zugreifen dürfen.
|
||||||
|
|
||||||
|
|
||||||
|
listener 1883
|
||||||
|
|
||||||
|
allow_anonymous false
|
||||||
|
password_file /mosquitto/config/users.txt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Erzeugen Sie eine Passwortdatei mit mehreren Nutzern.
|
||||||
|
Sie können `mosquitto_passwd` benutzen:
|
||||||
|
|
||||||
|
$ docker run --rm -it --net host eclipse-mosquitto sh
|
||||||
|
# mosquitto_passwd -b -c users.txt thomas geheim
|
||||||
|
# mosquitto_passwd -b users.txt admin secret
|
||||||
|
# cat users.txt
|
||||||
|
|
||||||
|
|
||||||
|
Für CyberChef befindet sich ein Rezept im Unterordner `CyberChef` oder
|
||||||
|
der folgende Link kann genutzt werden:
|
||||||
|
"https://gchq.github.io/CyberChef/#recipe=Fork('%5C%5Cn','%5C%5Cn',false)Register('%5E(%5B%5E:%5D%2B)',true,false,false)Find_/_Replace(%7B'option':'Regex','string':'%5E%5B%5E:%5D%2B:'%7D,'',false,false,false,false)Register('(.*)',true,false,false)Pseudo-Random_Number_Generator(12,'Hex')Register('(.*)',true,false,false)From_Hex('Auto')To_Base64('A-Za-z0-9%2B/%3D')Register('(%5B%5C%5Cs%5C%5CS%5D*)',true,false,false)Find_/_Replace(%7B'option':'Regex','string':'.*'%7D,'$R1',false,false,false,false)Derive_PBKDF2_key(%7B'option':'Latin1','string':'$R1'%7D,512,101,'SHA512',%7B'option':'Hex','string':'$R2'%7D)From_Hex('Auto')To_Base64('A-Za-z0-9%2B/%3D')Find_/_Replace(%7B'option':'Regex','string':'.*'%7D,'$R0:$$7$$101$$$R3$$$%26',false,false,false,false)"
|
||||||
|
|
||||||
|
Das Inputformat ist dabei: "user:klartextpasswort"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Testen Sie, ob der Zugriff funktioniert
|
||||||
|
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host -v $PWD/config:/mosquitto/config eclipse-mosquitto
|
||||||
|
|
||||||
|
$ docker run --rm -it --init --net host eclipse-mosquitto \
|
||||||
|
mosquitto_sub -V 5 --topic "demotopic" \
|
||||||
|
--username admin -P secret -W 2 --debug
|
||||||
|
|
||||||
8
04-mosquitto/lab04/config/acl.txt
Normal file
8
04-mosquitto/lab04/config/acl.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
topic readwrite freeforall
|
||||||
|
|
||||||
|
pattern readwrite users/%u/#
|
||||||
|
|
||||||
|
topic read announcements
|
||||||
|
|
||||||
|
user thomas
|
||||||
|
topic readwrite announcements
|
||||||
9
04-mosquitto/lab04/config/docker-compose.yml
Normal file
9
04-mosquitto/lab04/config/docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
services:
|
||||||
|
mosquitto:
|
||||||
|
image: eclipse-mosquitto
|
||||||
|
ports:
|
||||||
|
- "1883:1883"
|
||||||
|
volumes:
|
||||||
|
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
|
||||||
|
- ./users.txt:/mosquitto/config/users.txt:ro
|
||||||
|
- ./acl.txt:/mosquitto/config/acl.txt:ro
|
||||||
5
04-mosquitto/lab04/config/mosquitto.conf
Normal file
5
04-mosquitto/lab04/config/mosquitto.conf
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
listener 1883
|
||||||
|
|
||||||
|
allow_anonymous true
|
||||||
|
password_file /mosquitto/config/users.txt
|
||||||
|
acl_file /mosquitto/config/acl.txt
|
||||||
2
04-mosquitto/lab04/config/users.txt
Normal file
2
04-mosquitto/lab04/config/users.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
thomas:$7$101$+0sf4wma3qzDFw6R$H+lLmGLzo1Ex5rXxZqWxuEFCV7bSsAehEwTJ6XULFberEhwug/EC8aSWtiI4xScYQ2u/0sZ3xCg0rTRaMb5ITg==
|
||||||
|
admin:$7$101$S9wXlrBPl3PFz+9y$l3/GP/FjklfQ2inTxBf4FfLvFR3r5yF6G6ZSRDFRwAklzltZ+xhUWM83PKQjxy2ZFYYmHxMoKs4q1+IMrXL6NA==
|
||||||
14
04-mosquitto/lab04/cyberchef/chef.txt
Normal file
14
04-mosquitto/lab04/cyberchef/chef.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Fork('\\n','\\n',false)
|
||||||
|
Register('^([^:]+)',true,false,false)
|
||||||
|
Find_/_Replace({'option':'Regex','string':'^[^:]+:'},'',false,false,false,false)
|
||||||
|
Register('(.*)',true,false,false)
|
||||||
|
Pseudo-Random_Number_Generator(12,'Hex')
|
||||||
|
Register('(.*)',true,false,false)
|
||||||
|
From_Hex('Auto')
|
||||||
|
To_Base64('A-Za-z0-9+/=')
|
||||||
|
Register('([\\s\\S]*)',true,false,false)
|
||||||
|
Find_/_Replace({'option':'Regex','string':'.*'},'$R1',false,false,false,false)
|
||||||
|
Derive_PBKDF2_key({'option':'Latin1','string':'$R1'},512,101,'SHA512',{'option':'Hex','string':'$R2'})
|
||||||
|
From_Hex('Auto')
|
||||||
|
To_Base64('A-Za-z0-9+/=')
|
||||||
|
Find_/_Replace({'option':'Regex','string':'.*'},'$R0:$$7$$101$$$R3$$$&',false,false,false,false)
|
||||||
30
04-mosquitto/lab04/cyberchef/receipt.json
Normal file
30
04-mosquitto/lab04/cyberchef/receipt.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[
|
||||||
|
{ "op": "Fork",
|
||||||
|
"args": ["\\n", "\\n", false] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["^([^:]+)", true, false, false] },
|
||||||
|
{ "op": "Find / Replace",
|
||||||
|
"args": [{ "option": "Regex", "string": "^[^:]+:" }, "", false, false, false, false] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["(.*)", true, false, false] },
|
||||||
|
{ "op": "Pseudo-Random Number Generator",
|
||||||
|
"args": [12, "Hex"] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["(.*)", true, false, false] },
|
||||||
|
{ "op": "From Hex",
|
||||||
|
"args": ["Auto"] },
|
||||||
|
{ "op": "To Base64",
|
||||||
|
"args": ["A-Za-z0-9+/="] },
|
||||||
|
{ "op": "Register",
|
||||||
|
"args": ["([\\s\\S]*)", true, false, false] },
|
||||||
|
{ "op": "Find / Replace",
|
||||||
|
"args": [{ "option": "Regex", "string": ".*" }, "$R1", false, false, false, false] },
|
||||||
|
{ "op": "Derive PBKDF2 key",
|
||||||
|
"args": [{ "option": "Latin1", "string": "$R1" }, 512, 101, "SHA512", { "option": "Hex", "string": "$R2" }] },
|
||||||
|
{ "op": "From Hex",
|
||||||
|
"args": ["Auto"] },
|
||||||
|
{ "op": "To Base64",
|
||||||
|
"args": ["A-Za-z0-9+/="] },
|
||||||
|
{ "op": "Find / Replace",
|
||||||
|
"args": [{ "option": "Regex", "string": ".*" }, "$R0:$$7$$101$$$R3$$$&", false, false, false, false] }
|
||||||
|
]
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user