MQTTS/SSL 证书问题(连接到 MQTTS 时出错)

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

我和我的团队正在开发物联网家庭自动化系统。通过 mqtt 协议处理设备之间的实时更新和依赖关系对于我们的系统至关重要。在我们决定转向MQTTS之前,一切似乎都运行良好。 我们在Ngix Proxy Manager的帮助下颁发了SSL证书,将letsencrypt目录插入docker compose文件并运行后,代理持续拒绝连接。

检查 mosquitto-log 时,我得到以下输出: 证书验证错误

Docker-compose.yml :

version: "3.7"
services: 
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
  pyth:
    image: 'foxide123/prediction-model-image:1.2'
    restart: always
    ports:
      - '5000:5000'
    volumes:
      - ./letsencrypt:/etc/letsencrypt
  mqtt:
    container_name: ohmio_mqtt
    image: ohmio_mqtt_image
    restart: always
    volumes:
      - ./mosquitto.conf:/mosquitto/config/mosquitto.conf
      - ./pwfile:/mosquitto/config/pwfile
      - ./data:/mosquitto/data/
      - ./letsencrypt:/mosquitto/certificates 
      - ./log:/mosquitto/log
    ports:
      - "8883:8883"

mosquitto-conf 文件(/etc/mosquitto/mosquitto.config):

listener 8883 0.0.0.0

certfile /mosquitto/certificates/live/npm-3/fullchain.pem
keyfile /mosquitto/certificates/live/npm-3/privkey.pem

allow_anonymous false
password_file /mosquitto/config/pwfile/passwd

persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
log_type all
require_certificate true

Ngix的配置文件:

server{
  listen 8883;
  server_name mqtt.ohmio.org
  ssl_certificate nginx_npm/letsencrypt/live/npm-3/fullchain.pem
  ssl_certficiate nginx_npm/letsencrypt/live/npm-3/privkey.pem
  ssl_protocols TLSv1.2 TLSv1.3;
}

一开始我尝试通过“letsencrypt”直接生成证书,得到的错误是: 证书验证错误 后来我决定使用 Ngix 代理管理器来生成证书,错误仍然存在。

docker ssl-certificate mqtt lets-encrypt letsencrypt-nginx-proxy-companion
1个回答
0
投票

问题是

require_certificate true

来自

mosquitto.conf
页面

require_certificate [ true |假]

默认情况下,启用 SSL/TLS 的侦听器将以与启用 https 的 Web 服务器类似的方式运行,因为服务器具有由 CA 签名的证书,并且客户端将验证它是否是受信任的证书。总体目标是网络流量的加密。通过将 require_certificate 设置为 true,连接到此侦听器的客户端必须提供有效的证书才能继续进行网络连接。这允许在 MQTT 提供的机制之外控制对代理的访问。

这意味着客户端在打开连接时必须提供客户端证书以向代理标识自己的身份。

此选项需要匹配的

cafile
capath
条目,该条目指向颁发客户端证书的 CA 证书,以便可以验证它们。

在这种情况下,您似乎使用用户名/密码来验证/识别客户端而不是客户端证书,因此您需要从

require_certificate true
 中删除 
mosquitto.conf

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