MQTT Projekt III.: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| (9 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 25: | Zeile 25: | ||
;Konfiguration kopieren | ;Konfiguration kopieren | ||
| − | *cp /etc/mosquitto/conf.d/defaults.conf. | + | *cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt /etc/mosquitto/conf.d/defaults.conf |
;Konfigurationsdatei | ;Konfigurationsdatei | ||
<pre> | <pre> | ||
| − | # Öffnet den MQTT-Broker auf Port | + | # Öffnet den MQTT-Broker auf Port 8883 und bindet ihn an alle verfügbaren Netzwerkinterfaces. |
| − | listener | + | listener 8883 0.0.0.0 |
# Erlaubt anonyme Verbindungen, d. h. ohne Benutzername und Passwort. | # Erlaubt anonyme Verbindungen, d. h. ohne Benutzername und Passwort. | ||
| Zeile 43: | Zeile 43: | ||
password_file /etc/mosquitto/passwd | password_file /etc/mosquitto/passwd | ||
| + | # Zertifikat | ||
| + | certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt | ||
| + | |||
| + | #PrivKey | ||
| + | keyfile /etc/mosquitto/conf.d/mqtt.lab.intern.key | ||
| + | |||
| + | #Zertifikat der CA | ||
| + | cafile /etc/mosquitto/conf.d/ca.crt | ||
</pre> | </pre> | ||
;Restarten | ;Restarten | ||
| Zeile 51: | Zeile 59: | ||
==Aktor== | ==Aktor== | ||
Der Aktor '''abonniert (subscribed)''' die Nachrichten und reagiert darauf. | Der Aktor '''abonniert (subscribed)''' die Nachrichten und reagiert darauf. | ||
| − | *mosquitto_sub -h mqtt.lab.intern -u xinux -P 123Start$ -t test | + | *mosquitto_sub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control/ca.crt -u xinux -P 123Start$ -t test |
==Sensor== | ==Sensor== | ||
Der Sensor '''sendet (published)''' die Nachrichten an das Topic. | Der Sensor '''sendet (published)''' die Nachrichten an das Topic. | ||
| − | *mosquitto_pub -h mqtt.lab.intern -u xinux -P 123Start$ -t test -m "Hello World" | + | *mosquitto_pub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control-switch/ca.crt -u xinux -P 123Start$ -t test -m "Hello World" |
| − | *mosquitto_pub -h mqtt.lab.intern -u xinux -P 123Start$ -t test -m "2 Nachricht" | + | *mosquitto_pub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control-switch/ca.crt -u xinux -P 123Start$ -t test -m "2 Nachricht" |
==kali== | ==kali== | ||
| Zeile 66: | Zeile 74: | ||
*cat /usr/local/control-switch/.env | *cat /usr/local/control-switch/.env | ||
MQTT_HOST=mqtt.lab.intern | MQTT_HOST=mqtt.lab.intern | ||
| − | MQTT_PORT= | + | MQTT_PORT=8883 |
MQTT_USER=xinux | MQTT_USER=xinux | ||
MQTT_PASS=123Start$ | MQTT_PASS=123Start$ | ||
| + | MQTT_TLS=true | ||
| + | MQTT_CA=/usr/local/control-switch/ca.crt | ||
*systemctl restart control-switch.service | *systemctl restart control-switch.service | ||
*http://opnsense:9723/ | *http://opnsense:9723/ | ||
| Zeile 74: | Zeile 84: | ||
*cat /usr/local/control/.env | *cat /usr/local/control/.env | ||
MQTT_HOST=mqtt.lab.intern | MQTT_HOST=mqtt.lab.intern | ||
| − | MQTT_PORT= | + | MQTT_PORT=8883 |
MQTT_USER=xinux | MQTT_USER=xinux | ||
MQTT_PASS=123Start$ | MQTT_PASS=123Start$ | ||
| + | MQTT_TLS=true | ||
| + | MQTT_CA=/usr/local/control-switch/ca.crt | ||
*systemctl restart control-switch.service | *systemctl restart control-switch.service | ||
*http://opnsense:9724/ | *http://opnsense:9724/ | ||
Aktuelle Version vom 1. März 2025, 16:55 Uhr
Grundaufbau
Connectivity
ssh
- mqtt
- ssh xinux@opnsense -p 9822
- sensor
- ssh xinux@opnsense -p 9823
- aktor
- ssh xinux@opnsense -p 9824
http
- sensor
- aktor
Verschlüsselt mit Passwort
Wir haben eine ca.crt der Auth und ein Certificate mqtt.dkbi.int.crt sowie ein PrivKey mqtt.dkbi.int.key
mqtt
- Benutzer anlegen
- user: xinux
- pass: 123Start$
- mosquitto_passwd -c /etc/mosquitto/passwd xinux
- Konfiguration kopieren
- cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt /etc/mosquitto/conf.d/defaults.conf
- Konfigurationsdatei
# Öffnet den MQTT-Broker auf Port 8883 und bindet ihn an alle verfügbaren Netzwerkinterfaces. listener 8883 0.0.0.0 # Erlaubt anonyme Verbindungen, d. h. ohne Benutzername und Passwort. allow_anonymous false # Aktiviert alle Log-Typen für eine detaillierte Protokollierung. log_type all # Zeigt Verbindungs- und Trennungsmeldungen von Clients im Log an. connection_messages true #Hier gegen wird authentifiziert. password_file /etc/mosquitto/passwd # Zertifikat certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt #PrivKey keyfile /etc/mosquitto/conf.d/mqtt.lab.intern.key #Zertifikat der CA cafile /etc/mosquitto/conf.d/ca.crt
- Restarten
- systemctl restart mosquitto.service
- Checken
- systemctl status mosquitto.service
Aktor
Der Aktor abonniert (subscribed) die Nachrichten und reagiert darauf.
- mosquitto_sub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control/ca.crt -u xinux -P 123Start$ -t test
Sensor
Der Sensor sendet (published) die Nachrichten an das Topic.
- mosquitto_pub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control-switch/ca.crt -u xinux -P 123Start$ -t test -m "Hello World"
- mosquitto_pub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control-switch/ca.crt -u xinux -P 123Start$ -t test -m "2 Nachricht"
kali
Hier kann man auf Wireshark mitschneiden. Der Text ist Hexadezimal codiert.
- Schaut mal was man sieht.
Anpassen von node.js
- sensor
- cat /usr/local/control-switch/.env
MQTT_HOST=mqtt.lab.intern MQTT_PORT=8883 MQTT_USER=xinux MQTT_PASS=123Start$ MQTT_TLS=true MQTT_CA=/usr/local/control-switch/ca.crt
- systemctl restart control-switch.service
- http://opnsense:9723/
- aktor
- cat /usr/local/control/.env
MQTT_HOST=mqtt.lab.intern MQTT_PORT=8883 MQTT_USER=xinux MQTT_PASS=123Start$ MQTT_TLS=true MQTT_CA=/usr/local/control-switch/ca.crt
- systemctl restart control-switch.service
- http://opnsense:9724/
