Jump to content

RPI tinkerforge_mqtt Probleme mit MQTT und SSL/TLS


Recommended Posts

Hallo, ich habe Probleme mit meinem RPI4. Es läuft RPI OS lite drauf. Alles nochmals per apt update & upgrade.

Heute wollte ich MQTT SSL einrichten. Soweit bin ich gekommen. Brickd wollte sich nicht verbinden. Laut Doku gibt es unter Kommandozeilenargumente die Möglichkeit.
die Möglichkeit gibt es aber nicht. 

brickd ist jetzt auf Version 2.4.3

tinkerforge_mqtt war die Version 2.0.3 drauf ich hab sie selbst gegen 2.0.13 ausgetauscht.  Zur Hilfe kommt dies:

tinkerforge_mqtt --help
CRITICAL:root:requiring paho 1.3.1 or newer.

pip ist drauf

pip3 --version
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

tinkerforge und paho-mqtt auch

sudo pip3 install tinkerforge paho-mqtt
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: tinkerforge in /usr/local/lib/python3.7/dist-packages (2.1.24)
Requirement already satisfied: paho-mqtt in /usr/local/lib/python3.7/dist-packages (1.5.0)

Ich bin ratlos???

zumal ich eigentlich das Kommando nutzen wollte und das ca.crt hinzufügen wollte es aber nicht verfügbar ist?!?

tinkerforge_mqtt --broker-certificate /ort/zum/certificate/ca.crt

--broker-certificate <BROKER_CERTIFICATE> CA-Zertifikat für SSL/TLS-Verbindung zum Broker

bearbeitet von Manuel Ziel
Link zu diesem Kommentar
Share on other sites

On 1/23/2021 at 6:07 PM, Manuel Ziel said:

Heute wollte ich MQTT SSL einrichten. Soweit bin ich gekommen. Brickd wollte sich nicht verbinden. Laut Doku gibt es unter Kommandozeilenargumente die Möglichkeit.
die Möglichkeit gibt es aber nicht.

Mir ist unklar was genau dein Problem hier ist. Brickd an sich kann kein SSL.

Die MQTT Bindings können auf der MQTT Seite SSL.

Welche Kommandozeilenargumenten meinst du?

Das Problem hier ist das tinkerforge_mqtt in seiner Shebang Zeile noch auf Python 2 verweist. Das sollte ich mal auf Python 3 ändern, da Python 2 jetzt über ein Jahr EOL ist.

Da du die Abhängigkeiten für Python 3 installiert hast, tinkerforge_mqtt aber mit Python 2 läuft, findest es Paho MQTT nicht.

Teste mal bitte die angehängte Version die jetzt auf Python 3 gesetzt ist.

tinkerforge_mqtt_bindings_2_0_14_rc1.zip

Link zu diesem Kommentar
Share on other sites

Hallo, sorry dass ich erst jetzt antworte.

Ich hab die neuen tinkerforge_mqtt_bindings übertragen. Wenn ich jetzt dies eingebe... 

tinkerforge_mqtt --help

Dann kommt jetzt auch keine Fehlermeldung mehr.

Zitat

Welche Kommandozeilenargumenten meinst du?

Für SSL werde ich anscheinend dies gebrauchen:

--broker-certificate BROKER_CERTIFICATE

Ich werde es gleich testen.
 

Link zu diesem Kommentar
Share on other sites

Hab es versucht,

der Broker läuft auf dem gleichen RPI unter localhost:8883.

die mosquitto.conf ist so eingestellt:

# Port
port 8883

#CA file
cafile /etc/mosquitto/certs/ca.crt
# Path to the PEM encoded server certificate
certfile /etc/mosquitto/certs/broker.crt
# Path to the PEM encoded keyfile
keyfile /etc/mosquitto/certs/broker.key
#Add path to CA
#/etc/mosquitto/ca_certificates 

#TLS Version
tls_version tlsv1.2

#
# Authentication
#

require_certificate true
use_identity_as_username true

auf dem Broker kann ich von verschiedenen client's mit der client.crt und client.key zugreifen und habe dann eine SSL Verbindung.

wenn ich den Pfad zur ca.crt eintippe

tinkerforge_mqtt --broker-certificate /home/manu/ca.crt

dann kommt:

2021-02-01 10:19:35,429 <INFO> MQTT bindings: Could not connect to MQTT Broker. Will retry.

Obwohl ich den Brocker schon länger, ohne SSL, auf dem Port 8883 laufen habe und nie den Port in tinkerforge_mqtt eingestellt habe hat es funktioniert. Ich hab dennoch mal versucht den Port von default (1883) auf 8883 umzustellen und nochmals, mit der ca und client.crt, eine Verbindung aufzubauen.  Bisher immer nur mit Fehlermeldung.  Auch --broker-tls-insecure kann ich nicht verwenden:

