“NO_CIPHERS_AVAILABLE”,无法让flask_mqtt与基于hiveMQ云的mqtt代理(TLS)一起使用

问题描述 投票:0回答:1

我正在尝试让我的 Flask 应用程序与我的 HiveMQ Broker 集群进行通信。该集群仅通过端口 8883 进行 TLS 通信。据我了解,我需要一些证书文件才能执行此操作,但所有指导我如何创建这些文件的指南都没有帮助。

这是我的简单测试片段,我无法通过 TSL 发布到我的主题:

from flask import Flask, render_template, redirect
from flask_mqtt import Mqtt

app = Flask(__name__)

# MQTT configuration
app.config['MQTT_BROKER_URL'] = 'xxxxxxxxxxxxxxxxxxxxx.s2.eu.hivemq.cloud'
app.config['MQTT_BROKER_PORT'] = 8883
app.config['MQTT_USERNAME'] = 'my_user_name'
app.config['MQTT_PASSWORD'] = 'my_password'
app.config['MQTT_TLS_ENABLED'] = True
app.config['MQTT_TLS_INSECURE'] = True

app.config['MQTT_TLS_CA_CERTS'] = '' # Is this needed? If yes, how is such a file created?
app.config['MQTT_TLS_CERTFILE '] = ''  # Is this needed? If yes, how is such a file created?
app.config['MQTT_TLS_KEYFILE'] = ''  # Is this needed? If yes, how is such a file created?

mqtt = Mqtt(app)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/publish', methods=['POST'])
def publish():
    mqtt.publish("control/", "toggle_valve")
    return redirect('/', 200)

if __name__ == '__main__':
    app.run(debug=True)

我正在尝试遵循 Flask-MQTT 文档/示例,但在尝试运行代码时,我不断收到错误 SSL: NO_CIPHERS_AVAILABLE] no ciphers available..

这些认证文件是我应该直接从 HiveMQ 获取的,还是我必须自己使用 openssl 或类似的东西创建它们?

额外信息:我已经确定 url、端口和用户名+密码有效,因为我已经让它可以与 Flask 之外的 paho-mqtt 库一起使用。

感谢您的宝贵时间!

python flask mqtt tls1.3 hivemq
1个回答
0
投票

HiveMQ Cloud 产品不支持不安全连接,需要 TLS。安全 MQTT TLS 连接(端口 8883)和安全 Websocket TLS 连接(端口 8884)。

要建立 TLS 连接,您的客户端/设备必须信任已向客户端尝试连接的 HiveMQ 云服务器颁发证书的证书颁发机构 (CA)。

您可以在此处下载 HiveMQ Cloud 根 CA:https://letsencrypt.org/certs/isrgrootx1.pem

如果您想执行双向 TLS,则其他参数(例如 MQTT_TLS_CERTFILE 和 MQTT_TLS_KEYFILE )是可选的,以确保客户端和服务器之间的通信使用相互加密(同时使用客户端和服务器证书)。

我鼓励您下次对 HiveMQ Cloud 有任何疑问时使用我们的社区论坛 https://community.hivemq.com/

亲切的问候,
来自 HiveMQ 团队的迭戈

© www.soinside.com 2019 - 2024. All rights reserved.