Mosquito MQTT客户端证书异常



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

问题是,在mosquitto.conf文件中,我要求要连接的客户端使用客户端证书,所以如果我想从web应用程序订阅主题,我需要客户端证书。我正试图找到正确的方法来实现这一点,但在一台无法控制的机器中拥有证书和密钥似乎是一个巨大的安全风险。

如果有人知道调整mosquito配置文件的方法,或者建立某种异常(可能类似于ACL(,只要求某些客户端(在我的情况下,是微控制器(的客户端证书,并使用username@password用于其他(web客户端(。有可能做这样的事吗?

如有任何帮助,将不胜感激

编辑(关于@hardillb的回答(

我的蚊子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部分可能不是必需的。但是,我仍然需要它来配置websocket的用户名和密码。

我的配置文件有问题吗?

链接到我关于如何在客户端的机器中存储客户端证书和密钥的问题

Mosquitto允许每个代理有多个侦听器,所有侦听器共享同一主题空间。

监听器可以支持本机MQTT、基于Websockets的MQTT(包括基于TLS的Websockets(和基于TLS的MQTT。

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

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

例如类似的东西(但可能使用身份验证插件而不是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上的websocket(但不要使用require_certificate,因为浏览器端客户端证书处理websocket不是一种很好的体验,因为它们不要求使用哪个(。但通常情况下,我会使用类似NGINX的东西来代理websocket侦听器,并进行TLS终止。

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

最新更新