tinkerforge_mqtt: error: --broker-tls-[in]secure cannot be used without --broker-certificate

Um mit dem Broker eine Verbindung aufzubauen muss ich doch die client.crt und clinet.key verwenden. Da bin ich gerade verunsichert.

Was mach ich falsch?

Link zu diesem Kommentar
Share on other sites

Moin,

Teste mal immer mit

tinkerforge_mqtt --debug ... andere Flags

Dann bekommst du mehr hilfreiche Ausgabe.

Mich wundert folgendes:

1 hour ago, Manuel Ziel said:

Obwohl ich den Brocker schon länger, ohne SSL, auf dem Port 8883 laufen habe und nie den Port in tinkerforge_mqtt eingestellt habe hat es funktioniert

Die Bindings verwenden als Default-Port immer die 1883, d.h. wenn du den Broker ohne Verschlüsselung auch auf der 8883 laufen hast, hätte das nie funktionieren dürfen, wenn du den Port nicht angibst. Teste bitte nochmal, wie das bei deaktiviertem TLS mit den Ports genau ist, also ob du, selbst wenn du in mosquitto.conf 8883 konfigurierst, du mit der Default-Einstellung der Bindings eine Verbindung bekommst. Dann wäre auch interessant, was passiert, wenn du explizit --broker-port 1883 oder --broker-port 8883 mitgibst.

Die ganze SSL/TLS-Geschichte werde ich unabhängig davon in den nächsten Tagen hier nochmal durchtesten, bisher gab es da keine Beschwerden, aber auch kein positives Feedback, eventuell ist das also wirklich einfach kaputt und es hat bisher noch niemand gemerkt. Bis ich zum testen komme kann es aber noch etwas dauern, also durchaus erst nächste Woche oder so. Ich gebe Bescheid ;)

 

Link zu diesem Kommentar
Share on other sites

Moin,

ok danke, geschnallt.

Zitat

Mich wundert folgendes:

  vor 1 Stunde schrieb Manuel Ziel:
Obwohl ich den Brocker schon länger, ohne SSL, auf dem Port 8883 laufen habe und nie den Port in tinkerforge_mqtt eingestellt habe hat es funktioniert

Die Bindings verwenden als Default-Port immer die 1883, d.h. wenn du den Broker ohne Verschlüsselung auch auf der 8883 laufen hast, hätte das nie funktionieren dürfen, wenn du den Port nicht angibst.

Das hat mich auch gewundert. Deswegen hatte ich es erwähnt.

Ich stelle jetzt erstmal alles ohne TLS auf Port 1883:

# Port
port 1883

#CA file
#cafile /etc/mosquitto/certs/ca.crt
# Path to the PEM encoded server certificate
#certfile /etc/mosquitto/certs/broker.crt
# Path to the PEM encoded keyfile
#keyfile /etc/mosquitto/certs/broker.key
#Add path to CA
#/etc/mosquitto/ca_certificates 

#TLS Version
#tls_version tlsv1.2

#
# Authentication
#

#require_certificate true
#use_identity_as_username true

password_file /etc/mosquitto/passwd
tinkerforge_mqtt --debug --broker-username <USER> --broker-password <PSK>
2021-02-01 13:06:36,165 <INFO> MQTT bindings: Starting Tinkerforge MQTT bindings 2.0.14
2021-02-01 13:06:36,166 <DEBUG> MQTT bindings: Configuring connection to MQTT broker at localhost:1883
2021-02-01 13:06:36,167 <DEBUG> MQTT bindings: Connected to MQTT broker at localhost:1883
2021-02-01 13:06:36,174 <DEBUG> paho.mqtt.client: Sending CONNECT (u1, p1, wr0, wq0, wf1, c1, k60) client_id=b''
2021-02-01 13:06:36,175 <DEBUG> paho.mqtt.client: Received CONNACK (0, 0)
2021-02-01 13:06:36,175 <DEBUG> MQTT bindings: Connected to mqtt broker.
2021-02-01 13:06:36,175 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m1) [(b'tinkerforge/request/#', 0)]
2021-02-01 13:06:36,175 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m2) [(b'tinkerforge/register/#', 0)]
2021-02-01 13:06:36,176 <DEBUG> paho.mqtt.client: Sending PUBLISH (d0, q0, r0, m3), 'b'tinkerforge/callback/bindings/restart'', ... (4 bytes)
2021-02-01 13:06:36,176 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m4) [(b'tinkerforge/callback/bindings/restart', 0)]
2021-02-01 13:06:36,176 <DEBUG> MQTT bindings: Connecting to brickd at localhost:4223
2021-02-01 13:06:36,177 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 13:06:36,178 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 13:06:36,178 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 13:06:36,180 <DEBUG> MQTT bindings: Connected to Brick Daemon: Connection established after request from user.
2021-02-01 13:06:36,180 <DEBUG> MQTT bindings: Connected to brickd at localhost:4223

