【问题标题】:Mosquitto MQTT client certificate exceptionMosquitto MQTT 客户端证书异常
【发布时间】:2020-04-01 20:06:04
【问题描述】:

我正在开发一个应用程序,总而言之,它使用 MQTT 将传感器值发送到代理,以便稍后在仪表板 Web 应用程序中可视化该数据。 我有五个微控制器连接到代理,并且我为代理设置了服务器证书,并为每个微控制器设置了客户端证书。

问题是,在 mosquitto.conf 文件中,我需要为想要连接的客户端使用客户端证书,所以如果我想从我的 Web 应用程序订阅主题,我需要一个客户端证书。我正在尝试找到完成此任务的正确方法,但在您无法控制的机器中拥有证书和密钥似乎是一个很大的安全风险。

如果有人知道调整 mosquitto 配置文件的方法或建立某种异常(可能类似于 ACL)以仅要求某些客户端(在我的情况下为微控制器)的客户端证书并使用用户名@,那将是理想的其他人(网络客户端)的密码。有可能做这样的事情吗?

任何帮助将不胜感激

编辑(关于@hardillb 的回答)

我的 mosquitto.conf:

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

per_listener_settings true

listener 9873
protocol websockets
#http_dir /home/jamengual/Desktop/UIB/TFG/mqtt/webAPP
cafile /etc/mosquitto/ca_certificates/ca.crt
keyfile /etc/mosquitto/certs/server.key
certfile /etc/mosquitto/certs/server.crt

listener 8883
cafile /etc/mosquitto/ca_certificates/ca.crt
keyfile /etc/mosquitto/certs/server.key
certfile /etc/mosquitto/certs/server.crt
require_certificate true

“per_listener_settings true”使服务器进入活动(退出)状态。 来自 mosquitto.conf 指南:

谈谈认证机制:

基于证书和 PSK 的加密均配置在 每个听众的基础。

谈论 per_listener_settings 选项:

per_listener_settings [ true | false ]

    If true, then authentication and access control settings will be controlled on a per-listener basis. The following options are affected:

    password_file, acl_file, psk_file, allow_anonymous, allow_zero_length_clientid, auth_plugin, auth_opt_*, auto_id_prefix.

所以我知道 per_listener_settings 选项对于 require_certificate 部分可能不是必需的。但是,我仍然需要它来配置 websockets 的用户名和密码。

我的配置文件有问题吗?

Link to my question about how to store client certificates and keys in the client's machine

【问题讨论】:

    标签: ssl ssl-certificate mqtt mosquitto


    【解决方案1】:

    Mosquitto 允许您为每个代理拥有多个共享同一主题空间的侦听器。

    监听器可以支持原生 MQTT、MQTT over Websockets(包括 Websockets over TLS)和 MQTT over TLS。

    它还具有per_listener_settings 选项,允许您为不同的侦听器指定不同的身份验证选项。这个选项是在 mosquitto 1.5 版中添加的。

    因此,在这种情况下,您可以创建一个 MQTT over TLS 侦听器并使用客户端证书对这些用户(设备)进行身份验证,并创建一个 MQTT over Websocket 侦听器将使用用户名/密码身份验证。

    例如像这样的东西(但可能使用身份验证插件而不是 acl/密码文件)

    per_listener_settings true
    
    listener 1884
    cafile /path/to/ca
    certfile /path/to/cert
    keyfile /path/to/key
    require_certificate true
    acl_file /path/to/acl_file
    
    listener 8883
    protocol websockets
    acl_file /path/to/acl_file
    password_file /path/to/password
    

    您还可以为 websocket 侦听器包含 ca_filecert_filekey_file 选项,以启用基于 TLS 的 Websockets(但不要使用 require_certificate,因为浏览器端客户端证书处理 websockets 不是很棒的体验,因为他们不问使用哪个)。但通常我通常会使用 NGINX 之类的东西来代理 websocket 侦听器并进行 TLS 终止。

    所有选项的详细信息可以在 mosquitto.conf 手册页中找到:https://mosquitto.org/man/mosquitto-conf-5.html

    【讨论】:

    • 感谢您的回答。拥有 per_listener_settings 选项会使服务器崩溃并进入活动(退出)状态。但是,如果我输入 require_certificate true ,websockets 监听器似乎会忽略它并让客户端连接。我将编辑我的问题以包含我的 mosquitto.conf 文件。此外,mosquitto.conf 指南的链接说:“基于证书和 PSK 的加密都是基于每个侦听器配置的。”,所以我知道可能没有必要包含 per_listener_settings true 选项。
    • 你运行的是什么版本的 mosquitto?还要检查日志,了解它为什么崩溃(我猜是因为你运行的是旧版本)
    • 正如我所说,您不应该将客户端证书 (require_certificate true) 与 websockets 一起使用,因为浏览器不正确支持选择正确的证书来发送。
    • 我正在运行 mosquitto 版本 1.4.15。也许我没有很好地解释自己。我的意思是,即使我将 require_certificate 设置为 true(没有 per_listener_settings),websockets 也不会受到影响,这就是我想要的,因为我的计划是对 websockets 侦听器使用用户名和密码,对另一个使用 TLS。日志没有报告任何有关配置错误的信息,但我会再看一下。请查看我对问题的编辑。谢谢!
    • 如果你想使用 websockets 的用户名和密码,不要使用require_certificate true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 2021-11-19
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    相关资源
    最近更新 更多