【问题标题】:MQTT problem with raspberry pi, SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)树莓派的 MQTT 问题,SSL:UNSUPPORTED_PROTOCOL] 不支持的协议 (_ssl.c:1056)
【发布时间】:2019-12-13 01:56:30
【问题描述】:

我在 AWS 服务器上运行 MQTT 代理,该代理在 mac 上正常运行,而 windows 设备在我的树莓派上无法正常运行。我的订阅者和发布者代码有效,并且已经在多个操作系统上进行了测试。我相信问题出在我的树莓派设置上,但是我无法解决这个问题。

我收到的错误(使用 python3):

pi@raspberrypi:~/MQTT $ sudo python3 subscriber.py 
Traceback (most recent call last):
  File "subscriber.py", line 42, in <module>
    client.connect(brokerAddress,port,60)
  File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1100, in reconnect
    sock.do_handshake()
  File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)

我收到的 python 错误,

pi@raspberrypi:~/MQTT $ python subscriber.py 
Traceback (most recent call last):
  File "subscriber.py", line 42, in <module>
    client.connect(brokerAddress,port,60)
  File "/home/pi/.local/lib/python2.7/site-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/home/pi/.local/lib/python2.7/site-packages/paho/mqtt/client.py", line 1100, in reconnect
    sock.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 828, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:727)

我尝试了几件事,包括使用 python 与 python3、确保安装最新版本的 paho、重新启动、在另一个网络上运行树莓派、以 sudo 运行,以及其他一些事情。

这可能无关,但我之前尝试在这个树莓派上运行 git clone 时遇到过问题,我认为这可能与 ssl 问题有关。

其他可能有用的东西

pi@raspberrypi:~/MQTT $ openssl version
OpenSSL 1.1.1d  10 Sep 2019

代码,subscriber.py:

import paho.mqtt.client as mqtt
import sys
import time
import ssl

# The callback for when the client receives a conack response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe("test")
    printf("subscribed to test")

# When a message is received
def on_message(client, userdata, msg):
    print("INCOMING") #begin message
    print("TOPIC: \t\t"+msg.topic+"\nMESSAGE:\t"+str(msg.payload.decode()))

client = mqtt.Client("C1")
#declare loc of tls certificate
client.tls_set('/home/pi/MQTT/ca.crt',cert_reqs=ssl.CERT_NONE)

client.tls_insecure_set(True)
client.on_connect = on_connect
client.on_message = on_message

#plain text credentials
client.username_pw_set("myusername","mypassword")

#declare address and port
brokerAddress="my-ipv4-ip-address"
port=8883
client.connect(brokerAddress,port,60)
#continuous loop
client.loop_forever()

当在我的 mac 上运行时,这个确切的代码可以工作,我可以从我的桌面(windows)发布这条消息,它会按预期显示。

如果您需要我提供任何其他信息来帮助解决问题,请告诉我。

【问题讨论】:

  • 有时需要重新编译库代码才能在不同的操作系统上工作。您是否在 Raspberry Pi 上进行了冻结并安装?
  • 这看起来是客户端和代理之间的 TLS 版本不匹配。请编辑问题以包含有关如何配置代理的更多详细信息。
  • 请在您的 RPI 设备上运行此程序并在您的问题中添加响应:openssl s_client -connect server-ip-address:8883 --showcerts。可能您在 RPI 设备上的 openssl 默认禁用了一些旧的“不太安全”密码(您实际上可以启用)。

标签: python ssl raspberry-pi mqtt iot


【解决方案1】:

我遇到了同样的问题。
我在 TLSv1.0 证书中生成的证书。但默认情况下,RPi 的 openssl 配置不接受这些。
我通过将接受的最低协议版本从 v1.2 更改为 v1.0 解决了这个问题

/etc/ssl/openssl.cnf
MinProtocol = TLSv1.2 更改为MinProtocol = TLSv1.0

【讨论】:

  • 在我的 openssl.cnf 文件中没有MinProtocol = ,我可以将它添加到文件中的任何位置吗?我不想弄乱我的树莓派,所以问问
  • 在我的配置文件中,它的结构是这样的。 ` openssl_conf = default_conf [default_conf] ssl_conf = ssl_sect [ssl_sect] system_default = system_default_sect [system_default_sect] MinProtocol = TLSv1.0 ` MinProtocol = TLSv1.0 [sections] ... ` 可能发生的最糟糕的事情是它无法识别该密钥并且不使用它。
  • 好的,谢谢!它有效......我只是想确保它不会引起任何问题(由于一些我无法修复的问题,我在上个月不得不重新安装 Raspbian 大约 5 次)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 2015-11-26
  • 2022-01-05
  • 1970-01-01
相关资源
最近更新 更多