Und es funktioniert mit Benutzernamen und Passwort. Was ich auch zum allerersten mal eingegeben habe. Das hätte ich mir sicher in meiner Dokumentation aufgeschrieben. Laut meiner Dokumentation hat es schon ausgereicht die tinkerforge_mqtt bindings zu starten dass alles lief. 

Jetzt nur den Port auf 8883 umstellen und mosquitto neustarten:

tinkerforge_mqtt --debug --broker-username <User> --broker-password <PSK>
2021-02-01 13:14:05,387 <INFO> MQTT bindings: Starting Tinkerforge MQTT bindings 2.0.14
2021-02-01 13:14:05,388 <DEBUG> MQTT bindings: Configuring connection to MQTT broker at localhost:1883
2021-02-01 13:14:05,388 <DEBUG> MQTT bindings: Connected to MQTT broker at localhost:1883
2021-02-01 13:14:05,395 <INFO> MQTT bindings: Could not connect to MQTT Broker. Will retry.

So ist es ja richtig dass es nicht geht.

jetzt mit Port 8883

tinkerforge_mqtt --debug --broker-port 8883 --broker-username <User> --broker-password <PSK>
2021-02-01 13:16:14,871 <INFO> MQTT bindings: Starting Tinkerforge MQTT bindings 2.0.14
2021-02-01 13:16:14,872 <DEBUG> MQTT bindings: Configuring connection to MQTT broker at localhost:8883
2021-02-01 13:16:14,872 <DEBUG> MQTT bindings: Connected to MQTT broker at localhost:8883
2021-02-01 13:16:14,878 <DEBUG> paho.mqtt.client: Sending CONNECT (u1, p1, wr0, wq0, wf1, c1, k60) client_id=b''
2021-02-01 13:16:14,882 <DEBUG> paho.mqtt.client: Received CONNACK (0, 0)
2021-02-01 13:16:14,882 <DEBUG> MQTT bindings: Connected to mqtt broker.
2021-02-01 13:16:14,882 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m1) [(b'tinkerforge/request/#', 0)]
2021-02-01 13:16:14,883 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m2) [(b'tinkerforge/register/#', 0)]
2021-02-01 13:16:14,883 <DEBUG> paho.mqtt.client: Sending PUBLISH (d0, q0, r0, m3), 'b'tinkerforge/callback/bindings/restart'', ... (4 bytes)
2021-02-01 13:16:14,883 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m4) [(b'tinkerforge/callback/bindings/restart', 0)]
2021-02-01 13:16:14,884 <DEBUG> MQTT bindings: Connecting to brickd at localhost:4223
2021-02-01 13:16:14,885 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 13:16:14,885 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 13:16:14,886 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 13:16:14,887 <DEBUG> MQTT bindings: Connected to Brick Daemon: Connection established after request from user.
2021-02-01 13:16:14,888 <DEBUG> MQTT bindings: Connected to brickd at localhost:4223

Ok das geht. 

jetzt nochmals mit ca.crt auf Port 8883 und den TLS Einstellungen in mosquitto.conf

tinkerforge_mqtt --debug --broker-port 8883 --broker-certificate /home/manu/ca.crt
2021-02-01 13:20:44,087 <INFO> MQTT bindings: Starting Tinkerforge MQTT bindings 2.0.14
2021-02-01 13:20:44,094 <DEBUG> MQTT bindings: Configuring connection to MQTT broker at localhost:8883
2021-02-01 13:20:44,094 <DEBUG> MQTT bindings: Connected to MQTT broker at localhost:8883
2021-02-01 13:20:44,112 <DEBUG> paho.mqtt.client: Sending CONNECT (u0, p0, wr0, wq0, wf1, c1, k60) client_id=b''
2021-02-01 13:20:44,113 <ERROR> paho.mqtt.client: failed to receive on socket: [SSL] tlsv13 alert certificate required (_ssl.c:2488)
2021-02-01 13:20:45,126 <DEBUG> paho.mqtt.client: Sending CONNECT (u0, p0, wr0, wq0, wf1, c1, k60) client_id=b''
2021-02-01 13:20:45,126 <ERROR> paho.mqtt.client: failed to receive on socket: [SSL] tlsv13 alert certificate required (_ssl.c:2488)

Ok schon mal weiter gekommen. Jetzt werde ich bei der Fehlermeldung weiter schauen. Wenn ich etwas finde schreib ich es.

bearbeitet von Manuel Ziel
Link zu diesem Kommentar
Share on other sites

