MQTT Projekt III.

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

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