MQTT Projekt IV.: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „=Grundaufbau= {{#drawio:mqtt-plan1}} =Connectivity= ==ssh== ;mqtt *ssh xinux@opnsense -p 9822 ;sensor *ssh xinux@opnsense -p 9823 ;aktor *ssh xinux@opnsense -…“)
 
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 31: Zeile 31:
 
*cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt /etc/mosquitto/conf.d/defaults.conf
 
*cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt /etc/mosquitto/conf.d/defaults.conf
  
;Konfigurationsdatei
+
;Konfigurationsdatei
listener 8883 0.0.0.0
+
listener 8883 0.0.0.0
allow_anonymous false
+
allow_anonymous false
log_type all
+
log_type all
connection_messages true
+
connection_messages true
 
+
# Passwortauthentifizierung
+
# Passwortauthentifizierung
password_file /etc/mosquitto/passwd
+
password_file /etc/mosquitto/passwd  
 
+
# TLS-Server-Zertifikate
+
# TLS-Server-Zertifikate
certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt
+
certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt
keyfile /etc/mosquitto/conf.d/mqtt.lab.intern.key
+
keyfile /etc/mosquitto/conf.d/mqtt.lab.intern.key
cafile /etc/mosquitto/conf.d/ca.crt
+
cafile /etc/mosquitto/conf.d/ca.crt
 
+
# Client-Zertifikate erforderlich
+
# Client-Zertifikate erforderlich
require_certificate true
+
require_certificate true
use_identity_as_username true
+
use_identity_as_username true  
  
 
;Restarten
 
;Restarten
Zeile 58: Zeile 58:
 
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 \
+
*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
--cafile /usr/local/control/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 \
+
*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"
--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"
 
  
 
==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 21. März 2025, 15:05 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

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
listener 8883 0.0.0.0
allow_anonymous false
log_type all
connection_messages true

# Passwortauthentifizierung
password_file /etc/mosquitto/passwd 

# TLS-Server-Zertifikate
certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt
keyfile /etc/mosquitto/conf.d/mqtt.lab.intern.key
cafile /etc/mosquitto/conf.d/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.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

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 --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.