MQTT Projekt III.: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(10 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
 
=Grundaufbau=
 
=Grundaufbau=
 
{{#drawio:mqtt-plan1}}
 
{{#drawio:mqtt-plan1}}
=Connectivity=
 
==ssh==
 
;mqtt
 
*ssh xinux@opnsense -p 9822
 
;sensor
 
*ssh xinux@opnsense -p 9823
 
;aktor
 
*ssh xinux@opnsense -p 9824
 
==http==
 
;sensor
 
*http://opnsense:9723
 
;aktor
 
*http://opnsense:9724
 
 
 
=Verschlüsselt mit Passwort=
 
=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
 
Wir haben eine ca.crt der Auth und ein Certificate mqtt.dkbi.int.crt sowie ein PrivKey mqtt.dkbi.int.key
Zeile 25: Zeile 11:
  
 
;Konfiguration kopieren
 
;Konfiguration kopieren
*cp /etc/mosquitto/conf.d/defaults.conf.mit-password /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>
Zeile 44: Zeile 30:
  
 
# Zertifikat
 
# Zertifikat
certfilev /etc/mosquitto/conf.d/mqtt.lab.intern.crt
+
certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt
  
 
#PrivKey
 
#PrivKey
Zeile 59: Zeile 45:
 
==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 74: Zeile 60:
 
*cat /usr/local/control-switch/.env
 
*cat /usr/local/control-switch/.env
 
  MQTT_HOST=mqtt.lab.intern
 
  MQTT_HOST=mqtt.lab.intern
  MQTT_PORT=1883
+
  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://sensor:3000/
 
;aktor
 
;aktor
 
*cat /usr/local/control/.env
 
*cat /usr/local/control/.env
 
  MQTT_HOST=mqtt.lab.intern
 
  MQTT_HOST=mqtt.lab.intern
  MQTT_PORT=1883
+
  MQTT_PORT=8883
 
  MQTT_USER=xinux
 
  MQTT_USER=xinux
 
  MQTT_PASS=123Start$
 
  MQTT_PASS=123Start$
*systemctl restart control-switch.service
+
MQTT_TLS=true
*http://opnsense:9724/
+
MQTT_CA=/usr/local/control/ca.crt
 +
*systemctl restart control.service
 +
*http://aktor:3000/

Aktuelle Version vom 24. November 2025, 10:27 Uhr

Grundaufbau

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
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/ca.crt