MQTT Projekt IV.: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(5 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 22: Zeile 22:
  
 
==mqtt==
 
==mqtt==
;Benutzer anlegen
+
;Sensor Benutzer anlegen
*user: xinux
+
*user: sensor
 
*pass: 123Start$
 
*pass: 123Start$
  
*mosquitto_passwd -c /etc/mosquitto/passwd xinux
+
*mosquitto_passwd -c /etc/mosquitto/passwd sensor
 +
 
 +
;Aktor Benutzer anlegen
 +
*user: aktor
 +
*pass: 123Start$
 +
 
 +
*mosquitto_passwd -c /etc/mosquitto/passwd aktor
  
 
;Konfiguration kopieren
 
;Konfiguration kopieren
 
*cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt.2fa /etc/mosquitto/conf.d/defaults.conf
 
*cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt.2fa /etc/mosquitto/conf.d/defaults.conf
  
;Konfigurationsdatei
+
*cat /etc/mosquitto/conf.d/defaults.conf
listener 8883 0.0.0.0
+
<pre>
allow_anonymous false
+
# Öffnet den MQTT-Broker auf Port 8883 und bindet ihn an alle verfügbaren Netzwerkinterfaces.
log_type all
+
listener 8883 0.0.0.0
connection_messages true
+
 
+
# Erlaubt anonyme Verbindungen, d. h. ohne Benutzername und Passwort.
# Passwortauthentifizierung
+
allow_anonymous false
password_file /etc/mosquitto/passwd  
+
 
+
# Aktiviert alle Log-Typen für eine detaillierte Protokollierung.
# TLS-Server-Zertifikate
+
log_type all
certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt
+
 
  keyfile /etc/mosquitto/conf.d/mqtt.lab.intern.key
+
# Zeigt Verbindungs- und Trennungsmeldungen von Clients im Log an.
  cafile /etc/mosquitto/conf.d/ca.crt
+
connection_messages true
+
 
# Client-Zertifikate erforderlich
+
#Hier gegen wird authentifiziert.
require_certificate true
+
password_file /etc/mosquitto/passwd
use_identity_as_username true  
+
 
 +
# Zertifikat
 +
certfile /etc/mosquitto/conf.d/own.crt
 +
 
 +
#PrivKey
 +
keyfile /etc/mosquitto/conf.d/own.key
 +
 
 +
#Zertifikat der CA
 +
cafile /etc/mosquitto/conf.d/kit-ca.crt
 +
 
 +
 
 +
# Client-Zertifikate erforderlich
 +
require_certificate true
 +
use_identity_as_username true  
 +
</pre>
  
 
;Restarten
 
;Restarten
Zeile 58: Zeile 78:
 
Der Aktor '''abonniert (subscribed)''' die Nachrichten und reagiert darauf.
 
Der Aktor '''abonniert (subscribed)''' die Nachrichten und reagiert darauf.
  
*mosquitto_sub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control/ca.crt --cert /usr/local/control/aktor.crt --key /usr/local/control/aktor.key -u xinux -P 123Start$ -t test
+
*mosquitto_sub -h mqtt.dkbi.com -p 8883 --cafile /usr/local/control/kit-ca.crt --cert /usr/local/control/aktor.crt --key /usr/local/control/aktor.key -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 -p 8883 --cafile /usr/local/control-switch/ca.crt --cert /usr/local/control-switch/sensor.crt --key /usr/local/control-switch/sensor.key -u xinux -P 123Start$ -t test -m "Zertifikat + Passwort"
+
*mosquitto_pub -h mqtt.dkbi.com -p 8883 --cafile /usr/local/control-switch/kit-ca.crt --cert /usr/local/control-switch/sensor.crt --key /usr/local/control-switch/sensor.key -u xinux -P 123Start$ -t test -m "Zertifikat + Passwort"
  
 
==kali==
 
==kali==
 
Hier kann man auf Wireshark mitschneiden. Der Text ist Hexadezimal codiert.   
 
Hier kann man auf Wireshark mitschneiden. Der Text ist Hexadezimal codiert.   
 
;Schaut mal was man sieht.
 
;Schaut mal was man sieht.

Aktuelle Version vom 20. Juni 2026, 10:49 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 2FA (Zertifikat + Passwort)

Wir haben eine ca.crt der Auth, ein Server-Zertifikat mqtt.dkbi.int.crt mit mqtt.dkbi.int.key und zwei Client-Zertifikate: sensor.crt/sensor.key und aktor.crt/aktor.key

mqtt

Sensor Benutzer anlegen
  • user: sensor
  • pass: 123Start$
  • mosquitto_passwd -c /etc/mosquitto/passwd sensor
Aktor Benutzer anlegen
  • user: aktor
  • pass: 123Start$
  • mosquitto_passwd -c /etc/mosquitto/passwd aktor
Konfiguration kopieren
  • cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt.2fa /etc/mosquitto/conf.d/defaults.conf
  • cat /etc/mosquitto/conf.d/defaults.conf
# Ö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/own.crt

#PrivKey
keyfile  /etc/mosquitto/conf.d/own.key

#Zertifikat der CA
cafile  /etc/mosquitto/conf.d/kit-ca.crt


# Client-Zertifikate erforderlich
require_certificate true
use_identity_as_username true 
Restarten
  • systemctl restart mosquitto.service
Checken
  • systemctl status mosquitto.service

Aktor

Der Aktor abonniert (subscribed) die Nachrichten und reagiert darauf.

  • mosquitto_sub -h mqtt.dkbi.com -p 8883 --cafile /usr/local/control/kit-ca.crt --cert /usr/local/control/aktor.crt --key /usr/local/control/aktor.key -u xinux -P 123Start$ -t test

Sensor

Der Sensor sendet (published) die Nachrichten an das Topic.

  • mosquitto_pub -h mqtt.dkbi.com -p 8883 --cafile /usr/local/control-switch/kit-ca.crt --cert /usr/local/control-switch/sensor.crt --key /usr/local/control-switch/sensor.key -u xinux -P 123Start$ -t test -m "Zertifikat + Passwort"

kali

Hier kann man auf Wireshark mitschneiden. Der Text ist Hexadezimal codiert.

Schaut mal was man sieht.