Im Debug-Log ist auffällig, dass die Bindings TLS 1.3 sprechen, du Mosquitto aber auf TLS 1.2 betreibst (da kannst du nicht so einfach auf 1.3 wechseln, das gibt es erst ab Mosquitto 1.6 und Raspberry Pi OS liefert noch die 1.5.7 aus) Als Schnellschuss: Teste mal mit der angehangenen Bindings-Version, in der ich TLS 1.2 erzwungen habe.

tinkerforge_mqtt_bindings_2_0_14_rc2.zip

Link zu diesem Kommentar
Share on other sites

Die Fehlermeldung zu tlsv1.3 ist schon mal weg.

 

inkerforge_mqtt --debug --broker-port 8883 --broker-certificate /home/manu/ca.crt
2021-02-01 14:28:59,446 <INFO> MQTT bindings: Starting Tinkerforge MQTT bindings 2.0.14
2021-02-01 14:28:59,449 <DEBUG> MQTT bindings: Configuring connection to MQTT broker at localhost:8883
2021-02-01 14:28:59,449 <DEBUG> MQTT bindings: Connected to MQTT broker at localhost:8883
2021-02-01 14:28:59,467 <INFO> MQTT bindings: Could not connect to MQTT Broker. Will retry.
2021-02-01 14:28:59,467 <DEBUG> paho.mqtt.client: Connection failed, retrying
2021-02-01 14:29:02,488 <INFO> MQTT bindings: Could not connect to MQTT Broker. Will retry.
2021-02-01 14:29:02,488 <DEBUG> paho.mqtt.client: Connection failed, retrying
2021-02-01 14:29:06,510 <INFO> MQTT bindings: Could not connect to MQTT Broker. Will retry.
2021-02-01 14:29:06,510 <DEBUG> paho.mqtt.client: Connection failed, retrying

Auch mit --broker-tls-insecure als weiteren Flag kommt das gleiche raus. 

Kann require_certificate überhaupt ausgefuhrt werden?

Link zu diesem Kommentar
Share on other sites

Ohne require_certificate funktioniert es.

tinkerforge_mqtt --debug --broker-port 8883 --broker-username <User> --broker-password <PSK> --broker-certificate /home/manu/ca.crt
2021-02-01 14:41:04,810 <INFO> MQTT bindings: Starting Tinkerforge MQTT bindings 2.0.14
2021-02-01 14:41:04,813 <DEBUG> MQTT bindings: Configuring connection to MQTT broker at localhost:8883
2021-02-01 14:41:04,814 <DEBUG> MQTT bindings: Connected to MQTT broker at localhost:8883
2021-02-01 14:41:04,833 <DEBUG> paho.mqtt.client: Sending CONNECT (u1, p1, wr0, wq0, wf1, c1, k60) client_id=b''
2021-02-01 14:41:04,834 <DEBUG> paho.mqtt.client: Received CONNACK (0, 0)
2021-02-01 14:41:04,834 <DEBUG> MQTT bindings: Connected to mqtt broker.
2021-02-01 14:41:04,834 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m1) [(b'tinkerforge/request/#', 0)]
2021-02-01 14:41:04,835 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m2) [(b'tinkerforge/register/#', 0)]
2021-02-01 14:41:04,835 <DEBUG> paho.mqtt.client: Sending PUBLISH (d0, q0, r0, m3), 'b'tinkerforge/callback/bindings/restart'', ... (4 bytes)
2021-02-01 14:41:04,836 <DEBUG> paho.mqtt.client: Sending SUBSCRIBE (d0, m4) [(b'tinkerforge/callback/bindings/restart', 0)]
2021-02-01 14:41:04,836 <DEBUG> MQTT bindings: Connecting to brickd at localhost:4223
2021-02-01 14:41:04,838 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 14:41:04,839 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 14:41:04,840 <DEBUG> paho.mqtt.client: Received SUBACK
2021-02-01 14:41:04,841 <DEBUG> MQTT bindings: Connected to Brick Daemon: Connection established after request from user.
2021-02-01 14:41:04,841 <DEBUG> MQTT bindings: Connected to brickd at localhost:4223

Immerhin mit Passwort geht es.

Link zu diesem Kommentar
Share on other sites

57 minutes ago, Manuel Ziel said:

Ohne require_certificate funktioniert es.

Das ist erwartet. Mosquitto erwartet bei "require_certificate true", dass sich der Client (tinkerforge_mqtt in diesem Fall) per Client Zertifikat ausweißt. Das tut tinkerforge_mqtt aktuelle nicht. Das müsste man tinkerforge_mqtt erst beibringen, damit du neben ca.cert auch client.crt und client.key angeben könntest.

Link zu diesem Kommentar
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...